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

View File

@ -24,7 +24,7 @@ defmodule MemexWeb.UserAuthTest do
conn = UserAuth.log_in_user(conn, current_user) conn = UserAuth.log_in_user(conn, current_user)
assert token = get_session(conn, :user_token) assert token = get_session(conn, :user_token)
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(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) assert Accounts.get_user_by_session_token(token)
end end
@ -64,7 +64,7 @@ defmodule MemexWeb.UserAuthTest do
refute get_session(conn, :user_token) refute get_session(conn, :user_token)
refute conn.cookies[@remember_me_cookie] refute conn.cookies[@remember_me_cookie]
assert %{max_age: 0} = conn.resp_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) refute Accounts.get_user_by_session_token(user_token)
end end
@ -86,7 +86,7 @@ defmodule MemexWeb.UserAuthTest do
conn = conn |> fetch_cookies() |> UserAuth.log_out_user() conn = conn |> fetch_cookies() |> UserAuth.log_out_user()
refute get_session(conn, :user_token) refute get_session(conn, :user_token)
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie] assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
end end
end end
@ -129,7 +129,7 @@ defmodule MemexWeb.UserAuthTest do
|> UserAuth.redirect_if_user_is_authenticated([]) |> UserAuth.redirect_if_user_is_authenticated([])
assert conn.halted assert conn.halted
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
end end
test "does not redirect if user is not authenticated", %{conn: conn} do 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} user: %{email: user.email}
}) })
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ 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." "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} user: %{email: user.email}
}) })
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ 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." "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"} user: %{email: "unknown@example.com"}
}) })
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ 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." "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) end)
conn = get(conn, ~p"/users/confirm/#{token}") conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ "#{user.email} confirmed successfully" conn.assigns.flash["info"] =~ "#{user.email} confirmed successfully"
@ -83,7 +83,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
# When not logged in # When not logged in
conn = get(conn, ~p"/users/confirm/#{token}") 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" conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
# When logged in # When logged in
@ -92,13 +92,13 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|> log_in_user(user) |> log_in_user(user)
|> get(~p"/users/confirm/#{token}") |> get(~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
refute conn.assigns.flash["error"] refute conn.assigns.flash["error"]
end end
test "does not confirm email with invalid token", %{conn: conn, user: user} do test "does not confirm email with invalid token", %{conn: conn, user: user} do
conn = get(conn, ~p"/users/confirm/#{"oops"}") 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" conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
refute Accounts.get_user!(user.id).confirmed_at 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 test "redirects if already logged in", %{conn: conn} do
conn = conn |> log_in_user(user_fixture()) |> get(~p"/users/register") conn = conn |> log_in_user(user_fixture()) |> get(~p"/users/register")
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
end end
end end
@ -35,7 +35,7 @@ defmodule MemexWeb.UserRegistrationControllerTest do
"info" => "please check your email to verify your account" "info" => "please check your email to verify your account"
} }
assert redirected_to(conn) =~ "/" assert redirected_to(conn) =~ ~p"/"
end end
test "render errors for invalid data", %{conn: conn} do test "render errors for invalid data", %{conn: conn} do

View File

@ -28,7 +28,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
user: %{email: user.email} user: %{email: user.email}
}) })
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly." "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"} user: %{email: "unknown@example.com"}
}) })
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
conn.assigns.flash["info"] =~ conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly." "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 test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, ~p"/users/reset_password/#{"oops"}") 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" conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end end
end end
@ -115,7 +115,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
test "does not reset password with invalid token", %{conn: conn} do test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, ~p"/users/reset_password/#{"oops"}") 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" conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end end
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 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") conn = conn |> log_in_user(current_user) |> get(~p"/users/log_in")
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
end end
end end
@ -32,10 +32,10 @@ defmodule MemexWeb.UserSessionControllerTest do
}) })
assert get_session(conn, :user_token) 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 # Now do a logged in request and assert on the menu
conn = get(conn, "/") conn = get(conn, ~p"/")
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ current_user.email assert response =~ current_user.email
assert response =~ "are you sure you want to log out?" 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 conn.resp_cookies["_memex_web_user_remember_me"]
assert redirected_to(conn) =~ "/" assert redirected_to(conn) =~ ~p"/"
end end
test "logs the user in with return to", %{conn: conn, current_user: current_user} do 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) response = html_response(conn, 200)
assert response =~ "log in" assert response =~ "log in"
assert response =~ "Invalid email or password" assert response =~ "invalid email or password"
end end
end end
describe "DELETE /users/log_out" do describe "DELETE /users/log_out" do
test "logs the user out", %{conn: conn, current_user: current_user} 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") 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) refute get_session(conn, :user_token)
conn.assigns.flash["info"] =~ "logged out successfully" conn.assigns.flash["info"] =~ "logged out successfully"
end end
test "succeeds even if the user is not logged in", %{conn: conn} do test "succeeds even if the user is not logged in", %{conn: conn} do
conn = delete(conn, ~p"/users/log_out") conn = delete(conn, ~p"/users/log_out")
assert redirected_to(conn) == "/" assert redirected_to(conn) == ~p"/"
refute get_session(conn, :user_token) refute get_session(conn, :user_token)
conn.assigns.flash["info"] =~ "logged out successfully" conn.assigns.flash["info"] =~ "logged out successfully"
end end

View File

@ -8,4 +8,10 @@ defmodule MemexWeb.HomeLiveTest do
assert disconnected_html =~ "memEx" assert disconnected_html =~ "memEx"
assert render(page_live) =~ "memEx" assert render(page_live) =~ "memEx"
end 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 end