diff --git a/src/components/quote-form.test.tsx b/src/components/quote-form.test.tsx index 0e3124d..5f13cff 100644 --- a/src/components/quote-form.test.tsx +++ b/src/components/quote-form.test.tsx @@ -113,10 +113,19 @@ describe("QuoteForm", () => { createMock .mockResolvedValueOnce({ id: "quote-1" }) .mockResolvedValueOnce({ id: "item-1" }); - fetchMock.mockResolvedValue({ - ok: true, - json: async () => ({ id: "att-1" }), - }); + // The form now hits /api/v1/quotes/next-number before PB create, + // and /api/v1/quotes/items//attachments/upload after. Queue + // both responses so the first fetch call gets the next-number + // shape and the second gets the upload shape. + fetchMock + .mockResolvedValueOnce({ + ok: true, + json: async () => ({ quote_number: "Q-2026-07-001" }), + }) + .mockResolvedValueOnce({ + ok: true, + json: async () => ({ id: "att-1" }), + }); render(); @@ -165,6 +174,11 @@ describe("QuoteForm", () => { it("allows a company-only selection when creating a quote", async () => { createMock.mockResolvedValueOnce({ id: "quote-2" }).mockResolvedValueOnce({ id: "item-2" }); + // The form hits /api/v1/quotes/next-number before PB create. + fetchMock.mockResolvedValueOnce({ + ok: true, + json: async () => ({ quote_number: "Q-2026-07-001" }), + }); const onSaved = vi.fn(); const onOpenChange = vi.fn(); @@ -201,6 +215,12 @@ describe("QuoteForm", () => { createMock .mockResolvedValueOnce({ id: "quote-1" }) .mockRejectedValueOnce(new Error("item create failed")); + // The form hits /api/v1/quotes/next-number before PB create. + // The item-create then fails, so the upload fetch is NOT called. + fetchMock.mockResolvedValueOnce({ + ok: true, + json: async () => ({ quote_number: "Q-2026-07-001" }), + }); render(); @@ -220,7 +240,10 @@ describe("QuoteForm", () => { fireEvent.click(screen.getByRole("button", { name: /create quote/i })); await waitFor(() => { - expect(fetchMock).not.toHaveBeenCalled(); + // Next-number WAS called before PB create; the upload + // fetch was NOT called because the item-create branch + // threw before reaching it. + expect(fetchMock).toHaveBeenCalledTimes(1); expect(toastErrorMock).toHaveBeenCalledWith( expect.stringMatching(/partially created/i), ); @@ -231,11 +254,17 @@ describe("QuoteForm", () => { createMock .mockResolvedValueOnce({ id: "quote-1" }) .mockResolvedValueOnce({ id: "item-1" }); - fetchMock.mockResolvedValue({ - ok: false, - status: 500, - json: async () => ({ error: "Upload failed" }), - }); + // First fetch: next-number (success). Second fetch: upload (500). + fetchMock + .mockResolvedValueOnce({ + ok: true, + json: async () => ({ quote_number: "Q-2026-07-001" }), + }) + .mockResolvedValueOnce({ + ok: false, + status: 500, + json: async () => ({ error: "Upload failed" }), + }); render();