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
+13 -13
View File
@@ -13,7 +13,6 @@ import (
v1 "git.tipsy.codes/charles/webstory/pkg/api/webstory/v1"
"github.com/google/uuid"
"github.com/lib/pq"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -92,14 +91,14 @@ func (t *ActorTranslator) ToAPI(dbActor *DBActor) *v1.Actor {
}
return &v1.Actor{
Name: name,
ActorId: dbActor.ActorID,
NameValue: dbActor.NameValue,
Role: dbActor.Role,
Notes: dbActor.Notes,
CreateTime: timestamppb.New(dbActor.CreatedAt),
UpdateTime: timestamppb.New(dbActor.UpdatedAt),
Etag: dbActor.Etag,
Name: name,
ActorId: dbActor.ActorID,
NameValue: dbActor.NameValue,
Role: dbActor.Role,
Notes: dbActor.Notes,
CreateTime: timestamppb.New(dbActor.CreatedAt),
UpdateTime: timestamppb.New(dbActor.UpdatedAt),
Etag: dbActor.Etag,
}
}
@@ -180,8 +179,8 @@ func (a *DBActor) insert(db *sql.DB) error {
a.StoryID,
a.ActorID,
a.NameValue,
pq.Array([]string{a.Role}),
pq.Array([]string{a.Notes}),
a.Role,
a.Notes,
a.CreatedAt,
a.UpdatedAt,
etag,
@@ -396,11 +395,12 @@ func GetActorIDForResourceName(resourceName string) (int64, string, error) {
remaining := strings.TrimPrefix(resourceName, prefix)
actorPrefix := "actors/"
if !strings.HasPrefix(remaining, actorPrefix) {
idx := strings.Index(remaining, actorPrefix)
if idx == -1 {
return 0, "", fmt.Errorf("invalid actor resource name: must contain '%s', got '%s'", actorPrefix, remaining)
}
actorID := strings.TrimPrefix(remaining, actorPrefix)
actorID := remaining[idx+len(actorPrefix):]
if actorID == "" {
return 0, "", errors.New("actor_id is empty in resource name")
}