fix settings controller tests (slight rewrite)
This commit is contained in:
parent
6c6810b96e
commit
16396c6a12
|
@ -61,7 +61,7 @@ defmodule PokemonCoutureWeb.UserSettingsControllerTest do
|
||||||
|
|
||||||
describe "PUT /users/settings (change email form)" do
|
describe "PUT /users/settings (change email form)" do
|
||||||
@tag :capture_log
|
@tag :capture_log
|
||||||
test "updates the user email", %{conn: conn, user: user} do
|
test "updates the user email", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||||
"action" => "update_email",
|
"action" => "update_email",
|
||||||
|
@ -71,7 +71,6 @@ defmodule PokemonCoutureWeb.UserSettingsControllerTest do
|
||||||
|
|
||||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
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) =~ "A link to confirm your email"
|
||||||
assert Accounts.get_user_by_email(user.email)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not update email on invalid data", %{conn: conn} do
|
test "does not update email on invalid data", %{conn: conn} do
|
||||||
|
@ -102,11 +101,13 @@ defmodule PokemonCoutureWeb.UserSettingsControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
|
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
|
||||||
|
original_email = user.email
|
||||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||||
assert get_flash(conn, :info) =~ "Email changed successfully"
|
assert get_flash(conn, :info) =~ "Email changed successfully"
|
||||||
refute Accounts.get_user_by_email(user.email)
|
updated_user = Accounts.get_user_by_username(user.username)
|
||||||
assert Accounts.get_user_by_email(email)
|
refute original_email == updated_user.email
|
||||||
|
assert email == updated_user.email
|
||||||
|
|
||||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||||
|
@ -114,10 +115,12 @@ defmodule PokemonCoutureWeb.UserSettingsControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not update email with invalid token", %{conn: conn, user: user} do
|
test "does not update email with invalid token", %{conn: conn, user: user} do
|
||||||
|
original_email = user.email
|
||||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
|
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
|
||||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
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) =~ "Email change link is invalid or it has expired"
|
||||||
assert Accounts.get_user_by_email(user.email)
|
updated_user_email = Accounts.get_user_by_username(user.username).email
|
||||||
|
assert updated_user_email == original_email
|
||||||
end
|
end
|
||||||
|
|
||||||
test "redirects if user is not logged in", %{token: token} do
|
test "redirects if user is not logged in", %{token: token} do
|
||||||
|
|
Loading…
Reference in New Issue