pass user settings controller test
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
@moduledoc """
|
||||
Tests the user settings controller
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Accounts
|
||||
import Cannery.AccountsFixtures
|
||||
|
||||
@moduletag :user_settings_controller_test
|
||||
|
||||
setup :register_and_log_in_user
|
||||
|
||||
@ -10,7 +15,7 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
test "renders settings page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :edit))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ gettext("Settings")
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in" do
|
||||
@ -34,7 +39,10 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
|
||||
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
assert get_flash(new_password_conn, :info) =~ "Password updated successfully"
|
||||
|
||||
assert get_flash(new_password_conn, :info) =~
|
||||
dgettext("actions", "Password updated successfully")
|
||||
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
@ -50,10 +58,10 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
})
|
||||
|
||||
response = html_response(old_password_conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
assert response =~ "is not valid"
|
||||
assert response =~ gettext("Settings")
|
||||
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||
assert response =~ dgettext("errors", "does not match password")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
|
||||
assert get_session(old_password_conn, :user_token) == get_session(conn, :user_token)
|
||||
end
|
||||
@ -70,7 +78,13 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ "A link to confirm your email"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"A link to confirm your email change has been sent to the new address."
|
||||
)
|
||||
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
@ -83,9 +97,9 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "is not valid"
|
||||
assert response =~ gettext("Settings")
|
||||
assert response =~ dgettext("errors", "must have the @ sign and no spaces")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
end
|
||||
end
|
||||
|
||||
@ -104,19 +118,24 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ "Email changed successfully"
|
||||
assert get_flash(conn, :info) =~ dgettext("prompts", "Email changed successfully")
|
||||
refute Accounts.get_user_by_email(user.email)
|
||||
assert Accounts.get_user_by_email(email)
|
||||
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "Email change link is invalid or it has expired")
|
||||
end
|
||||
|
||||
test "does not update email with invalid token", %{conn: conn, user: user} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "Email change link is invalid or it has expired")
|
||||
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user