-
Notifications
You must be signed in to change notification settings - Fork 35
/
integration_test.exs
54 lines (43 loc) · 1.67 KB
/
integration_test.exs
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
defmodule Blackjack.IntegrationTest do
use ExUnit.Case, async: true
@behaviour Blackjack.PlayerNotifier
test "game with two players" do
{:ok, _} = Blackjack.RoundServer.start_playing(
:round_1,
[
%{id: :player_1, callback_mod: __MODULE__, callback_arg: self()},
%{id: :player_2, callback_mod: __MODULE__, callback_arg: self()}
]
)
assert_receive {:player_1, {:deal_card, _card}}
assert_receive {:player_1, {:deal_card, _card}}
assert_receive {:player_1, :move}
hit_until_busted(:round_1, :player_1)
assert_receive {:player_2, :move}
assert_receive {:player_2, {:deal_card, _card}}
assert_receive {:player_2, {:deal_card, _card}}
Blackjack.RoundServer.move(:round_1, :player_2, :stand)
assert_receive {:player_1, {:winners, [:player_2]}}
assert_receive {:player_2, {:winners, [:player_2]}}
refute_receive _
end
defp hit_until_busted(round_id, player_id) do
Blackjack.RoundServer.move(round_id, player_id, :hit)
assert_receive {^player_id, {:deal_card, _card}}
assert_receive {^player_id, move_or_busted}
case move_or_busted do
:move -> hit_until_busted(round_id, player_id)
:busted -> :ok
end
end
def deal_card(test_pid, player_id, card), do:
send(test_pid, {player_id, {:deal_card, card}})
def move(test_pid, player_id), do:
send(test_pid, {player_id, :move})
def busted(test_pid, player_id), do:
send(test_pid, {player_id, :busted})
def unauthorized_move(test_pid, player_id), do:
send(test_pid, {player_id, :unauthorized_move})
def winners(test_pid, player_id, winner_ids), do:
send(test_pid, {player_id, {:winners, winner_ids}})
end