From cbee15b70fb325047630a29eafe20f3b0431c406 Mon Sep 17 00:00:00 2001 From: shibao Date: Thu, 17 Nov 2022 22:32:27 -0500 Subject: [PATCH] change conn case user assign to user --- .../user_settings_controller_test.exs | 22 +++++++++---------- test/memex_web/live/invite_live_test.exs | 6 ++--- test/support/conn_case.ex | 6 ++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/memex_web/controllers/user_settings_controller_test.exs b/test/memex_web/controllers/user_settings_controller_test.exs index dfb0128..7617e50 100644 --- a/test/memex_web/controllers/user_settings_controller_test.exs +++ b/test/memex_web/controllers/user_settings_controller_test.exs @@ -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 diff --git a/test/memex_web/live/invite_live_test.exs b/test/memex_web/live/invite_live_test.exs index a73efb0..5dad085 100644 --- a/test/memex_web/live/invite_live_test.exs +++ b/test/memex_web/live/invite_live_test.exs @@ -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 diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 82b5c16..91e9608 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -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()