Skip to content

Commit 428a5e8

Browse files
committed
Minor change
1 parent 17e195d commit 428a5e8

2 files changed

Lines changed: 48 additions & 25 deletions

File tree

apps/codebattle/lib/codebattle_web/controllers/tournament_controller.ex

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,25 @@ defmodule CodebattleWeb.TournamentController do
7373
if latest_game_id do
7474
redirect(conn, to: Routes.game_path(conn, :show, latest_game_id))
7575
else
76-
redirect(conn,
77-
to:
78-
Routes.tournament_path(
79-
conn,
80-
:show,
81-
tournament.id,
82-
tournament_access_params(params)
83-
)
84-
)
76+
render_tournament(conn, tournament, params)
8577
end
8678
else
87-
conn
88-
|> put_view(CodebattleWeb.TournamentView)
89-
|> put_meta_tags(%{
90-
title: tournament.name,
91-
description: tournament.description,
92-
image: Routes.tournament_image_url(conn, :show, tournament.id),
93-
url: Routes.tournament_url(conn, :show, tournament.id)
94-
})
95-
|> put_gon(tournament_id: tournament.id)
96-
|> put_gon(event_id: tournament.event_id)
97-
|> put_gon(tournament_access_token: params["access_token"])
98-
|> render("show.html")
79+
render_tournament(conn, tournament, params)
9980
end
10081
end
10182

102-
defp tournament_access_params(%{"access_token" => access_token}) when is_binary(access_token) do
103-
[access_token: access_token]
83+
defp render_tournament(conn, tournament, params) do
84+
conn
85+
|> put_view(CodebattleWeb.TournamentView)
86+
|> put_meta_tags(%{
87+
title: tournament.name,
88+
description: tournament.description,
89+
image: Routes.tournament_image_url(conn, :show, tournament.id),
90+
url: Routes.tournament_url(conn, :show, tournament.id)
91+
})
92+
|> put_gon(tournament_id: tournament.id)
93+
|> put_gon(event_id: tournament.event_id)
94+
|> put_gon(tournament_access_token: params["access_token"])
95+
|> render("show.html")
10496
end
105-
106-
defp tournament_access_params(_params), do: []
10797
end

apps/codebattle/test/codebattle_web/controllers/live_view_tournament_controller_test.exs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,37 @@ defmodule CodebattleWeb.LiveViewTournamentControllerTest do
112112
|> get(Routes.tournament_path(conn, :show, 12_313_221))
113113
end
114114
end
115+
116+
test "renders tournament page when redirect-to-latest-game is enabled and user has no latest game", %{conn: conn} do
117+
FunWithFlags.enable(:tournament_redirect_to_latest_game)
118+
119+
on_exit(fn ->
120+
FunWithFlags.disable(:tournament_redirect_to_latest_game)
121+
end)
122+
123+
creator = insert(:user)
124+
125+
{:ok, tournament} =
126+
Tournament.Context.create(%{
127+
"starts_at" => "2022-02-24T06:00",
128+
"name" => "Redirect Guard Tournament",
129+
"description" => "Redirect Guard Tournament description",
130+
"user_timezone" => "Etc/UTC",
131+
"level" => "easy",
132+
"creator" => creator,
133+
"access_type" => "token",
134+
"access_token" => "access_token",
135+
"break_duration_seconds" => 0,
136+
"type" => "swiss",
137+
"state" => "waiting_participants",
138+
"players_limit" => 200
139+
})
140+
141+
new_conn =
142+
conn
143+
|> put_session(:user_id, creator.id)
144+
|> get(Routes.tournament_path(conn, :show, tournament.id))
145+
146+
assert new_conn.status == 200
147+
end
115148
end

0 commit comments

Comments
 (0)