Some checks failed
deploy / deploy (push) Has been cancelled
- semantic HTML: step numbers inside h2, strong provider names, details for adapter configs, strong error messages, fieldset drawer toggle hidden - inline field errors via flash for no-JS controller fallback - single form POST button for test email (works with and without JS) - admin sidebar: remove brand/view-shop, move user email to footer nav - replace inline style with .admin-setup-step-spaced class - clean up unused CSS (.admin-brand, .admin-sidebar-header, etc.) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.2 KiB
Elixir
71 lines
2.2 KiB
Elixir
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",
|
|
brevo: %{api_key: "xkeysib-abc123def456"}
|
|
}
|
|
})
|
|
|
|
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 field errors on validation failure", %{conn: conn} do
|
|
conn =
|
|
post(conn, ~p"/admin/settings/email", %{
|
|
email: %{adapter: "brevo", brevo: %{api_key: ""}}
|
|
})
|
|
|
|
assert redirected_to(conn) =~ ~p"/admin/settings/email"
|
|
|
|
field_errors = Phoenix.Flash.get(conn.assigns.flash, :field_errors)
|
|
assert is_map(field_errors)
|
|
assert field_errors |> Map.values() |> Enum.any?(&String.contains?(&1, "required"))
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error_adapter) == "brevo"
|
|
end
|
|
end
|
|
|
|
describe "POST /admin/settings/email/test" do
|
|
test "sends test email and redirects", %{conn: conn} do
|
|
Settings.put_setting("email_adapter", "brevo")
|
|
Settings.put_secret("email_brevo_api_key", "xkeysib-test-abc")
|
|
|
|
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
|