Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion platforms/web/src/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";

import type { Checkout, CheckoutProtocolMessageMap, UcpErrorResponse } from "./checkout.types";
import "./checkout-web-component";
import { DEFAULT_POPUP_WIDTH, DEFAULT_POPUP_HEIGHT, EMBED_PROTOCOL_VERSION } from "./checkout";
import {
DEFAULT_POPUP_WIDTH,
DEFAULT_POPUP_HEIGHT,
EMBED_PROTOCOL_VERSION,
CK_VERSION,
} from "./checkout";
import type { ShopifyCheckout } from "./checkout";

const POPUP_TARGETS = ["popup"] as const;
Expand Down Expand Up @@ -826,6 +831,43 @@ describe("<shopify-checkout>", () => {
});
});

describe("ck_version parameter", () => {
it("appends ck_version to the opened URL", () => {
const checkout = renderCheckout({ target: "popup" });

const windowOpenSpy = vi.spyOn(window, "open").mockReturnValue(createMockWindow());

checkout.open();

const url = new URL(expectWindowOpenArgs(windowOpenSpy)[0] as string);
expect(url.searchParams.get("ck_version")).toBe(CK_VERSION);
});

it("uses the documented constant value", () => {
expect(CK_VERSION).toBe("4.0.0");
});

it("includes ck_version on the overlay link", () => {
const checkout = renderCheckout({ src: "https://shop.example.com/checkout" });
const link = checkout.shadowRoot!.querySelector<HTMLAnchorElement>("#overlay-link");
const url = new URL(link!.getAttribute("href") ?? "");
expect(url.searchParams.get("ck_version")).toBe(CK_VERSION);
});

it("preserves caller-provided ck_version rather than appending a duplicate", () => {
const checkout = renderCheckout({
src: "https://shop.example.com/checkout?ck_version=old",
});

const windowOpenSpy = vi.spyOn(window, "open").mockReturnValue(createMockWindow());

checkout.open();

const url = new URL(expectWindowOpenArgs(windowOpenSpy)[0] as string);
expect(url.searchParams.getAll("ck_version")).toEqual([CK_VERSION]);
});
});

describe("debug attribute", () => {
it("logs a console warning for dropped messages when the debug attribute is set", async () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
Expand Down
2 changes: 2 additions & 0 deletions platforms/web/src/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { STYLES } from "./checkout.styles";
export const DEFAULT_POPUP_WIDTH = 600;
export const DEFAULT_POPUP_HEIGHT = 600;
export const EMBED_PROTOCOL_VERSION = "2026-04-08";
export const CK_VERSION = "4.0.0";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider reading this from package.json in the future.

const EMBED_DELEGATIONS: readonly string[] = ["window.open"];

const SHADOW_TEMPLATE = createTemplate(html`
Expand Down Expand Up @@ -157,6 +158,7 @@ export class ShopifyCheckout
if (EMBED_DELEGATIONS.length > 0) {
url.searchParams.set("ec_delegate", EMBED_DELEGATIONS.join(","));
}
url.searchParams.set("ck_version", CK_VERSION);
return url;
}

Expand Down
Loading