-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.test.js
More file actions
49 lines (45 loc) · 1.51 KB
/
game.test.js
File metadata and controls
49 lines (45 loc) · 1.51 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
const Game = require('./game')
const User = require('./user')
const WaitingState = require('./waitingState')
const pokerDeck = function PokerDeck() {
return {
drawTwoCards() {
return ['1', '2']
},
drawThreeCards() {
return ['3', '4', '5']
},
drawOneCard() {
return '6'
},
}
}
const room = 'room'
const user = User('name', room, 'id')
const user2 = User('name2', room, 'id2')
const game = Game(user, room, pokerDeck())
game.addPlayer(user)
game.addPlayer(user2)
test('I can bootstrap a game', () => {
const state = game.bootstrapGame(user)
const expectedWaitingState = WaitingState(room, user2.name, user2.id)
expect(game.lastPlayerInTurn).toBe(0)
expect(state.startedBy).toBe(user.name)
expect(state.roomId).toBe(room)
expect(state.dealerName).toBe('name')
expect(state.smallBlindName).toBe('name2')
expect(state.bigBlindName).toBe('name')
expect(state.poolPrize).toBe(15)
expect(state.hands[0].id).toBe('id')
expect(state.hands[0].cards).toEqual(['1', '2'])
expect(state.hands[0].moneyLeft).toBe(90)
expect(state.hands[1].id).toBe('id2')
expect(state.hands[1].cards).toEqual(['1', '2'])
expect(state.hands[1].moneyLeft).toBe(95)
expect(JSON.stringify(state.nextState)).toBe(JSON.stringify(expectedWaitingState))
})
test("I can't bootstrap a game if not started by the owner", () => {
const errorState = game.bootstrapGame(user2)
expect(errorState.room).toBe(user2.id)
expect(errorState.message).toBe('You cannot start a game that you did not create')
})