change conn case user assign to user
This commit is contained in:
parent
f1889aec07
commit
cbee15b70f
@ -27,7 +27,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
|
|
||||||
describe "PUT /users/settings (change password form)" do
|
describe "PUT /users/settings (change password form)" do
|
||||||
test "updates the user password and resets tokens",
|
test "updates the user password and resets tokens",
|
||||||
%{conn: conn, current_user: current_user} do
|
%{conn: conn, user: user} do
|
||||||
new_password_conn =
|
new_password_conn =
|
||||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||||
"action" => "update_password",
|
"action" => "update_password",
|
||||||
@ -44,7 +44,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
assert get_flash(new_password_conn, :info) =~
|
assert get_flash(new_password_conn, :info) =~
|
||||||
dgettext("actions", "Password updated successfully")
|
dgettext("actions", "Password updated successfully")
|
||||||
|
|
||||||
assert Accounts.get_user_by_email_and_password(current_user.email, "new valid password")
|
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not update password on invalid data", %{conn: conn} do
|
test "does not update password on invalid data", %{conn: conn} do
|
||||||
@ -70,7 +70,7 @@ defmodule MemexWeb.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, current_user: current_user} do
|
test "updates the user email", %{conn: conn, user: user} 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",
|
||||||
@ -86,7 +86,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
"A link to confirm your email change has been sent to the new address."
|
"A link to confirm your email change has been sent to the new address."
|
||||||
)
|
)
|
||||||
|
|
||||||
assert Accounts.get_user_by_email(current_user.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
|
||||||
@ -105,14 +105,14 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /users/settings/confirm_email/:token" do
|
describe "GET /users/settings/confirm_email/:token" do
|
||||||
setup %{current_user: current_user} do
|
setup %{user: user} do
|
||||||
email = unique_user_email()
|
email = unique_user_email()
|
||||||
|
|
||||||
token =
|
token =
|
||||||
extract_user_token(fn url ->
|
extract_user_token(fn url ->
|
||||||
Accounts.deliver_update_email_instructions(
|
Accounts.deliver_update_email_instructions(
|
||||||
%{current_user | email: email},
|
%{user | email: email},
|
||||||
current_user.email,
|
user.email,
|
||||||
url
|
url
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
@ -121,11 +121,11 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "updates the user email once",
|
test "updates the user email once",
|
||||||
%{conn: conn, current_user: current_user, token: token, email: email} do
|
%{conn: conn, user: user, token: token, email: email} do
|
||||||
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) =~ dgettext("prompts", "Email changed successfully")
|
assert get_flash(conn, :info) =~ dgettext("prompts", "Email changed successfully")
|
||||||
refute Accounts.get_user_by_email(current_user.email)
|
refute Accounts.get_user_by_email(user.email)
|
||||||
assert Accounts.get_user_by_email(email)
|
assert Accounts.get_user_by_email(email)
|
||||||
|
|
||||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||||
@ -135,14 +135,14 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
|||||||
dgettext("errors", "Email change link is invalid or it has expired")
|
dgettext("errors", "Email change link is invalid or it has expired")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not update email with invalid token", %{conn: conn, current_user: current_user} do
|
test "does not update email with invalid token", %{conn: conn, user: user} do
|
||||||
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) =~
|
assert get_flash(conn, :error) =~
|
||||||
dgettext("errors", "Email change link is invalid or it has expired")
|
dgettext("errors", "Email change link is invalid or it has expired")
|
||||||
|
|
||||||
assert Accounts.get_user_by_email(current_user.email)
|
assert Accounts.get_user_by_email(user.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
|
||||||
|
@ -16,9 +16,9 @@ defmodule MemexWeb.InviteLiveTest do
|
|||||||
describe "Index" do
|
describe "Index" do
|
||||||
setup [:register_and_log_in_user]
|
setup [:register_and_log_in_user]
|
||||||
|
|
||||||
setup %{current_user: current_user} do
|
setup %{user: user} do
|
||||||
{:ok, invite} = Invites.create_invite(current_user, @create_attrs)
|
{:ok, invite} = Invites.create_invite(user, @create_attrs)
|
||||||
%{invite: invite, current_user: current_user}
|
%{invite: invite, user: user}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "lists all invites", %{conn: conn, invite: invite} do
|
test "lists all invites", %{conn: conn, invite: invite} do
|
||||||
|
@ -50,10 +50,10 @@ defmodule MemexWeb.ConnCase do
|
|||||||
test context.
|
test context.
|
||||||
"""
|
"""
|
||||||
@spec register_and_log_in_user(%{conn: Plug.Conn.t()}) ::
|
@spec register_and_log_in_user(%{conn: Plug.Conn.t()}) ::
|
||||||
%{conn: Plug.Conn.t(), current_user: User.t()}
|
%{conn: Plug.Conn.t(), user: User.t()}
|
||||||
def register_and_log_in_user(%{conn: conn}) do
|
def register_and_log_in_user(%{conn: conn}) do
|
||||||
current_user = user_fixture() |> confirm_user()
|
user = user_fixture() |> confirm_user()
|
||||||
%{conn: log_in_user(conn, current_user), current_user: current_user}
|
%{conn: log_in_user(conn, user), user: user}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec confirm_user(User.t()) :: User.t()
|
@spec confirm_user(User.t()) :: User.t()
|
||||||
|
Loading…
Reference in New Issue
Block a user