refactor: fix review blockers
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2026-05-06 13:54:22 +02:00
parent 104d945dd1
commit cc1df449c6
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
9 changed files with 253 additions and 161 deletions

View file

@ -12,10 +12,9 @@ defmodule MvWeb.JoinLiveTest do
# async: false → shared sandbox; all processes (including LiveView) share the DB connection.
use MvWeb.ConnCase, async: false
import Phoenix.LiveViewTest
import Ecto.Query
alias Mv.Membership
alias Mv.Repo
alias Mv.Membership.JoinRequest
describe "GET /join" do
@tag role: :unauthenticated
@ -55,11 +54,12 @@ defmodule MvWeb.JoinLiveTest do
})
|> render_submit()
# Anti-enumeration delay is applied in LiveView via send_after (100300 ms); wait for success UI.
Process.sleep(400)
assert_eventually(fn -> count_join_requests() == count_before + 1 end)
assert_eventually(fn ->
view |> element("[data-testid='join-success-message']") |> has_element?()
end)
assert count_join_requests() == count_before + 1
assert view |> element("[data-testid='join-success-message']") |> has_element?()
assert render(view) =~ "saved your details"
assert render(view) =~ "click the link"
end
@ -298,10 +298,11 @@ defmodule MvWeb.JoinLiveTest do
"not_allowlisted" => "should-not-be-persisted"
})
Process.sleep(400)
assert_eventually(fn -> count_join_requests() == count_before + 1 end)
assert count_join_requests() == count_before + 1
assert view |> element("[data-testid='join-success-message']") |> has_element?()
assert_eventually(fn ->
view |> element("[data-testid='join-success-message']") |> has_element?()
end)
form_data = latest_join_request_form_data()
assert Map.get(form_data, boolean_field.id) == "on"
@ -328,16 +329,40 @@ defmodule MvWeb.JoinLiveTest do
end
defp count_join_requests do
Repo.one(from j in "join_requests", select: count(j.id)) || 0
case Ash.count(JoinRequest, domain: Membership, authorize?: false) do
{:ok, count} -> count
_ -> 0
end
end
defp latest_join_request_form_data do
Repo.one(
from j in "join_requests",
order_by: [desc: j.inserted_at],
limit: 1,
select: j.form_data
) || %{}
query =
JoinRequest
|> Ash.Query.sort(inserted_at: :desc)
|> Ash.Query.limit(1)
case Ash.read(query, domain: Membership, authorize?: false) do
{:ok, [request]} -> request.form_data || %{}
_ -> %{}
end
end
defp assert_eventually(fun, timeout_ms \\ 1500) when is_function(fun, 0) do
deadline = System.monotonic_time(:millisecond) + timeout_ms
do_assert_eventually(fun, deadline)
end
defp do_assert_eventually(fun, deadline) do
if fun.() do
true
else
if System.monotonic_time(:millisecond) < deadline do
Process.sleep(25)
do_assert_eventually(fun, deadline)
else
assert fun.()
end
end
end
defp reset_rate_limiter do