mitgliederverwaltung/test/mv_web/live/join_live_email_failure_test.exs
Simon c933144920
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/promote/production Build is failing
feat: unify page titles
2026-03-13 19:01:50 +01:00

57 lines
1.6 KiB
Elixir

defmodule MvWeb.JoinLiveEmailFailureTest do
@moduledoc """
When join confirmation email delivery fails, the user sees an error message
and no success copy. Uses FailingMailAdapter; async: false to avoid config races.
"""
use MvWeb.ConnCase, async: false
import Phoenix.LiveViewTest
alias Mv.Membership
@tag role: :unauthenticated
test "when confirmation email fails, user sees error flash and no success message", %{
conn: conn
} do
enable_join_form_for_test()
saved = Application.get_env(:mv, Mv.Mailer)
Application.put_env(
:mv,
Mv.Mailer,
Keyword.put(saved || [], :adapter, Mv.TestSupport.FailingMailAdapter)
)
on_exit(fn ->
Application.put_env(:mv, Mv.Mailer, saved)
end)
{:ok, view, _html} = live(conn, "/join")
view
|> form("#join-form", %{
"email" => "fail#{System.unique_integer([:positive])}@example.com",
"first_name" => "Jane",
"last_name" => "Doe",
"website" => ""
})
|> render_submit()
html = render(view)
# Error message is translated; accept English or German wording
assert html =~ "could not send" or html =~ "confirmation email" or
html =~ "konnte nicht" or html =~ "Bestätigungs-E-Mail"
refute view |> element("[data-testid='join-success-message']") |> has_element?()
end
defp enable_join_form_for_test do
{:ok, settings} = Membership.get_settings()
Membership.update_settings(settings, %{
join_form_enabled: true,
join_form_field_ids: ["email", "first_name", "last_name"],
join_form_field_required: %{"email" => true, "first_name" => false, "last_name" => false}
})
end
end