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 "/chess-test", ChessTestLive
|
||||||
|
|
||||||
live "/endgames", EndgameLive.PlayerIndex, :index
|
live "/endgames", EndgameLive.PlayerIndex, :index
|
||||||
live "/endgames/:id/play", EndgameLive.Play, :play
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/admin", ChesstrainerWeb do
|
scope "/admin", ChesstrainerWeb do
|
||||||
@@ -81,6 +80,7 @@ defmodule ChesstrainerWeb.Router do
|
|||||||
|
|
||||||
live_session :current_user,
|
live_session :current_user,
|
||||||
on_mount: [{ChesstrainerWeb.UserAuth, :mount_current_scope}] do
|
on_mount: [{ChesstrainerWeb.UserAuth, :mount_current_scope}] do
|
||||||
|
live "/endgames/:id/play", EndgameLive.Play, :play
|
||||||
live "/users/register", UserLive.Registration, :new
|
live "/users/register", UserLive.Registration, :new
|
||||||
live "/users/log-in", UserLive.Login, :new
|
live "/users/log-in", UserLive.Login, :new
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -175,6 +175,30 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
|||||||
end
|
end
|
||||||
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
|
describe "tablebase availability" do
|
||||||
test "blocks the attempt when the tablebase is cooling down", %{conn: conn} 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
|
# Six pieces routes to Lichess, so the cooldown applies (five or fewer
|
||||||
|
|||||||
Reference in New Issue
Block a user