From 7e46b190f1fce8bd82c780b348cfd4b0302534bf Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Mon, 23 Feb 2026 18:49:37 -0500 Subject: [PATCH] Ensure backward compatibility for single-player mode Added explicit tests documenting that createCombatState, drawCards, playCard, and endTurn all accept the original single-string/no-index signatures and keep state.player and state.enemy aliases in sync. --- src/state.test.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/state.test.js b/src/state.test.js index 8bdb8a7..fcbb4b8 100644 --- a/src/state.test.js +++ b/src/state.test.js @@ -226,3 +226,42 @@ describe("endTurn - indexed player", () => { expect(next.combat.phase).toBe("player_turn"); }); }); + +describe("backward compat - single string args", () => { + test("string args produce state with compat player/enemy aliases", () => { + const state = createCombatState("ironclad", "jaw_worm"); + // compat aliases still work + expect(state.player).toBeDefined(); + expect(state.enemy).toBeDefined(); + expect(state.player.hp).toBe(11); + expect(state.enemy.name).toBe("Jaw Worm"); + // arrays also populated + expect(state.players).toHaveLength(1); + expect(state.enemies).toHaveLength(1); + expect(state.combat.playerCount).toBe(1); + }); + + test("drawCards with single count arg still works", () => { + const state = createCombatState("ironclad", "jaw_worm"); + const next = drawCards(state, 3); + expect(next.player.hand).toHaveLength(3); + expect(next.players[0].hand).toHaveLength(3); + }); + + test("playCard with just handIndex still works", () => { + let state = createCombatState("ironclad", "jaw_worm"); + state = drawCards(state, 5); + const cardIndex = state.player.hand.indexOf("strike_r"); + const next = playCard(state, cardIndex); + expect(next.player.energy).toBe(2); + expect(next.players[0].energy).toBe(2); + }); + + test("endTurn with no playerIndex still works", () => { + let state = createCombatState("ironclad", "jaw_worm"); + state = drawCards(state, 5); + const next = endTurn(state); + expect(next.combat.phase).toBe("enemy_turn"); + expect(next.player.hand).toHaveLength(0); + }); +});