feat: add order management admin with list and detail views
Admin UI at /admin/orders to view, filter, and inspect orders. Adds list_orders/1 and count_orders_by_status/0 to the Orders context, status filter tabs, clickable order table with streams, and a detail page showing items, totals, and shipping address. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
65
test/simpleshop_theme/orders_test.exs
Normal file
65
test/simpleshop_theme/orders_test.exs
Normal file
@@ -0,0 +1,65 @@
|
||||
defmodule SimpleshopTheme.OrdersTest do
|
||||
use SimpleshopTheme.DataCase, async: false
|
||||
|
||||
alias SimpleshopTheme.Orders
|
||||
|
||||
import SimpleshopTheme.OrdersFixtures
|
||||
|
||||
describe "list_orders/1" do
|
||||
test "returns all orders" do
|
||||
order1 = order_fixture()
|
||||
order2 = order_fixture()
|
||||
|
||||
orders = Orders.list_orders()
|
||||
order_ids = Enum.map(orders, & &1.id)
|
||||
|
||||
assert order1.id in order_ids
|
||||
assert order2.id in order_ids
|
||||
assert length(orders) == 2
|
||||
end
|
||||
|
||||
test "filters by payment status" do
|
||||
_pending = order_fixture()
|
||||
paid = order_fixture(payment_status: "paid")
|
||||
_failed = order_fixture(payment_status: "failed")
|
||||
|
||||
orders = Orders.list_orders(status: "paid")
|
||||
assert length(orders) == 1
|
||||
assert hd(orders).id == paid.id
|
||||
end
|
||||
|
||||
test "returns all when status is 'all'" do
|
||||
order_fixture()
|
||||
order_fixture(payment_status: "paid")
|
||||
|
||||
orders = Orders.list_orders(status: "all")
|
||||
assert length(orders) == 2
|
||||
end
|
||||
|
||||
test "preloads items" do
|
||||
order_fixture()
|
||||
|
||||
[order] = Orders.list_orders()
|
||||
assert Ecto.assoc_loaded?(order.items)
|
||||
assert length(order.items) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "count_orders_by_status/0" do
|
||||
test "returns empty map when no orders" do
|
||||
assert Orders.count_orders_by_status() == %{}
|
||||
end
|
||||
|
||||
test "counts orders by status" do
|
||||
order_fixture()
|
||||
order_fixture()
|
||||
order_fixture(payment_status: "paid")
|
||||
order_fixture(payment_status: "failed")
|
||||
|
||||
counts = Orders.count_orders_by_status()
|
||||
assert counts["pending"] == 2
|
||||
assert counts["paid"] == 1
|
||||
assert counts["failed"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user