-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.calculateWinningPlayer.test.js
56 lines (47 loc) · 1.45 KB
/
game.calculateWinningPlayer.test.js
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
const Game = require('./game')
const User = require('./user')
const CardExamination = require('./cardExamination')
const t = require('./testHelpers')
const room = 'room'
const user = User('name', room, 'id')
const user2 = User('name2', room, 'id2')
const user3 = User('name3', room, 'id3')
let game
const winCalc = t.WinnerCalculator()
beforeEach(() => {
game = Game(user, room, t.PokerDeck(), winCalc)
game.addPlayer(user)
game.addPlayer(user2)
game.addPlayer(user3)
game.bootstrapGame(user)
})
test('I am able to compute the showdown', () => {
// preflop
game.call(user)
game.call(user2)
game.call(user3)
// flop
game.call(user2)
game.call(user3)
game.call(user)
// turn
game.call(user2)
game.call(user3)
game.call(user)
// river
game.call(user2)
game.call(user3)
const winningState = game.fold(user)
expect(game.currentStep).toBe(4)
expect(winningState.nextState.winnerPlayers[0].user.name).toBe('name3')
expect(winningState.nextState.winnerPlayers[0].money).toBe(120)
expect(winningState.nextState.room).toBe(room)
expect(game.lookupPlayer(user3).money).toBe(120) // wrong, calc win
expect(game.poolPrize).toBe(30)
expect(winCalc.calculateWinningPlayer.mock.calls.length).toBe(1)
const expectedCall = [
CardExamination(1, ['1', '2', '3', '4', '5', '6', '6']),
CardExamination(2, ['1', '2', '3', '4', '5', '6', '6']),
]
expect(winCalc.calculateWinningPlayer.mock.calls[0][0]).toEqual(expectedCall)
})