Skip to content

Commit b06e2c4

Browse files
committed
Minor fix
1 parent f5b550d commit b06e2c4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

apps/codebattle/lib/codebattle_web/channels/game_channel.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ defmodule CodebattleWeb.GameChannel do
6565
%{entries: ranking}
6666
end)
6767

68-
in_main_draw = is_player? and current_player.draw_index == current_player.max_draw_index
68+
in_main_draw =
69+
match?(%{draw_index: draw_index, max_draw_index: draw_index}, current_player)
6970

7071
{:ok,
7172
%{

apps/codebattle/test/codebattle_web/channels/game_channel_test.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ defmodule CodebattleWeb.GameChannelTest do
7373
assert response.tournament.tournament_id == tournament.id
7474
end
7575

76+
test "sends tournament game info for player missing from tournament roster", %{
77+
user1: user1,
78+
user2: user2,
79+
socket1: socket1
80+
} do
81+
tournament = insert(:tournament, players: %{}, matches: %{}, players_count: 0)
82+
83+
{:ok, game} =
84+
Game.Context.create_game(%{
85+
state: "playing",
86+
players: [user1, user2],
87+
level: "easy",
88+
tournament_id: tournament.id
89+
})
90+
91+
{:ok, response, _socket} =
92+
subscribe_and_join(socket1, GameChannel, game_topic(game))
93+
94+
assert response.game.id == game.id
95+
assert response.current_player == nil
96+
assert response.in_main_draw == false
97+
assert response.active_game_id == nil
98+
assert response.tournament.tournament_id == tournament.id
99+
end
100+
76101
test "pushes head to head after join", %{user1: user1, socket1: socket1} do
77102
{:ok, game} =
78103
Game.Context.create_game(%{state: "waiting_opponent", players: [user1], level: "easy"})

0 commit comments

Comments
 (0)