diff --git a/platforms/web/src/checkout.test.ts b/platforms/web/src/checkout.test.ts index 0fbbfa23..71d5f402 100644 --- a/platforms/web/src/checkout.test.ts +++ b/platforms/web/src/checkout.test.ts @@ -1204,10 +1204,10 @@ describe("", () => { await wait; const event = spy.mock.calls[0]![0] as CustomEvent; - expect(event.detail).toEqual({ checkout: decodeCheckout(payload) }); + expect(event.detail).toStrictEqual({ checkout: decodeCheckout(payload) }); }); - it("ec.complete carries {checkout, order} with order derived from checkout", async () => { + it("ec.complete carries {checkout} with order nested in checkout", async () => { const { checkout, mockCheckoutWindow } = openPopupCheckout(); const spy = vi.fn(); const wait = waitForEvent(checkout, "ec.complete", spy); @@ -1224,11 +1224,11 @@ describe("", () => { const event = spy.mock.calls[0]![0] as CustomEvent; const decoded = decodeCheckout(payload); - expect(event.detail).toEqual({ checkout: decoded, order: decoded.order }); - expect(event.detail.order).toEqual(event.detail.checkout.order); + expect(event.detail).toStrictEqual({ checkout: decoded }); + expect(event.detail.checkout.order).toEqual(decoded.order); }); - it("ec.complete leaves order undefined when the checkout has no order", async () => { + it("ec.complete keeps an absent order nested in checkout", async () => { const { checkout, mockCheckoutWindow } = openPopupCheckout(); const spy = vi.fn(); const wait = waitForEvent(checkout, "ec.complete", spy); @@ -1240,7 +1240,9 @@ describe("", () => { await wait; const event = spy.mock.calls[0]![0] as CustomEvent; - expect(event.detail.order).toBeUndefined(); + const decoded = decodeCheckout(payload); + expect(event.detail).toStrictEqual({ checkout: decoded }); + expect(event.detail.checkout.order).toBeUndefined(); }); it("ec.error carries {error}", async () => { @@ -1255,10 +1257,10 @@ describe("", () => { await wait; const event = spy.mock.calls[0]![0] as CustomEvent; - expect(event.detail).toEqual({ error: decodeError(errorParams) }); + expect(event.detail).toStrictEqual({ error: decodeError(errorParams) }); }); - it("ec.line_items.change carries {lineItems, checkout}", async () => { + it("ec.line_items.change carries {checkout} with lineItems nested in checkout", async () => { const { checkout, mockCheckoutWindow } = openPopupCheckout(); const spy = vi.fn(); const wait = waitForEvent(checkout, "ec.line_items.change", spy); @@ -1271,11 +1273,11 @@ describe("", () => { const event = spy.mock.calls[0]![0] as CustomEvent; const decoded = decodeCheckout(payload); - expect(event.detail.lineItems).toEqual(decoded.lineItems); - expect(event.detail.checkout).toEqual(decoded); + expect(event.detail).toStrictEqual({ checkout: decoded }); + expect(event.detail.checkout.lineItems).toEqual(decoded.lineItems); }); - it("ec.totals.change carries {totals, checkout}", async () => { + it("ec.totals.change carries {checkout} with totals nested in checkout", async () => { const { checkout, mockCheckoutWindow } = openPopupCheckout(); const spy = vi.fn(); const wait = waitForEvent(checkout, "ec.totals.change", spy); @@ -1288,11 +1290,11 @@ describe("", () => { const event = spy.mock.calls[0]![0] as CustomEvent; const decoded = decodeCheckout(payload); - expect(event.detail.totals).toEqual(decoded.totals); - expect(event.detail.checkout).toEqual(decoded); + expect(event.detail).toStrictEqual({ checkout: decoded }); + expect(event.detail.checkout.totals).toEqual(decoded.totals); }); - it("ec.messages.change carries {messages, checkout}", async () => { + it("ec.messages.change carries {checkout} with messages nested in checkout", async () => { const { checkout, mockCheckoutWindow } = openPopupCheckout(); const spy = vi.fn(); const wait = waitForEvent(checkout, "ec.messages.change", spy); @@ -1305,8 +1307,8 @@ describe("", () => { const event = spy.mock.calls[0]![0] as CustomEvent; const decoded = decodeCheckout(payload); - expect(event.detail.messages).toEqual(decoded.messages ?? []); - expect(event.detail.checkout).toEqual(decoded); + expect(event.detail).toStrictEqual({ checkout: decoded }); + expect(event.detail.checkout.messages).toEqual(decoded.messages); }); it("ec.close carries no detail", () => { diff --git a/platforms/web/src/checkout.ts b/platforms/web/src/checkout.ts index a6b2fb9e..dc7d106a 100644 --- a/platforms/web/src/checkout.ts +++ b/platforms/web/src/checkout.ts @@ -17,10 +17,7 @@ import type { CheckoutTarget, TypedEventListener, Checkout, - LineItem, - Message, CheckoutAppearance, - CheckoutTotal, ErrorResponse, } from "./checkout.types"; @@ -232,7 +229,7 @@ export class ShopifyCheckout * @returns The current Checkout, or undefined before the first notification. * @example * checkout.addEventListener('ec.start', (event) => { - * const {line_items, totals, buyer} = event.detail.checkout; + * const {lineItems, totals, buyer} = event.detail.checkout; * }); */ get checkout(): Checkout | undefined { @@ -587,7 +584,7 @@ export class ShopifyCheckout }) .on(Event.complete, (checkout) => { this.#checkout = checkout; - this.dispatchEvent(new ShopifyCheckoutCompleteEvent({ checkout, order: checkout.order })); + this.dispatchEvent(new ShopifyCheckoutCompleteEvent({ checkout })); }) .on(Event.error, (error) => { this.#error = error; @@ -603,30 +600,15 @@ export class ShopifyCheckout }) .on(Event.lineItemsChange, (checkout) => { this.#checkout = checkout; - this.dispatchEvent( - new ShopifyCheckoutLineItemsChangeEvent({ - checkout, - lineItems: checkout.lineItems, - }), - ); + this.dispatchEvent(new ShopifyCheckoutLineItemsChangeEvent({ checkout })); }) .on(Event.totalsChange, (checkout) => { this.#checkout = checkout; - this.dispatchEvent( - new ShopifyCheckoutTotalsChangeEvent({ - checkout, - totals: checkout.totals, - }), - ); + this.dispatchEvent(new ShopifyCheckoutTotalsChangeEvent({ checkout })); }) .on(Event.messagesChange, (checkout) => { this.#checkout = checkout; - this.dispatchEvent( - new ShopifyCheckoutMessagesChangeEvent({ - checkout, - messages: checkout.messages ?? [], - }), - ); + this.dispatchEvent(new ShopifyCheckoutMessagesChangeEvent({ checkout })); }) .on(Event.windowOpen, (request) => this.#handleWindowOpen(request)); } @@ -801,7 +783,6 @@ export interface ShopifyCheckoutStartEventDetail { export interface ShopifyCheckoutCompleteEventDetail { /** Final checkout snapshot from the ECP `ec.complete` notification. */ checkout: Checkout; - order?: Checkout["order"]; } export interface ShopifyCheckoutErrorEventDetail { @@ -810,23 +791,17 @@ export interface ShopifyCheckoutErrorEventDetail { } export interface ShopifyCheckoutLineItemsChangeEventDetail { - /** Updated cart line items. */ - lineItems: readonly LineItem[]; - /** Full checkout snapshot for handlers that want broader context. */ + /** Checkout snapshot with updated cart line items. */ checkout: Checkout; } export interface ShopifyCheckoutTotalsChangeEventDetail { - /** Updated totals. */ - totals: readonly CheckoutTotal[]; - /** Full checkout snapshot for handlers that want broader context. */ + /** Checkout snapshot with updated totals. */ checkout: Checkout; } export interface ShopifyCheckoutMessagesChangeEventDetail { - /** Updated checkout-level messages (warnings, errors, info). */ - messages: readonly Message[]; - /** Full checkout snapshot for handlers that want broader context. */ + /** Checkout snapshot with updated warnings, errors, and informational messages. */ checkout: Checkout; }