diff --git a/lib/chesstrainer_web/router.ex b/lib/chesstrainer_web/router.ex index 0ac196e..ad1ac98 100644 --- a/lib/chesstrainer_web/router.ex +++ b/lib/chesstrainer_web/router.ex @@ -25,7 +25,6 @@ defmodule ChesstrainerWeb.Router do live "/chess-test", ChessTestLive live "/endgames", EndgameLive.PlayerIndex, :index - live "/endgames/:id/play", EndgameLive.Play, :play end scope "/admin", ChesstrainerWeb do @@ -81,6 +80,7 @@ defmodule ChesstrainerWeb.Router do live_session :current_user, on_mount: [{ChesstrainerWeb.UserAuth, :mount_current_scope}] do + live "/endgames/:id/play", EndgameLive.Play, :play live "/users/register", UserLive.Registration, :new live "/users/log-in", UserLive.Login, :new end diff --git a/test/chesstrainer_web/live/endgame_live/play_test.exs b/test/chesstrainer_web/live/endgame_live/play_test.exs index cd527bb..023db04 100644 --- a/test/chesstrainer_web/live/endgame_live/play_test.exs +++ b/test/chesstrainer_web/live/endgame_live/play_test.exs @@ -175,6 +175,30 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do end end + describe "current scope" do + test "carries the signed-in user into the play screen", %{conn: conn} do + user = Chesstrainer.AccountsFixtures.user_fixture() + endgame = endgame_fixture() + seed_tablebase(endgame.fen) + + {:ok, view, _html} = + conn + |> log_in_user(user) + |> live(~p"/endgames/#{endgame}/play") + + assert :sys.get_state(view.pid).socket.assigns.current_scope.user.id == user.id + end + + test "is nil for an anonymous visitor", %{conn: conn} do + endgame = endgame_fixture() + seed_tablebase(endgame.fen) + + {:ok, view, _html} = live(conn, ~p"/endgames/#{endgame}/play") + + assert :sys.get_state(view.pid).socket.assigns.current_scope == nil + end + end + describe "tablebase availability" do test "blocks the attempt when the tablebase is cooling down", %{conn: conn} do # Six pieces routes to Lichess, so the cooldown applies (five or fewer