mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Make the play screen current-user aware (#38)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user