From faaa47a4fe8217d874c5e864c16b20db31e5b391 Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Mon, 3 Aug 2026 10:55:10 +0200 Subject: [PATCH] test(buyer-tasks): lock wire shape of mail_failed group in po_draft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The route is a pass-through, but the smoke test guards against a future refactor silently dropping the new emailError field — the operator's retry affordance depends on it. Co-authored-by: Orca --- src/app/api/v1/buyer-tasks/route.test.ts | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/app/api/v1/buyer-tasks/route.test.ts b/src/app/api/v1/buyer-tasks/route.test.ts index 678d568..393a21e 100644 --- a/src/app/api/v1/buyer-tasks/route.test.ts +++ b/src/app/api/v1/buyer-tasks/route.test.ts @@ -46,6 +46,36 @@ describe("GET /api/v1/buyer-tasks", () => { expect(body.groups[0].supplierName).toBe("Steel Co"); }); + it("returns mail_failed groups when tab=po_draft (operator can retry from buyer-tasks)", async () => { + vi.mocked(listBuyerTasks).mockResolvedValue([ + { + groupId: "order-1::sup-1", + orderId: "order-1", + orderNumber: "ORD-001", + supplierId: "sup-1", + supplierName: "Steel Co", + customerName: "J. Smith", + companyName: "Acme", + items: [], + itemCount: 1, + totalCost: 50, + purchaseOrderId: "po-1", + poStatus: "mail_failed", + poNumber: "PO-26080301", + supplierEmail: "orders@steelco.example", + emailError: "[webhook] Webhook returned HTTP 502", + step: "po_draft", + }, + ]); + + const res = await GET(makeRequest("po_draft") as never); + expect(res.status).toBe(200); + const body = await res.json(); + expect(body.groups).toHaveLength(1); + expect(body.groups[0].poStatus).toBe("mail_failed"); + expect(body.groups[0].emailError).toMatch(/webhook/i); + }); + it("returns 400 on invalid tab", async () => { const res = await GET(makeRequest("invalid") as never); expect(res.status).toBe(400);