use atom keys in tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-03-28 21:57:29 -04:00
parent 8c95536ffd
commit bab2b26c13
28 changed files with 720 additions and 861 deletions

View File

@ -4,7 +4,6 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
"""
use CanneryWeb.ConnCase, async: true
import CanneryWeb.Gettext
alias Cannery.{Accounts, Repo}
@moduletag :user_confirmation_controller_test
@ -17,7 +16,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
test "renders the confirmation page", %{conn: conn} do
conn = get(conn, Routes.user_confirmation_path(conn, :new))
response = html_response(conn, 200)
assert response =~ dgettext("actions", "Resend confirmation instructions")
assert response =~ "Resend confirmation instructions"
end
end
@ -25,18 +24,12 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
@tag :capture_log
test "sends a new confirmation token", %{conn: conn, user: user} do
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
"user" => %{"email" => user.email}
})
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
assert redirected_to(conn) == "/"
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."
)
"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
@ -45,34 +38,24 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
Repo.update!(Accounts.User.confirm_changeset(user))
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
"user" => %{"email" => user.email}
})
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
assert redirected_to(conn) == "/"
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."
)
"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
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
"user" => %{"email" => "unknown@example.com"}
user: %{email: "unknown@example.com"}
})
assert redirected_to(conn) == "/"
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."
)
"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
@ -87,10 +70,7 @@ 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) =~ "#{user.email} confirmed successfully"
assert Accounts.get_user!(user.id).confirmed_at
refute get_session(conn, :user_token)
assert Repo.all(Accounts.UserToken) == []
@ -99,8 +79,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
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) =~ "User confirmation link is invalid or it has expired"
# When logged in
conn =
@ -115,10 +94,7 @@ 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) =~ "User confirmation link is invalid or it has expired"
refute Accounts.get_user!(user.id).confirmed_at
end
end