mockShopifyTransport

cart · /shopify·function

Builds an in-memory ShopifyTransport that responds with the same envelope shape the real Storefront API would produce. Lets cart-core's contract suite (and host integration tests) drive createShopifyCartAdapter without a real Shopify endpoint.

Signature

@nordcom/commerce-cart

Parameters

NameTypeDescription
optsMockShopifyTransportOpts

Returns

Stateful transport whose Map is scoped per call, so concurrent tests don't share state.

Example

import { consoleLogger } from '@nordcom/cart-core';
import { createShopifyCartAdapter } from '@nordcom/cart-shopify';
import { mockShopifyTransport } from '@nordcom/cart-shopify/testing';

const transport = mockShopifyTransport();
const adapter = createShopifyCartAdapter({ transport });

const ctx = {
    shop: {},
    locale: { language: 'en', country: 'US', currency: 'USD' },
    logger: consoleLogger,
};

const cart = await adapter.createCart(ctx, {
    lines: [{ variantId: 'gid://shopify/ProductVariant/1', quantity: 2 }],
});
// cart.totalQuantity === 2

ShopifyTransport createShopifyCartAdapter normalizeShopifyCart MockShopifyTransportOpts

Sourcetesting.ts:197Edit the JSDoc directly

On this page