-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathtd-out-state.test.js
More file actions
85 lines (77 loc) · 2.29 KB
/
Copy pathtd-out-state.test.js
File metadata and controls
85 lines (77 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const {
clearTdOutVotes,
getTdOutPublicState,
hasTdOutVote,
isTdOutAvailable,
pruneTdOutVotes,
} = require("../../../../routes/socket/game/td-out-state");
const makeGame = ({
playerCount = 6,
deadSeats = [],
electionTrackerCount = 2,
phase = "selectingChancellor",
status = phase === "voting" ? "Vote on election #3 now." : "Election #3: president to select chancellor.",
isTracksFlipped = true,
isCompleted = false,
isGameFrozen = false,
isRemade = false,
} = {}) => ({
general: {
isRemade,
isTourny: false,
status,
},
gameState: {
phase,
isTracksFlipped,
isCompleted,
isGameFrozen,
},
trackState: {
electionTrackerCount,
},
private: {
seatedPlayers: Array.from({ length: playerCount }, (_value, index) => ({
userName: `p${index}`,
isDead: deadSeats.includes(index),
})),
tdOutVotes: {},
},
});
describe("td-out state", () => {
it("is available after two failed elections with an even number of living players", () => {
expect(isTdOutAvailable(makeGame())).toBe(true);
expect(isTdOutAvailable(makeGame({ phase: "voting" }))).toBe(true);
});
it("is not available for the wrong tracker count, odd living count, or inactive phase", () => {
expect(isTdOutAvailable(makeGame({ electionTrackerCount: 1 }))).toBe(false);
expect(isTdOutAvailable(makeGame({ deadSeats: [0] }))).toBe(false);
expect(isTdOutAvailable(makeGame({ phase: "presidentSelectingPolicy" }))).toBe(false);
expect(isTdOutAvailable(makeGame({ phase: "voting", status: "Tallying results of ballots.." }))).toBe(false);
});
it("prunes dead-player votes and reports the public vote count", () => {
const game = makeGame({ deadSeats: [1] });
game.private.tdOutVotes = {
p0: true,
p1: true,
p2: true,
};
pruneTdOutVotes(game);
expect(game.private.tdOutVotes).toEqual({
p0: true,
p2: true,
});
expect(getTdOutPublicState(game)).toEqual({
isAvailable: false,
voteCount: 2,
requiredVotes: 5,
});
});
it("tracks and clears an individual player's vote", () => {
const game = makeGame();
game.private.tdOutVotes.p0 = true;
expect(hasTdOutVote(game, "p0")).toBe(true);
clearTdOutVotes(game);
expect(hasTdOutVote(game, "p0")).toBe(false);
});
});