email signup up flow in dev mode, therefore in place for prod

This commit is contained in:
2026-11-05 14:11:12 +01:00
parent 6b0e0ed352
commit e89df68e7d
12 changed files with 271 additions and 11 deletions
@@ -0,0 +1,37 @@
defmodule ChesstrainerWeb.UserConfirmationControllerTest do
use ChesstrainerWeb.ConnCase, async: true
import Chesstrainer.AccountsFixtures
alias Chesstrainer.Accounts
alias Chesstrainer.Accounts.User
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) ==
"User not found or token is invalid."
assert redirected_to(conn) == ~p"/users/register"
end
end
end
@@ -2,6 +2,7 @@ defmodule ChesstrainerWeb.UserSessionControllerTest do
use ChesstrainerWeb.ConnCase, async: true
import Chesstrainer.AccountsFixtures
import Swoosh.TestAssertions
setup do
%{user: user_fixture()}
@@ -75,6 +76,25 @@ defmodule ChesstrainerWeb.UserSessionControllerTest do
assert redirected_to(conn) == ~p"/users/log-in"
end
test "does not log in an unconfirmed user and resends confirmation instructions", %{
conn: conn
} do
user = unconfirmed_user_fixture()
conn =
post(conn, ~p"/users/log-in", %{
"user" => %{"email" => user.email, "password" => valid_user_password()}
})
refute get_session(conn, :user_token)
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
"Invalid email, username or password"
assert redirected_to(conn) == ~p"/users/log-in"
assert_email_sent(subject: "Confirmation instructions")
end
end
describe "DELETE /users/log-out" do
@@ -3,6 +3,7 @@ defmodule ChesstrainerWeb.UserLive.RegistrationTest do
import Phoenix.LiveViewTest
import Chesstrainer.AccountsFixtures
import Swoosh.TestAssertions
describe "Registration page" do
test "renders registration page", %{conn: conn} do
@@ -56,7 +57,10 @@ defmodule ChesstrainerWeb.UserLive.RegistrationTest do
render_submit(form)
|> follow_redirect(conn, ~p"/users/log-in")
assert html =~ "Account created successfully"
assert html =~
"An email with instructions for how to confirm your email address has been sent to your inbox."
assert_email_sent(subject: "Confirmation instructions")
end
test "renders errors for duplicated email", %{conn: conn} do