Files
pad/internal/items/validate_test.go
T
xarmian 7cda0d7896 feat: rebrand to Perpetual Software + new tagline (IDEA-832) (#273)
Migrates from xarmian/pad to PerpetualSoftware/pad across the entire
repo and updates the product subtitle to "Collaborate with your AI
agents".

Go module rename
- go.mod: github.com/xarmian/pad → github.com/PerpetualSoftware/pad
- All Go imports updated across cmd/pad, internal/{cli,server,store,
  models,collections,items,events,metrics,webhooks} (~130 files)
- Test fixtures with the literal repo slug ("xarmian/pad" in JSON
  shapes, SSH/HTTPS git URL strings, workspace_context fixtures)
  also updated, including the secondary repo entry
  (xarmian/pad-web → PerpetualSoftware/pad-web — pad-web was also
  moved to the org per branch context)

Docs / config
- README badges, install instructions, brew tap, Docker image, source
  build path, sponsor link (sponsor link kept as personal @xarmian)
- Subtitle: "Project management for developers and AI agents." →
  "Collaborate with your AI agents." (README, manifests, web layout
  meta, .goreleaser homebrew description)
- CONTRIBUTING.md, SECURITY.md, skills/INSTALL.md
- .goreleaser.yaml: homebrew_casks owner, GHCR image, release github
  owner, cosign cert-identity regex, comments
- .github/workflows/release.yml: tap/release comments
- deploy/k8s/deployment.yaml: container image
- docs/deployment.md: clone URL
- web/static/{site.webmanifest,manifest.json}: description
- web/src/routes/+layout.svelte: meta description + og:description

Brew tap path is PerpetualSoftware/tap/pad (CamelCase, matches
GitHub user case). GHCR image is ghcr.io/perpetualsoftware/pad
(lowercased per GHCR's URL normalization). CODEOWNERS @xarmian and
FUNDING.yml github: xarmian intentionally retained — those are the
personal maintainer / sponsor account, separate from the org repo.

Verification: go build ./..., go test ./... (all pkgs pass), web
build, and make install all clean (TASK-844, TASK-845).
2026-04-28 12:26:39 -04:00

269 lines
5.7 KiB
Go

package items
import (
"testing"
"github.com/PerpetualSoftware/pad/internal/models"
)
func taskSchema() models.CollectionSchema {
return models.CollectionSchema{
Fields: []models.FieldDef{
{
Key: "status",
Label: "Status",
Type: "select",
Options: []string{"open", "in-progress", "done", "cancelled"},
Default: "open",
Required: true,
},
{
Key: "priority",
Label: "Priority",
Type: "select",
Options: []string{"low", "medium", "high", "critical"},
Default: "medium",
},
{
Key: "assignee",
Label: "Assignee",
Type: "text",
},
{
Key: "due_date",
Label: "Due Date",
Type: "date",
},
{
Key: "effort_hours",
Label: "Effort",
Type: "number",
},
{
Key: "done",
Label: "Done",
Type: "checkbox",
},
},
}
}
func TestValidateFields_RequiredWithDefault(t *testing.T) {
schema := taskSchema()
fields := map[string]any{}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
// Required field "status" should have been filled with default
if fields["status"] != "open" {
t.Errorf("expected status default 'open', got %v", fields["status"])
}
// Optional field "priority" should have been filled with default
if fields["priority"] != "medium" {
t.Errorf("expected priority default 'medium', got %v", fields["priority"])
}
}
func TestValidateFields_RequiredMissingNoDefault(t *testing.T) {
schema := models.CollectionSchema{
Fields: []models.FieldDef{
{Key: "name", Label: "Name", Type: "text", Required: true},
},
}
fields := map[string]any{}
err := ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for missing required field without default")
}
}
func TestValidateFields_SelectInvalid(t *testing.T) {
schema := taskSchema()
fields := map[string]any{
"status": "invalid-value",
}
err := ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for invalid select value")
}
}
func TestValidateFields_SelectValid(t *testing.T) {
schema := taskSchema()
fields := map[string]any{
"status": "done",
"priority": "high",
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
}
func TestValidateFields_NumberType(t *testing.T) {
schema := taskSchema()
// Valid number
fields := map[string]any{
"effort_hours": float64(5),
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error for valid number, got: %v", err)
}
// Invalid number
fields = map[string]any{
"effort_hours": "not-a-number",
}
err = ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for string in number field")
}
}
func TestValidateFields_CheckboxType(t *testing.T) {
schema := taskSchema()
// Valid boolean
fields := map[string]any{
"done": true,
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error for valid checkbox, got: %v", err)
}
// Invalid boolean
fields = map[string]any{
"done": "yes",
}
err = ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for string in checkbox field")
}
}
func TestValidateFields_DateType(t *testing.T) {
schema := taskSchema()
// Valid date
fields := map[string]any{
"due_date": "2026-03-25",
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error for valid date, got: %v", err)
}
// Valid RFC3339
fields = map[string]any{
"due_date": "2026-03-25T10:00:00Z",
}
err = ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error for valid RFC3339, got: %v", err)
}
// Invalid date
fields = map[string]any{
"due_date": "not-a-date",
}
err = ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for invalid date")
}
// Empty date is OK (optional)
fields = map[string]any{
"due_date": "",
}
err = ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error for empty date, got: %v", err)
}
}
func TestValidateFields_TextType(t *testing.T) {
schema := taskSchema()
// Valid
fields := map[string]any{
"assignee": "alice",
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
// Invalid
fields = map[string]any{
"assignee": 42,
}
err = ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for number in text field")
}
}
func TestValidateFields_MultiSelect(t *testing.T) {
schema := models.CollectionSchema{
Fields: []models.FieldDef{
{
Key: "labels",
Label: "Labels",
Type: "multi_select",
Options: []string{"bug", "feature", "docs"},
},
},
}
// Valid
fields := map[string]any{
"labels": []any{"bug", "feature"},
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
// Invalid option
fields = map[string]any{
"labels": []any{"bug", "invalid"},
}
err = ValidateFields(fields, schema)
if err == nil {
t.Fatal("expected error for invalid multi_select option")
}
}
func TestValidateFields_DefaultsApplied(t *testing.T) {
schema := taskSchema()
fields := map[string]any{
"assignee": "bob",
}
err := ValidateFields(fields, schema)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
// Defaults should be applied
if fields["status"] != "open" {
t.Errorf("expected status default, got %v", fields["status"])
}
if fields["priority"] != "medium" {
t.Errorf("expected priority default, got %v", fields["priority"])
}
// Explicitly set field should remain
if fields["assignee"] != "bob" {
t.Errorf("expected assignee 'bob', got %v", fields["assignee"])
}
}