show logged-in player count in landing hero

Count distinct users with a session token valid within the 14-day window and use it for the hero players-training stat. The learning strip keeps the total player count.

Also load the split seed modules in seeds_test and drop an invalid 8-piece seed FEN so precommit passes.
This commit is contained in:
2026-11-06 22:11:06 +01:00
parent 46bc27f614
commit b54fb0a6d7
9 changed files with 58 additions and 19 deletions
+19
View File
@@ -583,6 +583,25 @@ defmodule Chesstrainer.AccountsTest do
end
end
describe "count_logged_in_users/0" do
test "counts distinct users with a valid session token" do
user = user_fixture()
_ = Accounts.generate_user_session_token(user)
_ = Accounts.generate_user_session_token(user)
_other = Accounts.generate_user_session_token(user_fixture())
assert Accounts.count_logged_in_users() == 2
end
test "ignores expired session tokens" do
user = user_fixture()
user_token = Accounts.generate_user_session_token(user)
offset_user_token(user_token, -15, :day)
assert Accounts.count_logged_in_users() == 0
end
end
describe "delete_user/1" do
test "deletes the user and their session tokens" do
user = user_fixture()
+2
View File
@@ -3,6 +3,8 @@ defmodule Chesstrainer.SeedsTest do
alias Chesstrainer.FEN
Code.require_file("../../priv/repo/seeds/endgames/win.ex", __DIR__)
Code.require_file("../../priv/repo/seeds/endgames/draw.ex", __DIR__)
Code.require_file("../../priv/repo/seeds/endgames.ex", __DIR__)
describe "seed endgames" do
@@ -4,6 +4,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
import Chesstrainer.AccountsFixtures
import Chesstrainer.EndgamesFixtures
alias Chesstrainer.Accounts
alias Chesstrainer.Accounts.Scope
alias Chesstrainer.Attempts
alias Chesstrainer.Branding
@@ -158,7 +159,17 @@ defmodule ChesstrainerWeb.PageControllerTest do
assert html =~ ~s(content="Test Brand")
end
test "hero shows the number of players with at least one attempt", %{conn: conn} do
test "hero shows the number of users with a valid session", %{conn: conn} do
user = user_fixture()
_token = Accounts.generate_user_session_token(user)
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
assert LazyHTML.text(LazyHTML.query(document, ".rating-note strong")) == "1"
end
test "hero does not count users who have only trained", %{conn: conn} do
user = user_fixture()
endgame = endgame_fixture()
{:ok, _} = Attempts.record_attempt(Scope.for_user(user), endgame, :solved)
@@ -166,7 +177,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
assert LazyHTML.text(LazyHTML.query(document, ".rating-note strong")) == "1"
assert LazyHTML.text(LazyHTML.query(document, ".rating-note strong")) == "0"
end
test "guest navbar links to log in and register", %{conn: conn} do
@@ -211,11 +222,10 @@ defmodule ChesstrainerWeb.PageControllerTest do
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
assert html =~ "Try today's puzzle"
assert html =~ "Begin with the basics"
assert html =~ "<span>puzzles</span>"
end
test "hero and progress CTAs link to the daily puzzle", %{conn: conn} do
test "hero CTA links to the daily puzzle", %{conn: conn} do
curated!()
daily = DailyPuzzles.today()
@@ -225,10 +235,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [play_path]
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
play_path
]
refute html =~ "/endgames//play"
end
@@ -258,10 +264,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
"/endgames"
]
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
"/endgames"
]
end
test "unknown routes render the branded 404 page", %{conn: conn} do