diff options
| author | historia <[not public]> | 2026-09-19 03:15:59 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-19 03:15:59 -0400 |
| commit | 0e60567a7a0addb9421769ee7be7853bfa8788cb (patch) | |
| tree | 7645112db0e4eae95b8a83c1e4f9aab38bede655 /internal/game/cmd_room_reconcile_regression_test.go | |
| parent | cc33072eced3d5460512c09c42ec4531c807d7af (diff) | |
| download | thehouseoficarus-0e60567a7a0addb9421769ee7be7853bfa8788cb.tar.gz | |
refactor: simplifcation, change how rooms are stored in player yaml, remove legacy code
Diffstat (limited to 'internal/game/cmd_room_reconcile_regression_test.go')
| -rw-r--r-- | internal/game/cmd_room_reconcile_regression_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/game/cmd_room_reconcile_regression_test.go b/internal/game/cmd_room_reconcile_regression_test.go new file mode 100644 index 0000000..790cb00 --- /dev/null +++ b/internal/game/cmd_room_reconcile_regression_test.go @@ -0,0 +1,47 @@ +package game + +import ( + "os" + "path/filepath" + "testing" + + "thehouseoficarus/internal/player" +) + +// TestRoomAddMobReconcilesLiveState: the in-game room editor used to write the +// YAML but leave the live room untouched, so an added mob did not appear until +// the room was re-entered or the server restarted. A successful room edit must +// reconcile runtime state like the admin editor does. +func TestRoomAddMobReconcilesLiveState(t *testing.T) { + dir := t.TempDir() + for _, sub := range []string{"mobs", "rooms"} { + if err := os.MkdirAll(filepath.Join(dir, sub), 0755); err != nil { + t.Fatal(err) + } + } + if err := os.WriteFile(filepath.Join(dir, "mobs", "rat.yaml"), + []byte("id: rat\nname: giant rat\ndescription: A scruffy rat.\ncombat:\n stats:\n hp: 5\n"), 0644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "rooms", "1.yaml"), + []byte("name: Central\n"), 0644); err != nil { + t.Fatal(err) + } + + g := newRemoveGame(t, dir) + sess := newRemoveSession(player.New("alice")) + sess.Player.RoomID = 1 + + if got := len(g.MobStore.MobsInRoom(1)); got != 0 { + t.Fatalf("room should start with no mobs, got %d", got) + } + g.roomAddMob(sess, []string{"rat"}) + if got := len(g.MobStore.MobsInRoom(1)); got != 1 { + t.Fatalf("room addmob did not reconcile live state: %d mobs in room, want 1", got) + } + for _, m := range g.MobStore.MobsInRoom(1) { + if m.DefID != "rat" { + t.Fatalf("seeded mob DefID = %q, want rat", m.DefID) + } + } +} |
