@eldrajs/theme-cli 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cli.js +2 -3
  2. package/dist/index.d.ts +0 -12
  3. package/dist/index.js +1 -1
  4. package/dist/{validate-DprFpjV7.js → validate-FjQ-5_ne.js} +9 -18
  5. package/package.json +3 -3
  6. package/template/.eldra/previews.json +35 -35
  7. package/template/app/plugins/chunk-reload.client.ts +29 -0
  8. package/template/app/plugins/eldra-storefront.ts +5 -0
  9. package/template/app/storefront/gateway.ts +34 -14
  10. package/template/app/storefront/sharedRead.ts +34 -0
  11. package/template/app/storefront/structuredData.ts +19 -2
  12. package/template/app/storefront/types.ts +0 -5
  13. package/template/app/utils/chunkReload.ts +11 -0
  14. package/template/app/utils/seoInput.ts +0 -1
  15. package/template/blocks/article-list/preview.png +0 -0
  16. package/template/blocks/breadcrumbs/preview.png +0 -0
  17. package/template/blocks/cart/preview.png +0 -0
  18. package/template/blocks/collection-grid/Block.vue +146 -94
  19. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  20. package/template/blocks/collection-grid/preview.png +0 -0
  21. package/template/blocks/collection-header/preview.png +0 -0
  22. package/template/blocks/navigation/Block.vue +125 -541
  23. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  24. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  25. package/template/blocks/product-detail/preview.png +0 -0
  26. package/template/blocks/search/preview.png +0 -0
  27. package/template/blocks/team/preview.png +0 -0
  28. package/template/blocks/video-embed/preview.png +0 -0
  29. package/template/package.json +1 -1
  30. package/template/test/chunkReload.spec.ts +20 -0
  31. package/template/test/imageFraming.browser.spec.ts +125 -0
  32. package/template/test/pages/article.spec.ts +1 -1
  33. package/template/test/pages/collection.spec.ts +1 -1
  34. package/template/test/pages/home.spec.ts +1 -1
  35. package/template/test/pages/product.spec.ts +1 -1
  36. package/template/test/prerenderRefresh.browser.spec.ts +58 -13
  37. package/template/test/seoInput.spec.ts +5 -4
  38. package/template/test/storefront/gateway.spec.ts +6 -0
  39. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  40. package/template/test/storefront/sharedRead.spec.ts +43 -0
  41. package/template/test/storefront/structuredData.spec.ts +34 -6
  42. package/template/test/structuredData.generate.spec.ts +1 -1
  43. package/template/test/support/mockGateway.ts +8 -3
  44. package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
@@ -84,7 +84,7 @@ describe('home page (pages/home.page.json)', () => {
84
84
  expect(announcement.textContent).toContain('Free shipping on orders over $80');
85
85
 
86
86
  expect(header.tagName).toBe('HEADER');
87
- expect(header.querySelector('nav')).not.toBeNull();
87
+ expect(header.querySelector('[data-eldra-header-focus]')).not.toBeNull();
88
88
 
89
89
  expect(hero.querySelector('h1')?.textContent).toBe('Made slowly, used daily');
90
90
 
@@ -71,7 +71,7 @@ describe('product sample page', () => {
71
71
  const html = wrapper.html();
72
72
  const markers = [
73
73
  'Free shipping on orders over $80', // announcement-bar
74
- 'aria-label="Primary navigation"', // navigation
74
+ 'data-eldra-header-focus', // navigation
75
75
  'aria-label="Breadcrumb"', // breadcrumbs
76
76
  'aria-label="Product images"', // product-detail (gallery)
77
77
  'You may also like', // product-carousel
@@ -747,15 +747,10 @@ describe('prerendered commerce data on the generated static site', () => {
747
747
  expect(panelId).not.toBeNull();
748
748
  // Vitest's `expect` here, not Playwright's — the wait is the locator's own.
749
749
  await page.locator(`#${panelId ?? ''}`).waitFor({ state: 'visible' });
750
- // "Visible" is true from the *first* frame of the panel's entrance, and that entrance carries
751
- // a 4px rise (`-translate-y-1` over 150ms, `panelTransition` in `blocks/navigation/Block.vue`).
752
- // Measuring there reads the panel 4px above where it settles — which, plus the bar's own 1px
753
- // border, is exactly the 5px this geometry case used to fail by whenever the machine got to
754
- // `evaluate` inside 150ms. So wait for the transition itself to finish, not just for the
755
- // element to exist.
750
+ // "Visible" holds from the entrance's first frame, so wait for the panel's animations to end.
756
751
  await page.waitForFunction(
757
752
  (id) =>
758
- (document.getElementById(id)?.getAnimations() ?? []).every(
753
+ (document.getElementById(id)?.getAnimations({ subtree: true }) ?? []).every(
759
754
  (animation) => animation.playState !== 'running'
760
755
  ),
761
756
  panelId ?? ''
@@ -774,7 +769,7 @@ describe('prerendered commerce data on the generated static site', () => {
774
769
  const rect = panel.getBoundingClientRect();
775
770
  // The first column of the grid, and the "View all" anchor — the two pieces of content
776
771
  // that decide whether the panel has an inset at all.
777
- const firstColumn = panel.firstElementChild!.getBoundingClientRect();
772
+ const firstColumn = panel.querySelector('[data-part="group"]')!.getBoundingClientRect();
778
773
  const viewAll = panel.querySelector('[data-eldra-mega-view-all]')!.getBoundingClientRect();
779
774
  return {
780
775
  panel: { left: rect.left, right: rect.right, bottom: rect.bottom, top: rect.top },
@@ -810,7 +805,7 @@ describe('prerendered commerce data on the generated static site', () => {
810
805
  // resolve `--eldra-header-surface` through the theme's token variables, which exist only in a
811
806
  // real stylesheet — jsdom sees the class names and no colour at all. Second the leave: a panel
812
807
  // that merely stops being `display: block` is indistinguishable, in a mounted test, from one
813
- // that fades out over 120ms, and the fade is the whole point of the change.
808
+ // that fades out over `--eldra-duration-fast`, and the fade is the whole point of the change.
814
809
  //
815
810
  // Both bar states are measured, because they are the two different grounds the bar can be
816
811
  // asked about: the home page's header is solid, and the collection template's carries
@@ -851,8 +846,9 @@ describe('prerendered commerce data on the generated static site', () => {
851
846
 
852
847
  const open = await page.evaluate((id) => {
853
848
  const bar = document.querySelector('header')!;
849
+ const sheet = document.getElementById(id)!.querySelector('[data-part="content"]')!;
854
850
  return {
855
- panel: getComputedStyle(document.getElementById(id)!).backgroundColor,
851
+ panel: getComputedStyle(sheet).backgroundColor,
856
852
  bar: getComputedStyle(bar).backgroundColor,
857
853
  transparentAttribute: bar.getAttribute('data-eldra-transparent'),
858
854
  };
@@ -888,8 +884,7 @@ describe('prerendered commerce data on the generated static site', () => {
888
884
  panelId
889
885
  );
890
886
  expect(leave.faded, `${path} fades out`).toBe(true);
891
- // 120ms of leave: comfortably more than the frame a bare `v-show` would have taken, and
892
- // nowhere near a panel that never leaves at all.
887
+ // 150ms of leave (`--eldra-duration-fast`): more than a bare `v-show`'s one frame, less than never.
893
888
  expect(leave.hiddenAfterMs, path).toBeGreaterThanOrEqual(60);
894
889
  expect(leave.hiddenAfterMs, path).toBeLessThan(1000);
895
890
  expect(await trigger.getAttribute('aria-expanded'), path).toBe('false');
@@ -959,7 +954,7 @@ describe('prerendered commerce data on the generated static site', () => {
959
954
  // same classes. A difference here is a page that jumps on hydration.
960
955
  reserved:
961
956
  spacer === null ? null : spacer.firstElementChild!.getBoundingClientRect().height,
962
- nav: element.querySelector('nav')!.getBoundingClientRect().height,
957
+ nav: element.querySelector('[data-eldra-header-bar]')!.getBoundingClientRect().height,
963
958
  wrapper: wrapper === null ? null : wrapper.getBoundingClientRect().height,
964
959
  };
965
960
  });
@@ -1259,6 +1254,56 @@ describe('prerendered commerce data on the generated static site', () => {
1259
1254
  }
1260
1255
  });
1261
1256
 
1257
+ /** A campaign mail's link, through `@eldrajs/theme-nuxt`'s capture and the SDK's cart add, on a generated site. */
1258
+ it('credits the cart to the campaign the visitor landed from, once they agree', async () => {
1259
+ const campaignId = '0b9f8a52-3c1d-4e6f-9a7b-2c4d6e8f0a1b';
1260
+ const attribution = {
1261
+ campaignId,
1262
+ utmSource: 'eldra',
1263
+ utmMedium: 'email',
1264
+ utmCampaign: 'haustutsala',
1265
+ };
1266
+ const page = await browser.newPage();
1267
+ try {
1268
+ await page.goto(
1269
+ `${statics.origin}${productPage}?utm_source=eldra&utm_medium=email&utm_campaign=haustutsala` +
1270
+ `&utm_id=${campaignId}&gclid=not-kept`,
1271
+ { waitUntil: 'domcontentloaded' }
1272
+ );
1273
+ await page.waitForTimeout(CATALOG_DELAY_MS + 1500);
1274
+ const kept = () => page.evaluate(() => localStorage.getItem('eldra.campaignAttribution'));
1275
+ expect(await kept(), 'nothing is kept before the visitor agrees').toBeNull();
1276
+ const answer = (granted: boolean) =>
1277
+ page.evaluate((value) => {
1278
+ (
1279
+ window as Window & { eldraCampaignAttributionConsent?: boolean }
1280
+ ).eldraCampaignAttributionConsent = value;
1281
+ window.dispatchEvent(new Event('eldra:campaign-attribution-consent'));
1282
+ }, granted);
1283
+ await answer(true);
1284
+ const stored = await kept();
1285
+ expect(JSON.parse(stored ?? 'null')).toMatchObject({ ...attribution, consented: true });
1286
+ expect(stored).not.toContain('gclid');
1287
+
1288
+ gateway.reset();
1289
+ await page.locator('main button[type="submit"]', { hasText: 'Add to cart' }).first().click();
1290
+ await expect.poll(() => gateway.cartAdds.length, { timeout: 5000 }).toBe(1);
1291
+ expect(gateway.cartAdds[0]).toMatchObject({
1292
+ productId: expect.any(String),
1293
+ variantId: `var-${PRODUCT_HANDLE}`,
1294
+ attribution,
1295
+ });
1296
+
1297
+ await answer(false);
1298
+ expect(await kept(), 'withdrawing removes it').toBeNull();
1299
+ await page.locator('main button[type="submit"]', { hasText: 'Add to cart' }).first().click();
1300
+ await expect.poll(() => gateway.cartAdds.length, { timeout: 5000 }).toBe(2);
1301
+ expect(gateway.cartAdds[1]).not.toHaveProperty('attribution');
1302
+ } finally {
1303
+ await page.close();
1304
+ }
1305
+ });
1306
+
1262
1307
  /**
1263
1308
  * **A reload with a cart already in the browser.**
1264
1309
  *
@@ -50,23 +50,24 @@ describe('seoInput', () => {
50
50
  expect(input.options.contentImage).toMatch(/\/lg$/);
51
51
  });
52
52
 
53
- it('sets product.brand from the projection and product.category from the resolved name', () => {
53
+ it('sets product.category from the resolved name and no product.brand, even from a record that has one', () => {
54
54
  const input = seoInput({
55
55
  ...base,
56
56
  catalog: { kind: 'product', slug: 'mug' },
57
57
  productCategory: 'Mugs',
58
58
  entry: { data: { title: 'Mug', brand: 'Acme', variants: [] } },
59
59
  });
60
- expect(input.data).toMatchObject({ 'product.brand': 'Acme', 'product.category': 'Mugs' });
60
+ expect(input.data).toMatchObject({ 'product.category': 'Mugs' });
61
+ expect('product.brand' in input.data).toBe(false);
61
62
  });
62
63
 
63
- it('leaves product.brand and product.category empty when the product has none', () => {
64
+ it('leaves product.category empty when the product has none', () => {
64
65
  const input = seoInput({
65
66
  ...base,
66
67
  catalog: { kind: 'product', slug: 'mug' },
67
68
  entry: { data: { title: 'Mug' } },
68
69
  });
69
- expect(input.data).toMatchObject({ 'product.brand': '', 'product.category': '' });
70
+ expect(input.data).toMatchObject({ 'product.category': '' });
70
71
  });
71
72
 
72
73
  it('leaves a missing price empty instead of inventing one', () => {
@@ -976,6 +976,12 @@ describe('createGatewayStorefront', () => {
976
976
  * cannot read stock into an error for no reason. One box is sent in the platform's own
977
977
  * spelling, which the retired hyphenated one folds into.
978
978
  */
979
+ it('sends the on-sale switch as onSale=true, and nothing for a switch the platform does not name', async () => {
980
+ expect((await paramsFor({ 'toggle:on_sale': ['1'] })).get('onSale')).toBe('true');
981
+ expect((await paramsFor({ 'toggle:pre_order': ['1'] })).has('onSale')).toBe(false);
982
+ expect((await paramsFor({ 'toggle:on_sale': [] })).has('onSale')).toBe(false);
983
+ });
984
+
979
985
  it('sends one availability value, never both, and never an unknown one', async () => {
980
986
  expect((await paramsFor({ availability: ['in_stock'] })).get('availability')).toBe(
981
987
  'in_stock'
@@ -3,8 +3,10 @@ import { describe, expect, it } from 'vitest';
3
3
  import { createEldraClient, type EldraClient, type EldraHttpRequest } from '@eldrajs/sdk';
4
4
  import {
5
5
  createGatewayStorefront,
6
+ type GatewayStorefrontOptions,
6
7
  type StorefrontPrerenderHandle,
7
8
  } from '../../app/storefront/gateway';
9
+ import { CATEGORIES_MEMO_NAME } from '../../app/storefront/sharedRead';
8
10
  import { createVolatileRefresher, type VolatileRefresher } from '../../app/storefront/refresh';
9
11
  import {
10
12
  prerenderThroughAsyncData,
@@ -171,7 +173,8 @@ function asyncDataStub(payload: Record<string, unknown> = {}) {
171
173
  function wire(
172
174
  client: EldraClient,
173
175
  prerender?: <T>(key: string, load: () => Promise<T | null>) => StorefrontPrerenderHandle<T>,
174
- locale?: () => string | undefined
176
+ locale?: () => string | undefined,
177
+ shared?: GatewayStorefrontOptions['shared']
175
178
  ): { storefront: StorefrontSource; refresher: VolatileRefresher } {
176
179
  // The refresh runs when this spec says so, not on a schedule of its own. It reaches the
177
180
  // storefront declared below through the closure, exactly as the plugin's does.
@@ -183,6 +186,7 @@ function wire(
183
186
  route: fakeRoute(),
184
187
  runtime: { prerender, register: refresher.register },
185
188
  locale,
189
+ shared,
186
190
  });
187
191
  return { storefront, refresher };
188
192
  }
@@ -1035,3 +1039,24 @@ describe('gateway storefront — `loading`, and who is allowed to write', () =>
1035
1039
  expect(grid.loading.value).toBe(false);
1036
1040
  });
1037
1041
  });
1042
+
1043
+ describe('gateway storefront — the shared category read (WS-406)', () => {
1044
+ it('asks for the category rows under the kit name and the page locale', async () => {
1045
+ const asked: Array<{ name: string; locale: string | undefined }> = [];
1046
+ const shared: GatewayStorefrontOptions['shared'] = (name, load, locale) => {
1047
+ asked.push({ name, locale });
1048
+ return load();
1049
+ };
1050
+ for (const locale of [undefined, 'is-IS']) {
1051
+ const ssr = asyncDataStub();
1052
+ wire(fakeClient().client, ssr.prerender, () => locale, shared).storefront.catalog.product(
1053
+ ref('merino-crew-sweater')
1054
+ );
1055
+ await ssr.settleAll();
1056
+ }
1057
+ expect(asked).toEqual([
1058
+ { name: CATEGORIES_MEMO_NAME, locale: undefined },
1059
+ { name: CATEGORIES_MEMO_NAME, locale: 'is-IS' },
1060
+ ]);
1061
+ });
1062
+ });
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createSharedRead } from '../../app/storefront/sharedRead';
3
+
4
+ const CONFIG = {
5
+ gatewayUrl: 'https://origin.example/api',
6
+ orgId: 'org-1',
7
+ };
8
+
9
+ describe('storefront shared reads (WS-406)', () => {
10
+ function keys(config: typeof CONFIG, name: string, locale: string | undefined) {
11
+ const seen: Array<string | null> = [];
12
+ const shared = createSharedRead(config, (scope, _name, load) => {
13
+ seen.push(scope === null ? null : `${scope}|${_name}`);
14
+ return load();
15
+ });
16
+ void shared(name, async () => 1, locale);
17
+ return seen[0];
18
+ }
19
+
20
+ it('keys on gateway, organisation, locale and read name', () => {
21
+ const base = keys(CONFIG, 'categories', 'is-IS');
22
+ expect(base).toBe('https://origin.example/api|org-1|is-IS|categories');
23
+ expect(keys({ ...CONFIG, orgId: 'org-2' }, 'categories', 'is-IS')).not.toBe(base);
24
+ expect(keys(CONFIG, 'categories', 'en-US')).not.toBe(base);
25
+ expect(keys(CONFIG, 'categories', undefined)).toBe(
26
+ 'https://origin.example/api|org-1||categories'
27
+ );
28
+ });
29
+
30
+ it('never shares a read without a gateway and organisation to key on', () => {
31
+ expect(keys({ ...CONFIG, orgId: '' }, 'categories', undefined)).toBeNull();
32
+ });
33
+
34
+ it('keys by the origin gateway, not the browser base', () => {
35
+ const seen: Array<string | null> = [];
36
+ const shared = createSharedRead(CONFIG, (scope, _name, load) => {
37
+ seen.push(scope);
38
+ return load();
39
+ });
40
+ void shared('categories', async () => 1, undefined);
41
+ expect(seen[0]).toContain(CONFIG.gatewayUrl);
42
+ });
43
+ });
@@ -39,6 +39,7 @@ const parts = (over: Partial<PageLdParts> = {}): PageLdParts => ({
39
39
  logoUrl: 'https://media.test/icon-512',
40
40
  sameAs: [],
41
41
  contact: { email: null, telephone: null },
42
+ legal: null,
42
43
  },
43
44
  searchPath: '/search',
44
45
  ...over,
@@ -63,6 +64,36 @@ describe('pageStructuredData', () => {
63
64
  ]);
64
65
  });
65
66
 
67
+ it('writes the registered company on the home Organization', () => {
68
+ const legal = {
69
+ name: 'Eldra Tech ehf.',
70
+ kennitala: '500826-1770',
71
+ streetAddress: null,
72
+ postalCode: '101',
73
+ city: 'Reykjavík',
74
+ countryCode: 'IS',
75
+ };
76
+ const [organization] = pageStructuredData(
77
+ parts({ kind: 'home', profile: { ...parts().profile, legal } })
78
+ );
79
+ expect(organization!.node).toMatchObject({
80
+ legalName: 'Eldra Tech ehf.',
81
+ taxID: '500826-1770',
82
+ address: {
83
+ '@type': 'PostalAddress',
84
+ postalCode: '101',
85
+ addressLocality: 'Reykjavík',
86
+ addressCountry: 'IS',
87
+ },
88
+ });
89
+ expect(organization!.node).not.toHaveProperty('address.streetAddress');
90
+
91
+ const [bare] = pageStructuredData(parts({ kind: 'home' }));
92
+ expect(bare!.node).not.toHaveProperty('legalName');
93
+ expect(bare!.node).not.toHaveProperty('taxID');
94
+ expect(bare!.node).not.toHaveProperty('address');
95
+ });
96
+
66
97
  it('writes nothing for the not-found shell', () => {
67
98
  expect(pageStructuredData(parts({ kind: 'notFound' }))).toEqual([]);
68
99
  });
@@ -74,7 +105,7 @@ describe('pageStructuredData', () => {
74
105
  title: 'Mug',
75
106
  currentUrl: `${ORIGIN}/products/mug`,
76
107
  trail: [{ label: 'Cups', path: '/categories/cups' }],
77
- product: product({ brand: 'Acme' }),
108
+ product: product(),
78
109
  })
79
110
  );
80
111
  expect(types(entries)).toEqual(['breadcrumb', 'product']);
@@ -86,14 +117,14 @@ describe('pageStructuredData', () => {
86
117
  name: 'Mug',
87
118
  description: 'A hand-thrown mug.',
88
119
  image: ['https://cdn.test/mug.jpg'],
89
- brand: { name: 'Acme' },
120
+ brand: { name: 'Shop' },
90
121
  offers: { price: 2800, priceCurrency: 'ISK', availability: 'https://schema.org/InStock' },
91
122
  });
92
123
  // The number the markup states is the number the visible price is formatted from.
93
124
  expect(formatMoney(node.offers.price, 'ISK', 'en-US')).toContain('2,800');
94
125
  });
95
126
 
96
- it('maps stock states to availability and falls back to the shop name as brand', () => {
127
+ it('maps stock states to availability', () => {
97
128
  const availability = (stock: StorefrontProduct['stock']) =>
98
129
  (
99
130
  pageStructuredData(parts({ kind: 'product', product: product({ stock }) }))[1]!.node
@@ -102,9 +133,6 @@ describe('pageStructuredData', () => {
102
133
  expect(availability('out')).toBe('https://schema.org/OutOfStock');
103
134
  expect(availability('preorder')).toBe('https://schema.org/PreOrder');
104
135
  expect(availability('low')).toBe('https://schema.org/LimitedAvailability');
105
- expect(
106
- pageStructuredData(parts({ kind: 'product', product: product() }))[1]!.node.brand
107
- ).toEqual({ '@type': 'Brand', name: 'Shop' });
108
136
  });
109
137
 
110
138
  it('writes one offer per variant, AggregateOffer when prices differ, and drops a bad barcode', () => {
@@ -112,7 +112,7 @@ describe('generated pages carry schema.org JSON-LD', () => {
112
112
  expect(product).toMatchObject({
113
113
  name: 'Ash glaze mug',
114
114
  url: `${ORIGIN}/products/${PRODUCT_HANDLE}`,
115
- brand: { name: 'Northwind Ceramics' },
115
+ brand: { name: 'Northwind Goods' },
116
116
  sku: PRODUCT_HANDLE.toUpperCase(),
117
117
  gtin: '4006381333931',
118
118
  offers: {
@@ -65,7 +65,6 @@ interface MockProduct {
65
65
  minPrice: number;
66
66
  maxPrice: number;
67
67
  compareAtPrice?: number;
68
- brand?: string;
69
68
  variants: MockVariant[];
70
69
  }
71
70
 
@@ -92,7 +91,6 @@ export const COLLECTION_HANDLE = 'the-winter-edit';
92
91
 
93
92
  export const PRODUCTS: MockProduct[] = [
94
93
  product(PRODUCT_HANDLE, 'Ash glaze mug', 42, {
95
- brand: 'Northwind Ceramics',
96
94
  variants: [
97
95
  {
98
96
  id: `var-${PRODUCT_HANDLE}`,
@@ -234,7 +232,6 @@ const detailOf = (row: MockProduct): Record<string, unknown> => ({
234
232
  // already read. Both, with the same value, is what a live response looks like.
235
233
  primaryCategoryId: row.categoryId,
236
234
  categoryIds: [row.categoryId],
237
- ...(row.brand === undefined ? {} : { brand: row.brand }),
238
235
  description: { text: `${row.title} — thrown by hand, glazed in ash.` },
239
236
  mediaLinks: [],
240
237
  options: [],
@@ -797,6 +794,8 @@ export interface MockGateway {
797
794
  url: string;
798
795
  /** `pathname + search` of every request, in order. */
799
796
  requests: string[];
797
+ /** The JSON body of every `POST /shopping-cart/v1/cart/items`, in order; each answers the seeded cart. */
798
+ cartAdds: unknown[];
800
799
  /** Milliseconds every `/catalog/v1/**` answer is held back. Settable between phases. */
801
800
  catalogDelayMs: number;
802
801
  /**
@@ -828,6 +827,7 @@ export function startMockGateway(
828
827
  setMockCatalogContract(options.catalogContract ?? '3.8.0');
829
828
  return new Promise((resolve) => {
830
829
  const requests: string[] = [];
830
+ const cartAdds: unknown[] = [];
831
831
  const state = {
832
832
  catalogDelayMs: 0,
833
833
  cartDelayMs: 0,
@@ -965,6 +965,9 @@ export function startMockGateway(
965
965
  );
966
966
  } else if (url.pathname === '/inventory/v1/stock/availability') {
967
967
  answer(availabilityOf(await readJsonBody(req)));
968
+ } else if (url.pathname === '/shopping-cart/v1/cart/items' && req.method === 'POST') {
969
+ cartAdds.push(await readJsonBody(req));
970
+ answer(seededCart());
968
971
  } else if (segments[0] === 'shopping-cart' && segments[2] === 'cart') {
969
972
  // The one cart this mock knows, and only by the id a test seeded. Any other id is a cart
970
973
  // the gateway has forgotten — which the store answers by clearing `eldra.cartId` and
@@ -1014,6 +1017,7 @@ export function startMockGateway(
1014
1017
  server,
1015
1018
  url: `http://127.0.0.1:${address.port}`,
1016
1019
  requests,
1020
+ cartAdds,
1017
1021
  get catalogDelayMs() {
1018
1022
  return state.catalogDelayMs;
1019
1023
  },
@@ -1034,6 +1038,7 @@ export function startMockGateway(
1034
1038
  },
1035
1039
  reset() {
1036
1040
  requests.length = 0;
1041
+ cartAdds.length = 0;
1037
1042
  },
1038
1043
  close: () =>
1039
1044
  new Promise<void>((done, fail) =>