fix: join confirmation mail configuration
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2026-03-13 09:34:56 +01:00
parent a7481f6ab1
commit 40a4461d23
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
12 changed files with 167 additions and 28 deletions

View file

@ -0,0 +1,33 @@
defmodule Mv.Membership.JoinRequestSubmitEmailFailureTest do
@moduledoc """
Tests that when join confirmation email delivery fails, the domain returns
{:error, :email_delivery_failed} (and the LiveView shows an error). Uses
FailingMailAdapter to simulate delivery failure; async: false to avoid config races.
"""
use Mv.DataCase, async: false
alias Mv.Membership
@valid_submit_attrs %{
email: "fail#{System.unique_integer([:positive])}@example.com"
}
test "submit_join_request returns {:error, :email_delivery_failed} when mail delivery fails" do
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)
token = "fail-token-#{System.unique_integer([:positive])}"
attrs = Map.put(@valid_submit_attrs, :confirmation_token, token)
assert {:error, :email_delivery_failed} = Membership.submit_join_request(attrs, actor: nil)
end
end

View file

@ -0,0 +1,54 @@
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)
assert html =~ "could not send" or html =~ "confirmation email"
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

View file

@ -0,0 +1,10 @@
defmodule Mv.TestSupport.FailingMailAdapter do
@moduledoc """
Swoosh adapter that always returns delivery failure. Used in tests to assert
that join confirmation email failure is handled (error shown to user, no success UI).
"""
use Swoosh.Adapter
@impl true
def deliver(_email, _config), do: {:error, :forced}
end