From bead3de995f9daa51cd5a304d6e3dbe28686a703 Mon Sep 17 00:00:00 2001 From: Simon Lemieux <1105380+simlmx@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:13:26 +0000 Subject: [PATCH] fixup --- packages/game/src/testing.test.ts | 49 +++++++++++++------------------ packages/game/src/testing.ts | 9 ------ 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/packages/game/src/testing.test.ts b/packages/game/src/testing.test.ts index d5d18ce..df32d6d 100644 --- a/packages/game/src/testing.test.ts +++ b/packages/game/src/testing.test.ts @@ -4,22 +4,20 @@ import { BoardMove, Game, GameState, INIT_MOVE, PlayerMove } from "."; import { MatchTester } from "./testing"; const gameBase = { - version: "2.3.0", minPlayers: 1, maxPlayers: 10, }; describe("turns", () => { - type B = { me: number; bot: number; numZeroDelay: number }; + type B = { + me: number; + bot: number; + numZeroDelay: number; + expiresAt: number | undefined; + }; type GS = GameState; type P = { itWasMe?: boolean }; - type PMT = Record; - // type PMT = { - // go: { itWasMe?: boolean }; - // endTurn: never; - // beginZeroDelay: never; - // }; - type PM

= PlayerMove; + type PM

= PlayerMove; const game = { ...gameBase, @@ -28,6 +26,7 @@ describe("turns", () => { me: 0, bot: 0, numZeroDelay: 0, + expiresAt: undefined, }, itsTheirTurn: players, }), @@ -40,10 +39,11 @@ describe("turns", () => { board.bot++; } - turns.begin(userId, { + const { expiresAt } = turns.begin(userId, { expiresIn: 1000, playerMoveOnExpire: ["go", { itWasMe: false }], }); + board.expiresAt = expiresAt; }, } as PM

, endTurn: { @@ -59,17 +59,18 @@ describe("turns", () => { endMatch(); return; } - turns.begin(userId, { + const { expiresAt } = turns.begin(userId, { expiresIn: delay, playerMoveOnExpire: ["beginWithDelay", { delay: 0 }], }); + board.expiresAt = expiresAt; }, } as PM<{ delay: number }>, move: { execute() { // }, - }, + } as PM, }, } satisfies Game; @@ -79,9 +80,11 @@ describe("turns", () => { const match = new MatchTester({ game, numPlayers: 1 }); const userId = match.meta.players.allIds[0]; + expect(match.board.expiresAt).toBe(undefined); // I make a move match.makeMove(userId, "go", {}); + expect(match.board.expiresAt).toEqual(1000); // Auto move 1 second later match.fastForward(1000); @@ -149,24 +152,14 @@ describe("turns", () => { expect(match.matchHasEnded).toBe(true); }); - // FIXME this is not true anymore, perhaps we need the opposite test - test.skip("turn ends on move", () => { - const match = new MatchTester({ game, numPlayers: 2 }); - const userId = match.meta.players.allIds[0]; - match.makeMove(userId, "go", { itWasMe: true }); - match.makeMove(userId, "move"); - - expect(match.meta.players.byId[userId].itsYourTurn).toBe(false); - }); + test("expiresAt", () => { + const match = new MatchTester({ game, numPlayers: 1 }); - // FIXME Not true anymore? - test.skip("making a move removes delayed move", () => { - const match = new MatchTester({ game, numPlayers: 2 }); const userId = match.meta.players.allIds[0]; - match.makeMove(userId, "go", { itWasMe: true }); - expect(match.delayedMoves.length).toBe(1); - match.makeMove(userId, "move"); - expect(match.delayedMoves.length).toBe(0); + expect(match.board.expiresAt).toBe(undefined); + + match.makeMove(userId, "go", {}); + expect(match.board.expiresAt).toEqual(1000); }); }); diff --git a/packages/game/src/testing.ts b/packages/game/src/testing.ts index 3effc82..43baa7d 100644 --- a/packages/game/src/testing.ts +++ b/packages/game/src/testing.ts @@ -484,7 +484,6 @@ export class MatchTester< } } - // FIXME test this in testing.test.ts return { expiresAt: expiresIn === undefined ? undefined : this.time + expiresIn, }; @@ -706,14 +705,6 @@ export class MatchTester< throw new Error("error in move"); } - // When a user makes a move, we end their turn (unless the move starts it again). - // Remember that this also clears the delayed moves for that player. - // if (game.playerMoveEndsTurn && !this._lastTurnsBegin.has(userId)) { - // FIXME Do this in action_handlers - // FIXME test the playerMoveEndsTurn option - // turns.end(userId); - // } - this.fastForward(0); }