aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_room_grid_seed_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-19 03:52:04 -0400
committerhistoria <[not public]>2026-09-19 03:52:04 -0400
commitbab5dd653039d026eb3d4e46da7aafef7137fe7c (patch)
tree9a1d8686dbcef8c145e3593511153768ae08962c /internal/admin/api_room_grid_seed_test.go
parent0e60567a7a0addb9421769ee7be7853bfa8788cb (diff)
downloadthehouseoficarus-bab5dd653039d026eb3d4e46da7aafef7137fe7c.tar.gz
fix: journal in-game room insert/remove, rewrite non-room room refs on rename/swap, seed admin grid from edited room, type action switches
Diffstat (limited to 'internal/admin/api_room_grid_seed_test.go')
-rw-r--r--internal/admin/api_room_grid_seed_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/internal/admin/api_room_grid_seed_test.go b/internal/admin/api_room_grid_seed_test.go
new file mode 100644
index 0000000..f1b347d
--- /dev/null
+++ b/internal/admin/api_room_grid_seed_test.go
@@ -0,0 +1,71 @@
+package admin
+
+// Regression: admin create/link grid prechecks seeded the layout from the
+// configured starting room. A detached in-progress area (not yet reachable
+// from the start room) was therefore never laid out, so a link that introduced
+// a grid twist was accepted, and auto-detecting a direction rejected two
+// adjacent detached rooms as "not reachable from the seed room". The prechecks
+// now seed from the room being edited.
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "thehouseoficarus/internal/config"
+)
+
+// newDetachedAdminServer builds a server whose configured starting room (999)
+// is deliberately outside every room under test.
+func newDetachedAdminServer(t *testing.T, rooms map[int]string) *AdminServer {
+ t.Helper()
+ s := newTestAdminServer(t, rooms)
+ s.cfg = config.Default()
+ s.cfg.StartingRoom = 999
+ return s
+}
+
+func postLink(t *testing.T, s *AdminServer, body string) (map[string]any, int) {
+ t.Helper()
+ req := httptest.NewRequest(http.MethodPost, "/api/rooms/link", strings.NewReader(body))
+ req.Header.Set("Content-Type", "application/json")
+ rr := httptest.NewRecorder()
+ s.handleRoomLink(rr, req)
+ var resp map[string]any
+ _ = json.Unmarshal(rr.Body.Bytes(), &resp)
+ return resp, rr.Code
+}
+
+func TestLinkConflictDetectedInDetachedArea(t *testing.T) {
+ s := newDetachedAdminServer(t, map[int]string{
+ 10: "id: 10\nname: A\nexits:\n north:\n room: 11\n",
+ 11: "id: 11\nname: B\nexits:\n south:\n room: 10\n east:\n room: 12\n",
+ 12: "id: 12\nname: C\n",
+ // Starting room outside the component under edit.
+ 999: "id: 999\nname: Start\n",
+ })
+
+ // 10-e north->11 and 11-east->12 place 12 at (1,-1); adding 10-east->12
+ // would also place it at (1,0) — a twist the detached precheck must catch.
+ if resp, code := postLink(t, s, `{"from":10,"to":12,"dir":"east"}`); code != http.StatusConflict {
+ t.Fatalf("detached link that creates a grid twist: status = %d (%v), want %d", code, resp, http.StatusConflict)
+ }
+}
+
+func TestAutoDirectionWorksInDetachedArea(t *testing.T) {
+ s := newDetachedAdminServer(t, map[int]string{
+ 10: "id: 10\nname: A\nexits:\n east:\n room: 11\n",
+ 11: "id: 11\nname: B\nexits:\n west:\n room: 10\n",
+ 999: "id: 999\nname: Start\n",
+ })
+
+ resp, code := postLink(t, s, `{"from":10,"to":11}`)
+ if code != http.StatusOK {
+ t.Fatalf("auto-direction in a detached area: status = %d (%v), want 200", code, resp)
+ }
+ if got := roomExitTarget(s, 10, "east"); got != 11 {
+ t.Fatalf("room 10 east exit = %d, want 11", got)
+ }
+}