aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_room_reconcile_regression_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_room_reconcile_regression_test.go')
-rw-r--r--internal/game/cmd_room_reconcile_regression_test.go47
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)
+ }
+ }
+}