use more verified routes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
shibao 2023-04-14 19:51:14 -04:00
parent c49140e7f5
commit 56e6eb3609
8 changed files with 36 additions and 30 deletions

View File

@ -25,7 +25,7 @@ defmodule MemexWeb.UserConfirmationController do
"if your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
)
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
# Do not log in the user after confirmation to avoid a
@ -35,7 +35,7 @@ defmodule MemexWeb.UserConfirmationController do
{:ok, %{email: email}} ->
conn
|> put_flash(:info, dgettext("prompts", "%{email} confirmed successfully.", email: email))
|> redirect(to: "/")
|> redirect(to: ~p"/")
:error ->
# If there is a current user and the account was already confirmed,
@ -44,7 +44,7 @@ defmodule MemexWeb.UserConfirmationController do
# a warning message.
case conn.assigns do
%{current_user: %{confirmed_at: confirmed_at}} when not is_nil(confirmed_at) ->
redirect(conn, to: "/")
redirect(conn, to: ~p"/")
%{} ->
conn
@ -52,7 +52,7 @@ defmodule MemexWeb.UserConfirmationController do
:error,
dgettext("errors", "user confirmation link is invalid or it has expired.")
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
end
end

View File

@ -26,7 +26,7 @@ defmodule MemexWeb.UserResetPasswordController do
"if your email is in our system, you will receive instructions to reset your password shortly."
)
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
def edit(conn, _params) do
@ -61,7 +61,7 @@ defmodule MemexWeb.UserResetPasswordController do
:error,
dgettext("errors", "reset password link is invalid or it has expired.")
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
|> halt()
end
end

View File

@ -24,7 +24,7 @@ defmodule MemexWeb.UserAuthTest do
conn = UserAuth.log_in_user(conn, current_user)
assert token = get_session(conn, :user_token)
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(token)}"
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
assert Accounts.get_user_by_session_token(token)
end
@ -64,7 +64,7 @@ defmodule MemexWeb.UserAuthTest do
refute get_session(conn, :user_token)
refute conn.cookies[@remember_me_cookie]
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
refute Accounts.get_user_by_session_token(user_token)
end
@ -86,7 +86,7 @@ defmodule MemexWeb.UserAuthTest do
conn = conn |> fetch_cookies() |> UserAuth.log_out_user()
refute get_session(conn, :user_token)
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
end
@ -129,7 +129,7 @@ defmodule MemexWeb.UserAuthTest do
|> UserAuth.redirect_if_user_is_authenticated([])
assert conn.halted
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
test "does not redirect if user is not authenticated", %{conn: conn} do

View File

@ -28,7 +28,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
@ -44,7 +44,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
@ -56,7 +56,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
user: %{email: "unknown@example.com"}
})
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
@ -73,7 +73,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
end)
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ "#{user.email} confirmed successfully"
@ -83,7 +83,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
# When not logged in
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
# When logged in
@ -92,13 +92,13 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|> log_in_user(user)
|> get(~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
refute conn.assigns.flash["error"]
end
test "does not confirm email with invalid token", %{conn: conn, user: user} do
conn = get(conn, ~p"/users/confirm/#{"oops"}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
refute Accounts.get_user!(user.id).confirmed_at

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.UserRegistrationControllerTest do
test "redirects if already logged in", %{conn: conn} do
conn = conn |> log_in_user(user_fixture()) |> get(~p"/users/register")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
end
@ -35,7 +35,7 @@ defmodule MemexWeb.UserRegistrationControllerTest do
"info" => "please check your email to verify your account"
}
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
end
test "render errors for invalid data", %{conn: conn} do

View File

@ -28,7 +28,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
@ -42,7 +42,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
user: %{email: "unknown@example.com"}
})
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
@ -68,7 +68,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, ~p"/users/reset_password/#{"oops"}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end
@ -115,7 +115,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, ~p"/users/reset_password/#{"oops"}")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end

View File

@ -20,7 +20,7 @@ defmodule MemexWeb.UserSessionControllerTest do
test "redirects if already logged in", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> get(~p"/users/log_in")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
end
@ -32,10 +32,10 @@ defmodule MemexWeb.UserSessionControllerTest do
})
assert get_session(conn, :user_token)
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
conn = get(conn, ~p"/")
response = html_response(conn, 200)
assert response =~ current_user.email
assert response =~ "are you sure you want to log out?"
@ -52,7 +52,7 @@ defmodule MemexWeb.UserSessionControllerTest do
})
assert conn.resp_cookies["_memex_web_user_remember_me"]
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
end
test "logs the user in with return to", %{conn: conn, current_user: current_user} do
@ -78,21 +78,21 @@ defmodule MemexWeb.UserSessionControllerTest do
response = html_response(conn, 200)
assert response =~ "log in"
assert response =~ "Invalid email or password"
assert response =~ "invalid email or password"
end
end
describe "DELETE /users/log_out" do
test "logs the user out", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> delete(~p"/users/log_out")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :user_token)
conn.assigns.flash["info"] =~ "logged out successfully"
end
test "succeeds even if the user is not logged in", %{conn: conn} do
conn = delete(conn, ~p"/users/log_out")
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :user_token)
conn.assigns.flash["info"] =~ "logged out successfully"
end

View File

@ -8,4 +8,10 @@ defmodule MemexWeb.HomeLiveTest do
assert disconnected_html =~ "memEx"
assert render(page_live) =~ "memEx"
end
test "displays version number", %{conn: conn} do
{:ok, home_live, disconnected_html} = live(conn, ~p"/")
assert disconnected_html =~ Mix.Project.config()[:version]
assert render(home_live) =~ Mix.Project.config()[:version]
end
end