Some checks failed
deploy / deploy (push) Has been cancelled
Both order tracking forms now have action="/contact/lookup" so they POST to a new OrderLookupController.lookup action when JS is off. The controller mirrors the LiveView handler: checks for paid orders, sends the verification email, and redirects with a flash message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
38 lines
1.2 KiB
Elixir
38 lines
1.2 KiB
Elixir
defmodule BerrypodWeb.OrderLookupControllerTest do
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
import Berrypod.AccountsFixtures
|
|
import Berrypod.OrdersFixtures
|
|
|
|
setup do
|
|
user_fixture()
|
|
{:ok, _} = Berrypod.Settings.set_site_live(true)
|
|
:ok
|
|
end
|
|
|
|
describe "POST /contact/lookup" do
|
|
test "sends lookup email and redirects when orders exist", %{conn: conn} do
|
|
order_fixture(%{customer_email: "buyer@test.com", payment_status: "paid"})
|
|
|
|
conn = post(conn, ~p"/contact/lookup", %{"email" => "buyer@test.com"})
|
|
|
|
assert redirected_to(conn) == "/contact"
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "sent a link"
|
|
end
|
|
|
|
test "shows error when no orders found", %{conn: conn} do
|
|
conn = post(conn, ~p"/contact/lookup", %{"email" => "nobody@test.com"})
|
|
|
|
assert redirected_to(conn) == "/contact"
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "No orders found"
|
|
end
|
|
|
|
test "shows error when email is missing", %{conn: conn} do
|
|
conn = post(conn, ~p"/contact/lookup", %{})
|
|
|
|
assert redirected_to(conn) == "/contact"
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "enter your email"
|
|
end
|
|
end
|
|
end
|