mockShopifyTransport
●cart · /shopify/testing·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
function mockShopifyTransport(opts: MockShopifyTransportOpts): ShopifyTransport;Parameters
| Name | Type | Description |
|---|---|---|
opts | MockShopifyTransportOpts |
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 === 2Related
MetadataOpen in GitHub ↗