fix: actor tests

This commit is contained in:
2026-04-01 20:37:38 -07:00
parent 789e32a57f
commit 0308c70061
3 changed files with 128 additions and 76 deletions
+114 -62
View File
@@ -11,6 +11,8 @@ import (
v1 "git.tipsy.codes/charles/webstory/pkg/api/webstory/v1"
"git.tipsy.codes/charles/webstory/pkg/database/schema"
story "git.tipsy.codes/charles/webstory/pkg/database/story"
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -105,8 +107,8 @@ func TestActorTranslator_ToAPI(t *testing.T) {
checkFunc func(*v1.Actor) error
}{
{
name: "nil dbActor returns nil",
dbActor: nil,
name: "nil dbActor returns nil",
dbActor: nil,
checkFunc: func(a *v1.Actor) error {
if a != nil {
return fmt.Errorf("expected nil, got %v", a)
@@ -222,9 +224,19 @@ func TestDBActor_Save(t *testing.T) {
t.Fatalf("failed to run schema: %v", err)
}
// Create a story first
story := &story.DBStory{
StoryID: "save-test-story-1",
Title: "Save Test Story",
}
err = story.Save(db)
if err != nil {
t.Fatalf("failed to save story: %v", err)
}
actor := &DBActor{
StoryID: 1,
ActorID: "save-test1",
StoryID: story.ID,
ActorID: "save-test-1",
NameValue: "Save Test",
Role: "Test Role",
Notes: "Test notes",
@@ -291,9 +303,19 @@ func TestDBActor_GetByID(t *testing.T) {
t.Fatalf("failed to run schema: %v", err)
}
// Create a story first
story := &story.DBStory{
StoryID: "get-by-id-story-1",
Title: "Get By ID Story",
}
err = story.Save(db)
if err != nil {
t.Fatalf("failed to save story: %v", err)
}
actor := &DBActor{
StoryID: 1,
ActorID: "get-by-id-test",
StoryID: story.ID,
ActorID: "get-by-id-test-1",
NameValue: "Get Test",
}
err = actor.Save(db)
@@ -340,9 +362,19 @@ func TestDBActor_GetByActorID(t *testing.T) {
t.Fatalf("failed to run schema: %v", err)
}
// Create a story first
story := &story.DBStory{
StoryID: "get-by-actor-id-story-1",
Title: "Get By Actor ID Story",
}
err = story.Save(db)
if err != nil {
t.Fatalf("failed to save story: %v", err)
}
actor := &DBActor{
StoryID: 1,
ActorID: "get-by-actor-id-test",
StoryID: story.ID,
ActorID: "get-by-actor-id-test-1",
NameValue: "Get By Actor ID Test",
}
err = actor.Save(db)
@@ -386,14 +418,24 @@ func TestDBActor_ListByStoryID(t *testing.T) {
t.Fatalf("failed to run schema: %v", err)
}
// Create a story first
story := &story.DBStory{
StoryID: "list-test-story-1",
Title: "List Test Story",
}
err = story.Save(db)
if err != nil {
t.Fatalf("failed to save story: %v", err)
}
actor1 := &DBActor{
StoryID: 1,
StoryID: story.ID,
ActorID: "list-test-1",
NameValue: "Actor One",
Role: "Role One",
}
actor2 := &DBActor{
StoryID: 1,
StoryID: story.ID,
ActorID: "list-test-2",
NameValue: "Actor Two",
Role: "Role Two",
@@ -448,9 +490,19 @@ func TestDBActor_Delete(t *testing.T) {
t.Fatalf("failed to run schema: %v", err)
}
// Create a story first
story := &story.DBStory{
StoryID: "delete-test-story-1",
Title: "Delete Test Story",
}
err = story.Save(db)
if err != nil {
t.Fatalf("failed to save story: %v", err)
}
actor := &DBActor{
StoryID: 1,
ActorID: "delete-test-1",
StoryID: story.ID,
ActorID: "delete-test-actor-1",
NameValue: "Delete Test",
}
err = actor.Save(db)
@@ -492,74 +544,74 @@ func TestDBActor_GetActorIDForResourceName(t *testing.T) {
expectErr bool
}{
{
name: "valid story/actor resource name",
input: "stories/1/actors/my-actor",
storyID: 1,
actorID: "my-actor",
expectErr: false,
name: "valid story/actor resource name",
input: "stories/1/actors/my-actor",
storyID: 1,
actorID: "my-actor",
expectErr: false,
},
{
name: "valid story/actor resource name with numbers",
input: "stories/100/actors/actor-123",
storyID: 100,
actorID: "actor-123",
expectErr: false,
name: "valid story/actor resource name with numbers",
input: "stories/100/actors/actor-123",
storyID: 100,
actorID: "actor-123",
expectErr: false,
},
{
name: "missing actors/ prefix",
input: "stories/1/actor/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "missing actors/ prefix",
input: "stories/1/actor/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "actor_id with underscore not allowed",
input: "stories/1/actors/my_actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "actor_id with underscore not allowed",
input: "stories/1/actors/my_actor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "actor_id with spaces not allowed",
input: "stories/1/actors/my actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "actor_id with spaces not allowed",
input: "stories/1/actors/my actor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "actor_id with uppercase not allowed",
input: "stories/1/actors/MyActor",
storyID: 1,
actorID: "",
expectErr: true,
name: "actor_id with uppercase not allowed",
input: "stories/1/actors/MyActor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "actor_id with dots not allowed",
input: "stories/1/actors/my.actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "actor_id with dots not allowed",
input: "stories/1/actors/my.actor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "missing stories/ prefix",
input: "actors/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "missing stories/ prefix",
input: "actors/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "empty actor_id",
input: "stories/1/actors/",
storyID: 1,
actorID: "",
expectErr: true,
name: "empty actor_id",
input: "stories/1/actors/",
storyID: 1,
actorID: "",
expectErr: true,
},
{
name: "wrong stories/ prefix",
input: "story/1/actors/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
name: "wrong stories/ prefix",
input: "story/1/actors/my-actor",
storyID: 1,
actorID: "",
expectErr: true,
},
}