berrypod/test/berrypod_web/controllers/contact_controller_test.exs
jamey ca01f43d70
All checks were successful
deploy / deploy (push) Successful in 1m21s
add no-JS contact form and noscript banner
Wire up the contact form with action/method/name attrs so it works
without JavaScript. Add ContactNotifier, ContactController, and a
noscript info banner in the shop root layout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 18:57:51 +00:00

49 lines
1.5 KiB
Elixir

defmodule BerrypodWeb.ContactControllerTest do
use BerrypodWeb.ConnCase, async: false
import Berrypod.AccountsFixtures
import Swoosh.TestAssertions
setup do
user_fixture()
{:ok, _} = Berrypod.Settings.set_site_live(true)
# Clear confirmation email from user_fixture
Swoosh.TestAssertions.assert_email_sent()
:ok
end
describe "POST /contact/send" do
test "sends email and redirects with success flash", %{conn: conn} do
conn =
post(conn, ~p"/contact/send", %{
"name" => "Jo Bloggs",
"email" => "jo@example.com",
"subject" => "Question",
"message" => "Do you ship internationally?"
})
assert redirected_to(conn) == "/contact"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Message sent"
assert_email_sent(fn email ->
assert email.subject =~ "Question"
assert email.text_body =~ "Do you ship internationally?"
end)
end
test "redirects with error flash when required fields missing", %{conn: conn} do
conn = post(conn, ~p"/contact/send", %{"name" => "", "email" => "", "message" => ""})
assert redirected_to(conn) == "/contact"
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "required fields"
end
test "redirects with error flash when params empty", %{conn: conn} do
conn = post(conn, ~p"/contact/send", %{})
assert redirected_to(conn) == "/contact"
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "required fields"
end
end
end