pass user reset password controller test
This commit is contained in:
parent
4d7a606479
commit
36b814a8a9
@ -1,9 +1,13 @@
|
|||||||
defmodule CanneryWeb.UserResetPasswordControllerTest do
|
defmodule CanneryWeb.UserResetPasswordControllerTest do
|
||||||
use CanneryWeb.ConnCase, async: true
|
@moduledoc """
|
||||||
|
Tests the user reset password controller
|
||||||
|
"""
|
||||||
|
|
||||||
alias Cannery.Accounts
|
use CanneryWeb.ConnCase, async: true
|
||||||
alias Cannery.Repo
|
import CanneryWeb.Gettext
|
||||||
import Cannery.AccountsFixtures
|
alias Cannery.{Accounts, Repo}
|
||||||
|
|
||||||
|
@moduletag :user_reset_password_controller_test
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
%{user: user_fixture()}
|
%{user: user_fixture()}
|
||||||
@ -13,7 +17,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
test "renders the reset password page", %{conn: conn} do
|
test "renders the reset password page", %{conn: conn} do
|
||||||
conn = get(conn, Routes.user_reset_password_path(conn, :new))
|
conn = get(conn, Routes.user_reset_password_path(conn, :new))
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ "<h1>Forgot your password?</h1>"
|
assert response =~ dgettext("actions", "Forgot your password?")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,7 +30,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
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"
|
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,7 +41,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
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) == []
|
assert Repo.all(Accounts.UserToken) == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -54,13 +58,15 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
|
|
||||||
test "renders reset password", %{conn: conn, token: token} do
|
test "renders reset password", %{conn: conn, token: token} do
|
||||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
|
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
|
end
|
||||||
|
|
||||||
test "does not render reset password with invalid token", %{conn: conn} do
|
test "does not render reset password with invalid token", %{conn: conn} do
|
||||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
|
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
|
||||||
assert redirected_to(conn) == "/"
|
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
|
end
|
||||||
|
|
||||||
@ -85,7 +91,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
|
|
||||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||||
refute get_session(conn, :user_token)
|
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")
|
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -99,15 +105,17 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ "<h1>Reset password</h1>"
|
assert response =~ gettext("Reset password")
|
||||||
assert response =~ "should be at least 12 character(s)"
|
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||||
assert response =~ "does not match password"
|
assert response =~ dgettext("errors", "does not match password")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not reset password with invalid token", %{conn: conn} do
|
test "does not reset password with invalid token", %{conn: conn} do
|
||||||
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
|
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
|
||||||
assert redirected_to(conn) == "/"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user