Files
chess-endgame-trainer/test/chesstrainer_web/controllers/user_confirmation_controller_test.exs
T
owenrees aebb2aecfb Fix the error-state regressions from the #164 verification (#171) (#173)
T8: the invalid-FEN flash is generic; the client message and FEN go to the
log. A2: an expired confirmation link says so and lands on log-in, where an
unconfirmed account resends the email. W3: the connection banner gains Reload
and Home actions. D1: a failed export logs and redirects to the data tab with
a support address instead of a bare 500. D2: an unknown export format renders
the styled 404. H1: the empty-database home CTA points at the guest trainer
instead of auth-gated /endgames. X2/X3: the importer hides inspect(reason)
behind generic copy and logs it.

Adds coverage for the T8 copy, A2 destination, D2 404 page, H1 CTA and the W3
actions; the H1 tests now restore the curated-code override so async page
tests cannot poison each other.
2026-11-13 16:46:29 +01:00

56 lines
1.7 KiB
Elixir

defmodule ChesstrainerWeb.UserConfirmationControllerTest do
use ChesstrainerWeb.ConnCase, async: true
import Chesstrainer.AccountsFixtures
alias Chesstrainer.Accounts
alias Chesstrainer.Accounts.User
alias Chesstrainer.MailingList
alias Chesstrainer.MailingList.Subscriber
alias Chesstrainer.Repo
setup do
%{user: unconfirmed_user_fixture()}
end
describe "GET /users/confirm/:token" do
test "confirms the user and redirects to the login page", %{conn: conn, user: user} do
token =
extract_user_token(fn url ->
Accounts.deliver_user_confirmation_instructions(user, url)
end)
conn = get(conn, ~p"/users/confirm/#{token}")
assert Phoenix.Flash.get(conn.assigns.flash, :info) == "User confirmed successfully."
assert redirected_to(conn) == ~p"/users/log-in"
assert Repo.get!(User, user.id).confirmed_at
end
test "redirects with an error for an invalid token", %{conn: conn} do
conn = get(conn, ~p"/users/confirm/oops")
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
"That confirmation link is invalid or has expired. Log in to request a new one."
assert redirected_to(conn) == ~p"/users/log-in"
end
test "confirms a linked mailing-list opt-in", %{conn: conn, user: user} do
{:ok, _subscriber} = MailingList.subscribe_user(user)
token =
extract_user_token(fn url ->
Accounts.deliver_user_confirmation_instructions(user, url)
end)
get(conn, ~p"/users/confirm/#{token}")
assert %Subscriber{confirmed_at: confirmed_at} =
Repo.get_by(Subscriber, user_id: user.id)
assert confirmed_at
end
end
end