-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.fold.test.js
More file actions
49 lines (42 loc) · 1.52 KB
/
game.fold.test.js
File metadata and controls
49 lines (42 loc) · 1.52 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 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
beforeEach(() => {
game = Game(user, room, t.PokerDeck())
game.addPlayer(user)
game.addPlayer(user2)
game.addPlayer(user3)
game.bootstrapGame(user)
})
test("I can bet on the game, if it's my turn", () => {
const foldState = game.fold(user)
expect(foldState.foldingPlayerName).toBe('name')
const expectedWaitingState = WaitingState(room, 'name2')
expect(foldState.nextState.room).toBe(expectedWaitingState.room)
expect(foldState.nextState.nextPlayerName).toBe(expectedWaitingState.nextPlayerName)
expect(foldState.room).toBe('room')
})
test("I cannot bet on the game, if it's not my turn", () => {
const errorState = game.fold(user2)
expect(errorState.room).toBe('id2')
expect(errorState.message).toBe("You cannot !fold because it's not your turn")
})
test('The next player will be the one that has not already folded', () => {
const user4 = User('name4', room, 'id4')
const game1 = Game(user, room, t.PokerDeck())
game1.addPlayer(user)
game1.addPlayer(user2)
game1.addPlayer(user3)
game1.addPlayer(user4)
game1.bootstrapGame(user)
game1.players[1].hasFolded = true
const foldState = game1.fold(user4)
expect(foldState.nextState.room).toBe(room)
expect(foldState.nextState.nextPlayerName).toBe('name')
})