fixed 11 out or 34 conn shadowing cases

11 are multi-line, script does not do that
This commit is contained in:
2026-05-05 21:26:00 +01:00
parent 73f6ca5049
commit a89d09e432
5 changed files with 180 additions and 185 deletions
@@ -3,23 +3,20 @@ defmodule FirehoseWeb.BlogControllerTest do
describe "GET /blog/:blog_id (index) - date filtering" do
test "does not show future-dated posts", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering")
html = html_response(conn, 200)
html = conn |> get(~p"/blog/engineering") |> html_response(200)
refute html =~ "Future Test Post"
end
end
describe "GET /blog/:blog_id/:slug (show) - date filtering" do
test "still shows a future-dated post by slug", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering/future-test-post")
assert html_response(conn, 200) =~ "Future Test Post"
assert conn |> get(~p"/blog/engineering/future-test-post") |> html_response(200) =~ "Future Test Post"
end
end
describe "GET /blog/:blog_id/tag/:tag - date filtering" do
test "excludes future-dated posts from tag page", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering/tag/test")
html = html_response(conn, 200)
html = conn |> get(~p"/blog/engineering/tag/test") |> html_response(200)
refute html =~ "Future Test Post"
end
end
@@ -28,24 +25,22 @@ defmodule FirehoseWeb.BlogControllerTest do
setup :register_and_log_in_user
test "authenticated user sees draft banner on draft post", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering/hello-world")
response = conn |> get(~p"/blog/engineering/hello-world")
assert html_response(conn, 200) =~ "Draft"
assert conn.resp_body =~ "not published"
assert html_response(response, 200) =~ "Draft"
assert response.resp_body =~ "not published"
end
test "authenticated user sees scheduled banner on future post", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering/future-test-post")
response = conn |> get(~p"/blog/engineering/future-test-post") |> html_response(200)
response = html_response(conn, 200)
assert response =~ "scheduled for"
assert response =~ "January 01, 2099"
end
test "authenticated user sees no banner on live post", %{conn: conn} do
conn = get(conn, ~p"/blog/engineering/why-firehose")
response = conn |> get(~p"/blog/engineering/why-firehose") |> html_response(200)
response = html_response(conn, 200)
refute response =~ "Draft"
refute response =~ "scheduled for"
end
@@ -5,8 +5,7 @@ defmodule FirehoseWeb.UserRegistrationControllerTest do
describe "GET /users/register" do
test "renders registration page", %{conn: conn} do
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
response = conn |> get(~p"/users/register") |> html_response(200)
assert response =~ "Register"
assert response =~ ~p"/users/log-in"
assert response =~ ~p"/users/register"
@@ -58,23 +57,21 @@ defmodule FirehoseWeb.UserRegistrationControllerTest do
Application.put_env(:firehose, :allowed_registration_email, "allowed@example.com")
on_exit(fn -> Application.delete_env(:firehose, :allowed_registration_email) end)
conn = post(conn, ~p"/users/register", %{"user" => %{"email" => "allowed@example.com"}})
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "email was sent"
response = conn |> post(~p"/users/register", %{"user" => %{"email" => "allowed@example.com"}})
assert Phoenix.Flash.get(response.assigns.flash, :info) =~ "email was sent"
end
test "fails with invite-only message when email doesn't match", %{conn: conn} do
Application.put_env(:firehose, :allowed_registration_email, "allowed@example.com")
on_exit(fn -> Application.delete_env(:firehose, :allowed_registration_email) end)
conn = post(conn, ~p"/users/register", %{"user" => %{"email" => "other@example.com"}})
assert html_response(conn, 200) =~ "registration is invite only"
assert conn |> post(~p"/users/register", %{"user" => %{"email" => "other@example.com"}}) |> html_response(200) =~ "registration is invite only"
end
test "fails with invite-only message when env var is unset", %{conn: conn} do
Application.delete_env(:firehose, :allowed_registration_email)
conn = post(conn, ~p"/users/register", %{"user" => %{"email" => "anyone@example.com"}})
assert html_response(conn, 200) =~ "registration is invite only"
assert conn |> post(~p"/users/register", %{"user" => %{"email" => "anyone@example.com"}}) |> html_response(200) =~ "registration is invite only"
end
end
end
@@ -10,8 +10,7 @@ defmodule FirehoseWeb.UserSessionControllerTest do
describe "GET /users/log-in" do
test "renders login page", %{conn: conn} do
conn = get(conn, ~p"/users/log-in")
response = html_response(conn, 200)
response = conn |> get(~p"/users/log-in") |> html_response(200)
assert response =~ "Log in"
assert response =~ ~p"/users/register"
assert response =~ "Log in with email"
@@ -33,8 +32,7 @@ defmodule FirehoseWeb.UserSessionControllerTest do
end
test "renders login page (email + password)", %{conn: conn} do
conn = get(conn, ~p"/users/log-in?mode=password")
response = html_response(conn, 200)
response = conn |> get(~p"/users/log-in?mode=password") |> html_response(200)
assert response =~ "Log in"
assert response =~ ~p"/users/register"
assert response =~ "Log in with email"
@@ -48,8 +46,7 @@ defmodule FirehoseWeb.UserSessionControllerTest do
Accounts.deliver_login_instructions(user, url)
end)
conn = get(conn, ~p"/users/log-in/#{token}")
assert html_response(conn, 200) =~ "Confirm and stay logged in"
assert conn |> get(~p"/users/log-in/#{token}") |> html_response(200) =~ "Confirm and stay logged in"
end
test "renders login page for confirmed user", %{conn: conn, user: user} do
@@ -58,17 +55,16 @@ defmodule FirehoseWeb.UserSessionControllerTest do
Accounts.deliver_login_instructions(user, url)
end)
conn = get(conn, ~p"/users/log-in/#{token}")
html = html_response(conn, 200)
html = conn |> get(~p"/users/log-in/#{token}") |> html_response(200)
refute html =~ "Confirm my account"
assert html =~ "Keep me logged in on this device"
end
test "raises error for invalid token", %{conn: conn} do
conn = get(conn, ~p"/users/log-in/invalid-token")
assert redirected_to(conn) == ~p"/users/log-in"
response = conn |> get(~p"/users/log-in/invalid-token")
assert redirected_to(response) == ~p"/users/log-in"
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
assert Phoenix.Flash.get(response.assigns.flash, :error) ==
"Magic link is invalid or it has expired."
end
end
@@ -190,10 +186,10 @@ defmodule FirehoseWeb.UserSessionControllerTest do
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) == ~p"/"
refute get_session(conn, :user_token)
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
response = conn |> delete(~p"/users/log-out")
assert redirected_to(response) == ~p"/"
refute get_session(response, :user_token)
assert Phoenix.Flash.get(response.assigns.flash, :info) =~ "Logged out successfully"
end
end
end
@@ -8,23 +8,22 @@ defmodule FirehoseWeb.UserSettingsControllerTest do
describe "GET /users/settings" do
test "renders settings page", %{conn: conn} do
conn = get(conn, ~p"/users/settings")
response = html_response(conn, 200)
response = conn |> get(~p"/users/settings") |> html_response(200)
assert response =~ "Settings"
end
test "redirects if user is not logged in" do
conn = build_conn()
conn = get(conn, ~p"/users/settings")
assert redirected_to(conn) == ~p"/users/log-in"
response = conn |> get(~p"/users/settings")
assert redirected_to(response) == ~p"/users/log-in"
end
@tag token_authenticated_at: DateTime.add(DateTime.utc_now(:second), -11, :minute)
test "redirects if user is not in sudo mode", %{conn: conn} do
conn = get(conn, ~p"/users/settings")
assert redirected_to(conn) == ~p"/users/log-in"
response = conn |> get(~p"/users/settings")
assert redirected_to(response) == ~p"/users/log-in"
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
assert Phoenix.Flash.get(response.assigns.flash, :error) ==
"You must re-authenticate to access this page."
end
end
@@ -112,28 +111,28 @@ defmodule FirehoseWeb.UserSettingsControllerTest do
end
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
conn = get(conn, ~p"/users/settings/confirm-email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
response = conn |> get(~p"/users/settings/confirm-email/#{token}")
assert redirected_to(response) == ~p"/users/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
assert Phoenix.Flash.get(response.assigns.flash, :info) =~
"Email changed successfully"
refute Accounts.get_user_by_email(user.email)
assert Accounts.get_user_by_email(email)
conn = get(conn, ~p"/users/settings/confirm-email/#{token}")
response = conn |> get(~p"/users/settings/confirm-email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
assert redirected_to(response) == ~p"/users/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
assert Phoenix.Flash.get(response.assigns.flash, :error) =~
"Email change link is invalid or it has expired"
end
test "does not update email with invalid token", %{conn: conn, user: user} do
conn = get(conn, ~p"/users/settings/confirm-email/oops")
assert redirected_to(conn) == ~p"/users/settings"
response = conn |> get(~p"/users/settings/confirm-email/oops")
assert redirected_to(response) == ~p"/users/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
assert Phoenix.Flash.get(response.assigns.flash, :error) =~
"Email change link is invalid or it has expired"
assert Accounts.get_user_by_email(user.email)
@@ -141,8 +140,8 @@ defmodule FirehoseWeb.UserSettingsControllerTest do
test "redirects if user is not logged in", %{token: token} do
conn = build_conn()
conn = get(conn, ~p"/users/settings/confirm-email/#{token}")
assert redirected_to(conn) == ~p"/users/log-in"
response = conn |> get(~p"/users/settings/confirm-email/#{token}")
assert redirected_to(response) == ~p"/users/log-in"
end
end
end