pass user settings controller test

This commit is contained in:
2022-02-16 21:20:04 -05:00
parent 954cdf185c
commit 025706e391
5 changed files with 90 additions and 26 deletions

View File

@ -31,7 +31,14 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ dgettext("prompts", "If your email is in our system")
assert get_flash(conn, :info) =~
dgettext(
"prompts",
"If your email is in our system and it has not been confirmed yet, " <>
"you will receive an email with instructions shortly."
)
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
end
@ -44,8 +51,13 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ "If your email is in our system"
refute Repo.get_by(Accounts.UserToken, user_id: user.id)
assert get_flash(conn, :info) =~
dgettext(
"prompts",
"If your email is in our system and it has not been confirmed yet, " <>
"you will receive an email with instructions shortly."
)
end
test "does not send confirmation token if email is invalid", %{conn: conn} do
@ -55,7 +67,14 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ dgettext("prompts", "If your email is in our system")
assert get_flash(conn, :info) =~
dgettext(
"prompts",
"If your email is in our system and it has not been confirmed yet, " <>
"you will receive an email with instructions shortly."
)
assert Repo.all(Accounts.UserToken) == []
end
end
@ -69,7 +88,10 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ dgettext("prompts", "%{email} confirmed successfully", email: user.email)
assert get_flash(conn, :info) =~
dgettext("prompts", "%{email} confirmed successfully", email: user.email)
assert Accounts.get_user!(user.id).confirmed_at
refute get_session(conn, :user_token)
assert Repo.all(Accounts.UserToken) == []
@ -77,7 +99,9 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
# When not logged in
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ dgettext("errors", "User confirmation link is invalid or it has expired")
assert get_flash(conn, :error) =~
dgettext("errors", "User confirmation link is invalid or it has expired")
# When logged in
conn =
@ -92,7 +116,10 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
test "does not confirm email with invalid token", %{conn: conn, user: user} do
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ dgettext("errors", "User confirmation link is invalid or it has expired")
assert get_flash(conn, :error) =~
dgettext("errors", "User confirmation link is invalid or it has expired")
refute Accounts.get_user!(user.id).confirmed_at
end
end