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