diff --git a/server/backend/internal/campaigns/messagewall/resolver_test.go b/server/backend/internal/campaigns/messagewall/resolver_test.go index f5aad22..22d1e00 100644 --- a/server/backend/internal/campaigns/messagewall/resolver_test.go +++ b/server/backend/internal/campaigns/messagewall/resolver_test.go @@ -1,6 +1,9 @@ package messagewall -import "testing" +import ( + "strings" + "testing" +) func TestResolveBuildsScenes(t *testing.T) { request := ResolveRequest{ @@ -60,3 +63,87 @@ func TestValidateRejectsOverlappingSlots(t *testing.T) { t.Fatal("Validate() error = nil, want overlap error") } } + +func TestValidateRejectsDocumentedInvalidLayouts(t *testing.T) { + tests := []struct { + name string + layout Layout + wantMessage string + }{ + { + name: "unsupported version", + layout: Layout{ + Version: 2, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"}, + FitMode: "cover", + Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}}, + }, + wantMessage: "unsupported layout version", + }, + { + name: "unsupported unit", + layout: Layout{ + Version: 1, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "pixel"}, + FitMode: "cover", + Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}}, + }, + wantMessage: "unsupported coordinate_space unit", + }, + { + name: "unsupported fit mode", + layout: Layout{ + Version: 1, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"}, + FitMode: "stretch", + Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}}, + }, + wantMessage: "unsupported fit_mode", + }, + { + name: "empty slots", + layout: Layout{ + Version: 1, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"}, + FitMode: "cover", + }, + wantMessage: "layout must contain at least one slot", + }, + { + name: "duplicate slot ids", + layout: Layout{ + Version: 1, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"}, + FitMode: "cover", + Slots: []Slot{ + {SlotID: "a", X: 0, Y: 0, Width: 50, Height: 100}, + {SlotID: "a", X: 50, Y: 0, Width: 50, Height: 100}, + }, + }, + wantMessage: "duplicate slot_id", + }, + { + name: "slot exceeds bounds", + layout: Layout{ + Version: 1, + CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"}, + FitMode: "cover", + Slots: []Slot{{SlotID: "a", X: 60, Y: 0, Width: 50, Height: 100}}, + }, + wantMessage: "exceeds coordinate_space width", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := Validate(tt.layout) + if err == nil { + t.Fatal("Validate() error = nil, want validation error") + } + + if !strings.Contains(err.Error(), tt.wantMessage) { + t.Fatalf("Validate() error = %q, want message containing %q", err.Error(), tt.wantMessage) + } + }) + } +}