Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package support
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TestCreateInputAuthValidation covers pre-DB authz-adjacent validation used by
|
||||
// ticket CRUD (subject/body/category/priority). No DATABASE_URL required.
|
||||
func TestCreateInputAuthValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := NewService(nil)
|
||||
ctx := context.Background()
|
||||
cid := uuid.MustParse("11111111-1111-1111-1111-111111111111")
|
||||
uid := uuid.MustParse("22222222-2222-2222-2222-222222222222")
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
in CreateInput
|
||||
want error
|
||||
}{
|
||||
{name: "empty subject", in: CreateInput{Subject: " ", Body: "hello"}, want: ErrSubjectRequired},
|
||||
{name: "empty body", in: CreateInput{Subject: "Help", Body: ""}, want: ErrBodyRequired},
|
||||
{name: "bad category", in: CreateInput{Subject: "Help", Body: "x", Category: "nope"}, want: ErrInvalidCategory},
|
||||
{name: "bad priority", in: CreateInput{Subject: "Help", Body: "x", Priority: "urgent"}, want: ErrInvalidPriority},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := s.Create(ctx, cid, uid, tc.in)
|
||||
if !errors.Is(err, tc.want) {
|
||||
t.Fatalf("err=%v want %v", err, tc.want)
|
||||
}
|
||||
if msg, ok := ClientError(err); !ok || msg == "" {
|
||||
t.Fatalf("ClientError(%v) = %q ok=%v", err, msg, ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeCategoryDefaultOther(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := normalizeCategory("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "other" {
|
||||
t.Fatalf("got %q want other", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePriorityDefaultNormal(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := normalizePriority("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "normal" {
|
||||
t.Fatalf("got %q want normal", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user