change conn case user assign to user

This commit is contained in:
shibao 2022-11-17 22:32:27 -05:00
parent f1889aec07
commit cbee15b70f
3 changed files with 17 additions and 17 deletions

View File

@ -27,7 +27,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
describe "PUT /users/settings (change password form)" do
test "updates the user password and resets tokens",
%{conn: conn, current_user: current_user} do
%{conn: conn, user: user} do
new_password_conn =
put(conn, Routes.user_settings_path(conn, :update), %{
"action" => "update_password",
@ -44,7 +44,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
assert get_flash(new_password_conn, :info) =~
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
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
@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 =
put(conn, Routes.user_settings_path(conn, :update), %{
"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."
)
assert Accounts.get_user_by_email(current_user.email)
assert Accounts.get_user_by_email(user.email)
end
test "does not update email on invalid data", %{conn: conn} do
@ -105,14 +105,14 @@ defmodule MemexWeb.UserSettingsControllerTest do
end
describe "GET /users/settings/confirm_email/:token" do
setup %{current_user: current_user} do
setup %{user: user} do
email = unique_user_email()
token =
extract_user_token(fn url ->
Accounts.deliver_update_email_instructions(
%{current_user | email: email},
current_user.email,
%{user | email: email},
user.email,
url
)
end)
@ -121,11 +121,11 @@ defmodule MemexWeb.UserSettingsControllerTest do
end
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))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
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)
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")
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"))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :error) =~
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
test "redirects if user is not logged in", %{token: token} do

View File

@ -16,9 +16,9 @@ defmodule MemexWeb.InviteLiveTest do
describe "Index" do
setup [:register_and_log_in_user]
setup %{current_user: current_user} do
{:ok, invite} = Invites.create_invite(current_user, @create_attrs)
%{invite: invite, current_user: current_user}
setup %{user: user} do
{:ok, invite} = Invites.create_invite(user, @create_attrs)
%{invite: invite, user: user}
end
test "lists all invites", %{conn: conn, invite: invite} do

View File

@ -50,10 +50,10 @@ defmodule MemexWeb.ConnCase do
test context.
"""
@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
current_user = user_fixture() |> confirm_user()
%{conn: log_in_user(conn, current_user), current_user: current_user}
user = user_fixture() |> confirm_user()
%{conn: log_in_user(conn, user), user: user}
end
@spec confirm_user(User.t()) :: User.t()