From 38fc1e6f9ba947151d5e76584ec84530c09e3f24 Mon Sep 17 00:00:00 2001 From: FanouZeng-TT <18280587072@163.com> Date: Wed, 12 Aug 2026 20:53:04 +0800 Subject: [PATCH] fix(rest/nodejs): include line items in shipped events --- rest/nodejs/src/api/checkout.ts | 5 +++- rest/nodejs/test/fulfillment.test.ts | 42 +++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/rest/nodejs/src/api/checkout.ts b/rest/nodejs/src/api/checkout.ts index c79950a..e7bd34d 100644 --- a/rest/nodejs/src/api/checkout.ts +++ b/rest/nodejs/src/api/checkout.ts @@ -1080,7 +1080,10 @@ export class CheckoutService { id: `evt_${uuidv4()}`, type: "shipped", occurred_at: new Date(), - line_items: [], + line_items: order.line_items.map((lineItem) => ({ + id: lineItem.id, + quantity: lineItem.quantity.total, + })), }); saveOrder(order.id, order); diff --git a/rest/nodejs/test/fulfillment.test.ts b/rest/nodejs/test/fulfillment.test.ts index 3fa0ad1..284af48 100644 --- a/rest/nodejs/test/fulfillment.test.ts +++ b/rest/nodejs/test/fulfillment.test.ts @@ -19,7 +19,12 @@ import { zValidator } from "@hono/zod-validator"; import { Hono } from "hono"; import { CheckoutService } from "../src/api/checkout"; -import { getProductsDb, getTransactionsDb, initDbs } from "../src/data/db"; +import { + getOrder, + getProductsDb, + getTransactionsDb, + initDbs, +} from "../src/data"; import { CheckoutCompleteRequestSchema, ExtendedCheckoutCreateRequestSchema, @@ -280,6 +285,41 @@ test("a checkout with fulfillment fully selected can be completed", async () => assert.ok(body.order?.id, "completion must assign an order id"); }); +test("shipping an order includes its line items in the fulfillment event", async () => { + const app = buildApp(); + const created = await createWithDestination(app); + const options = created.fulfillment!.methods![0].groups![0].options!; + + const selectRes = await selectOption(app, created, options[0].id); + assert.equal(selectRes.status, 200); + + const completeRes = await app.request( + `/checkout-sessions/${created.id}/complete`, + { + method: "POST", + headers: JSON_HEADERS, + body: JSON.stringify(SUCCESS_PAYMENT), + } + ); + assert.equal(completeRes.status, 200); + const completed = (await completeRes.json()) as Checkout; + assert.ok(completed.order?.id, "completion must assign an order id"); + + await new CheckoutService().shipOrder(completed.order.id); + + const order = getOrder(completed.order.id); + assert.ok(order, "completed order must be persisted"); + const event = order.fulfillment.events?.at(-1); + assert.equal(event?.type, "shipped"); + assert.deepEqual( + event?.line_items, + order.line_items.map((lineItem) => ({ + id: lineItem.id, + quantity: lineItem.quantity.total, + })) + ); +}); + test("empty fulfillment methods array blocks completion", async () => { const app = buildApp(); // Distinct from "no fulfillment at all": the request carries an explicit