All checks were successful
deploy / deploy (push) Successful in 1m17s
Magic link flow on contact page: customer enters email, gets a time-limited signed link, clicks through to /orders showing all their paid orders and full detail pages with thumbnails and product links. - OrderLookupController generates/verifies Phoenix.Token signed links - Contact LiveView handles lookup_orders + reset_tracking events - Orders and OrderDetail LiveViews gated by session email - Order detail shows thumbnails, links to products still available - .themed-button gets base padding/font-weight so all usages are consistent - order-summary-card sticky scoped to .cart-grid (was leaking to orders list) - 27 new tests (1095 total) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
98 lines
3.0 KiB
Elixir
98 lines
3.0 KiB
Elixir
defmodule BerrypodWeb.Shop.ContactTest do
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Swoosh.TestAssertions
|
|
import Berrypod.AccountsFixtures
|
|
import Berrypod.OrdersFixtures
|
|
|
|
setup do
|
|
user_fixture()
|
|
{:ok, _} = Berrypod.Settings.set_site_live(true)
|
|
# drain the confirmation email user_fixture sends so it doesn't leak into assertions
|
|
receive do
|
|
{:email, _} -> :ok
|
|
after
|
|
0 -> :ok
|
|
end
|
|
|
|
:ok
|
|
end
|
|
|
|
describe "contact page" do
|
|
test "renders the contact page", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/contact")
|
|
|
|
assert html =~ "Get in touch"
|
|
assert html =~ "Track your order"
|
|
end
|
|
|
|
test "shows order lookup form by default", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/contact")
|
|
|
|
assert html =~ "Enter the email address you used at checkout"
|
|
assert html =~ "Send link"
|
|
end
|
|
end
|
|
|
|
describe "order lookup" do
|
|
test "sends magic link when orders exist for email", %{conn: conn} do
|
|
order_fixture(%{customer_email: "buyer@example.com", payment_status: "paid"})
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/contact")
|
|
|
|
html = render_submit(view, "lookup_orders", %{"email" => "buyer@example.com"})
|
|
|
|
assert html =~ "Check your inbox"
|
|
assert html =~ "sent a link to your email address"
|
|
assert_email_sent(to: "buyer@example.com", subject: "Your order lookup link")
|
|
end
|
|
|
|
test "shows not-found state for unknown email", %{conn: conn} do
|
|
{:ok, view, _html} = live(conn, ~p"/contact")
|
|
|
|
html = render_submit(view, "lookup_orders", %{"email" => "nobody@example.com"})
|
|
|
|
assert html =~ "No orders found for that address"
|
|
assert html =~ "Try again"
|
|
assert_no_email_sent()
|
|
end
|
|
|
|
test "is case-insensitive for email lookup", %{conn: conn} do
|
|
order_fixture(%{customer_email: "Buyer@Example.com", payment_status: "paid"})
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/contact")
|
|
|
|
html = render_submit(view, "lookup_orders", %{"email" => "buyer@example.com"})
|
|
|
|
assert html =~ "Check your inbox"
|
|
# link is sent to the typed address, not the stored one
|
|
assert_email_sent(to: "buyer@example.com")
|
|
end
|
|
|
|
test "ignores pending/failed orders", %{conn: conn} do
|
|
order_fixture(%{customer_email: "buyer@example.com"})
|
|
order_fixture(%{customer_email: "buyer@example.com", payment_status: "failed"})
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/contact")
|
|
|
|
html = render_submit(view, "lookup_orders", %{"email" => "buyer@example.com"})
|
|
|
|
assert html =~ "No orders found for that address"
|
|
assert_no_email_sent()
|
|
end
|
|
|
|
test "reset button returns to idle form", %{conn: conn} do
|
|
order_fixture(%{customer_email: "buyer@example.com", payment_status: "paid"})
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/contact")
|
|
render_submit(view, "lookup_orders", %{"email" => "buyer@example.com"})
|
|
|
|
html = render_click(view, "reset_tracking")
|
|
|
|
assert html =~ "Enter the email address you used at checkout"
|
|
assert html =~ "Send link"
|
|
end
|
|
end
|
|
end
|