exmr/test/exmr_web/live/user_confirmation_instructions_live_test.exs

68 lines
2 KiB
Elixir
Raw Permalink Normal View History

2024-11-14 23:33:29 +02:00
defmodule ExmrWeb.UserConfirmationInstructionsLiveTest do
use ExmrWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Exmr.UsersFixtures
alias Exmr.Users
alias Exmr.Repo
setup do
%{user: user_fixture()}
end
describe "Resend confirmation" do
test "renders the resend confirmation page", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/users/confirm")
assert html =~ "Resend confirmation instructions"
end
test "sends a new confirmation token", %{conn: conn, user: user} do
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
{:ok, conn} =
lv
|> form("#resend_confirmation_form", user: %{email: user.email})
|> render_submit()
|> follow_redirect(conn, ~p"/")
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
"If your email is in our system"
assert Repo.get_by!(Users.UserToken, user_id: user.id).context == "confirm"
end
test "does not send confirmation token if user is confirmed", %{conn: conn, user: user} do
Repo.update!(Users.User.confirm_changeset(user))
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
{:ok, conn} =
lv
|> form("#resend_confirmation_form", user: %{email: user.email})
|> render_submit()
|> follow_redirect(conn, ~p"/")
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
"If your email is in our system"
refute Repo.get_by(Users.UserToken, user_id: user.id)
end
test "does not send confirmation token if email is invalid", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
{:ok, conn} =
lv
|> form("#resend_confirmation_form", user: %{email: "unknown@example.com"})
|> render_submit()
|> follow_redirect(conn, ~p"/")
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
"If your email is in our system"
assert Repo.all(Users.UserToken) == []
end
end
end