fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
defmodule BerrypodWeb.EmailSettingsControllerTest do
|
|
|
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
|
|
|
|
|
|
import Berrypod.AccountsFixtures
|
|
|
|
|
|
|
|
|
|
alias Berrypod.Settings
|
|
|
|
|
|
|
|
|
|
setup do
|
|
|
|
|
original = Application.get_env(:berrypod, Berrypod.Mailer)
|
|
|
|
|
Application.put_env(:berrypod, Berrypod.Mailer, adapter: Swoosh.Adapters.Test)
|
|
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
|
Application.put_env(:berrypod, Berrypod.Mailer, original)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
user = user_fixture()
|
|
|
|
|
conn = build_conn() |> log_in_user(user)
|
|
|
|
|
%{conn: conn, user: user}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "POST /admin/settings/email" do
|
|
|
|
|
test "saves adapter config and redirects", %{conn: conn} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, ~p"/admin/settings/email", %{
|
|
|
|
|
email: %{
|
|
|
|
|
adapter: "brevo",
|
2026-03-04 23:10:37 +00:00
|
|
|
brevo: %{api_key: "xkeysib-abc123def456"}
|
fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn) == ~p"/admin/settings/email"
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Settings saved"
|
|
|
|
|
assert Settings.get_setting("email_adapter") == "brevo"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "redirects with error on validation failure", %{conn: conn} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, ~p"/admin/settings/email", %{
|
2026-03-04 23:10:37 +00:00
|
|
|
email: %{adapter: "brevo", brevo: %{api_key: ""}}
|
fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn) =~ ~p"/admin/settings/email"
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "required"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "POST /admin/settings/email/test" do
|
|
|
|
|
test "sends test email and redirects", %{conn: conn} do
|
2026-03-04 23:10:37 +00:00
|
|
|
Settings.put_setting("email_adapter", "brevo")
|
|
|
|
|
Settings.put_secret("email_brevo_api_key", "xkeysib-test-abc")
|
fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
|
|
|
|
|
conn = post(conn, ~p"/admin/settings/email/test")
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn) == ~p"/admin/settings/email"
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Test email sent"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "unauthenticated" do
|
|
|
|
|
test "redirects to login", %{conn: _conn} do
|
|
|
|
|
conn = build_conn()
|
|
|
|
|
conn = post(conn, ~p"/admin/settings/email", %{email: %{adapter: "brevo"}})
|
|
|
|
|
assert redirected_to(conn) =~ ~p"/users/log-in"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|