-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinningMultiState.test.js
More file actions
81 lines (71 loc) · 2.77 KB
/
winningMultiState.test.js
File metadata and controls
81 lines (71 loc) · 2.77 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
const t = require('./testHelpers')
const WinningMultiState = require('./winningMultiState')
const winningPlayers = [
{
user: {
name: 'user1',
id: 'id1',
},
money: 10,
},
{
user: {
name: 'user2',
id: 'id2',
},
money: 12,
},
]
test('I can win', () => {
const chat = t.Chat()
const tableStatus = {
hands: [
{ cards: ['1h', '2h'], name: 'user1' },
{ cards: ['1h', '2h'], name: 'user2' },
{ cards: ['1h', '2h'], name: 'user3' },
],
}
const winningMultiState = WinningMultiState(winningPlayers, 'room', 2, tableStatus)
winningMultiState.print(chat)
expect(chat.game.mock.calls.length).toBe(2)
expect(chat.game.mock.calls[0][0]).toBe('room')
expect(chat.game.mock.calls[0][1]).toBe('Player user1 wins 2!')
expect(chat.game.mock.calls[1][0]).toBe('room')
expect(chat.game.mock.calls[1][1]).toBe('Player user2 wins 2!')
expect(chat.toSelfInTopic.mock.calls.length).toBe(2)
expect(chat.toSelfInTopic.mock.calls[0][0]).toBe('id1')
expect(chat.toSelfInTopic.mock.calls[0][1]).toEqual({ money: '10' })
expect(chat.toSelfInTopic.mock.calls[0][2]).toBe('update-money-left')
expect(chat.toSelfInTopic.mock.calls[1][0]).toBe('id2')
expect(chat.toSelfInTopic.mock.calls[1][1]).toEqual({ money: '12' })
expect(chat.toSelfInTopic.mock.calls[1][2]).toBe('update-money-left')
const possibleWinners = {
hands: [
{ cards: ['1♥️', '2♥️'], name: 'user1' },
{ cards: ['1♥️', '2♥️'], name: 'user2' },
{ cards: ['1♥️', '2♥️'], name: 'user3' },
],
}
expect(chat.toRoomInTopic.mock.calls.length).toBe(1)
expect(chat.toRoomInTopic.mock.calls[0][0]).toBe('room')
expect(chat.toRoomInTopic.mock.calls[0][1]).toEqual(possibleWinners)
expect(chat.toRoomInTopic.mock.calls[0][2]).toEqual('show-playing-players')
})
test('I can win when people folds', () => {
const chat = t.Chat()
const winningMultiState = WinningMultiState(winningPlayers, 'room', 2)
winningMultiState.print(chat)
expect(chat.game.mock.calls.length).toBe(2)
expect(chat.game.mock.calls[0][0]).toBe('room')
expect(chat.game.mock.calls[0][1]).toBe('Player user1 wins 2!')
expect(chat.game.mock.calls[1][0]).toBe('room')
expect(chat.game.mock.calls[1][1]).toBe('Player user2 wins 2!')
expect(chat.toSelfInTopic.mock.calls.length).toBe(2)
expect(chat.toSelfInTopic.mock.calls[0][0]).toBe('id1')
expect(chat.toSelfInTopic.mock.calls[0][1]).toEqual({ money: '10' })
expect(chat.toSelfInTopic.mock.calls[0][2]).toBe('update-money-left')
expect(chat.toSelfInTopic.mock.calls[1][0]).toBe('id2')
expect(chat.toSelfInTopic.mock.calls[1][1]).toEqual({ money: '12' })
expect(chat.toSelfInTopic.mock.calls[1][2]).toBe('update-money-left')
expect(chat.toRoomInTopic.mock.calls.length).toBe(0)
})