Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
simlmx committed Aug 18, 2024
1 parent 998464b commit bead3de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
49 changes: 21 additions & 28 deletions packages/game/src/testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<B>;
type P = { itWasMe?: boolean };
type PMT = Record<string, unknown>;
// type PMT = {
// go: { itWasMe?: boolean };
// endTurn: never;
// beginZeroDelay: never;
// };
type PM<P = null> = PlayerMove<GS, P, PMT>;
type PM<P = null> = PlayerMove<GS, P>;

const game = {
...gameBase,
Expand All @@ -28,6 +26,7 @@ describe("turns", () => {
me: 0,
bot: 0,
numZeroDelay: 0,
expiresAt: undefined,
},
itsTheirTurn: players,
}),
Expand All @@ -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<P>,
endTurn: {
Expand All @@ -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<GS>;

Expand All @@ -79,9 +80,11 @@ describe("turns", () => {
const match = new MatchTester<GS, G>({ 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);
Expand Down Expand Up @@ -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<GS, G>({ 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<GS, G>({ game, numPlayers: 1 });

// FIXME Not true anymore?
test.skip("making a move removes delayed move", () => {
const match = new MatchTester<GS, G>({ 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);
});
});

Expand Down
9 changes: 0 additions & 9 deletions packages/game/src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ export class MatchTester<
}
}

// FIXME test this in testing.test.ts
return {
expiresAt: expiresIn === undefined ? undefined : this.time + expiresIn,
};
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit bead3de

Please sign in to comment.