pass user reset password controller test

This commit is contained in:
shibao 2022-02-16 21:10:40 -05:00
parent 4d7a606479
commit 36b814a8a9
1 changed files with 22 additions and 14 deletions

View File

@ -1,9 +1,13 @@
defmodule CanneryWeb.UserResetPasswordControllerTest do
use CanneryWeb.ConnCase, async: true
@moduledoc """
Tests the user reset password controller
"""
alias Cannery.Accounts
alias Cannery.Repo
import Cannery.AccountsFixtures
use CanneryWeb.ConnCase, async: true
import CanneryWeb.Gettext
alias Cannery.{Accounts, Repo}
@moduletag :user_reset_password_controller_test
setup do
%{user: user_fixture()}
@ -13,7 +17,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
test "renders the reset password page", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :new))
response = html_response(conn, 200)
assert response =~ "<h1>Forgot your password?</h1>"
assert response =~ dgettext("actions", "Forgot your password?")
end
end
@ -26,7 +30,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ "If your email is in our system"
assert get_flash(conn, :info) =~ dgettext("prompts", "If your email is in our system")
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
end
@ -37,7 +41,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ "If your email is in our system"
assert get_flash(conn, :info) =~ dgettext("prompts", "If your email is in our system")
assert Repo.all(Accounts.UserToken) == []
end
end
@ -54,13 +58,15 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
test "renders reset password", %{conn: conn, token: token} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
assert html_response(conn, 200) =~ "<h1>Reset password</h1>"
assert html_response(conn, 200) =~ dgettext("actions", "Reset password")
end
test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
assert get_flash(conn, :error) =~
dgettext("errors", "Reset password link is invalid or it has expired")
end
end
@ -85,7 +91,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Password reset successfully"
assert get_flash(conn, :info) =~ dgettext("prompts", "Password reset successfully")
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
end
@ -99,15 +105,17 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
})
response = html_response(conn, 200)
assert response =~ "<h1>Reset password</h1>"
assert response =~ "should be at least 12 character(s)"
assert response =~ "does not match password"
assert response =~ gettext("Reset password")
assert response =~ dgettext("errors", "should be at least 12 character(s)")
assert response =~ dgettext("errors", "does not match password")
end
test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
assert get_flash(conn, :error) =~
dgettext("errors", "Reset password link is invalid or it has expired")
end
end
end