@merchi/cart 1.4.63 → 1.4.64

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.
@@ -1,7 +1,13 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
3
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
4
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
4
5
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
11
  import * as React from 'react';
6
12
  import { createRoot } from 'react-dom/client';
7
13
  import { act } from 'react-dom/test-utils';
@@ -12,6 +18,7 @@ import { tabIdClearCart, tabIdItems } from './utilities/tabs';
12
18
  import { jsx as _jsx } from "react/jsx-runtime";
13
19
  var mockGet = jest.fn();
14
20
  var mockPost = jest.fn();
21
+ var mockCreateItem = jest.fn();
15
22
  jest.mock('@merchi/sdk', function () {
16
23
  return {
17
24
  Merchi: jest.fn().mockImplementation(function () {
@@ -30,13 +37,22 @@ jest.mock('@merchi/sdk', function () {
30
37
  });
31
38
  jest.mock('./utilities/product', function () {
32
39
  return {
33
- makeProduct: jest.fn()
40
+ makeProduct: jest.fn(function (json) {
41
+ return json;
42
+ })
43
+ };
44
+ });
45
+ jest.mock('./utilities/job', function () {
46
+ return {
47
+ makeJob: jest.fn(function (json) {
48
+ return json;
49
+ })
34
50
  };
35
51
  });
36
52
  jest.mock('./utilities/cart', function () {
37
53
  return {
38
- makeCart: function makeCart() {
39
- return {
54
+ makeCart: function makeCart(json) {
55
+ return _objectSpread(_objectSpread({}, json), {}, {
40
56
  toFormData: function toFormData() {
41
57
  return new FormData();
42
58
  },
@@ -48,6 +64,11 @@ jest.mock('./utilities/cart', function () {
48
64
  isTest: false
49
65
  };
50
66
  }
67
+ });
68
+ },
69
+ makeCartItem: function makeCartItem() {
70
+ return {
71
+ create: mockCreateItem
51
72
  };
52
73
  },
53
74
  stripeIsValidAndActive: function stripeIsValidAndActive() {
@@ -89,6 +110,9 @@ jest.mock('./utilities/job_source', function () {
89
110
  jest.mock('./utilities/reportFailure', function () {
90
111
  return {
91
112
  reportCartFailure: jest.fn(),
113
+ reportAddCartItemFailure: jest.fn(function (error, onError) {
114
+ return onError(error);
115
+ }),
92
116
  CART_FAILURE_SOURCES: {
93
117
  load: 'cart.load',
94
118
  create: 'cart.create'
@@ -103,8 +127,33 @@ function Probe() {
103
127
  describe('cart load and replacement failures', function () {
104
128
  var root;
105
129
  var container;
130
+ var userAgentDescriptor = Object.getOwnPropertyDescriptor(navigator, 'userAgent');
131
+ var headlessUserAgent = 'Mozilla/5.0 (X11; Linux x86_64) HeadlessChrome/153.0.8010.0 Safari/537.36';
132
+ function setUserAgent(value) {
133
+ Object.defineProperty(navigator, 'userAgent', {
134
+ configurable: true,
135
+ value: value
136
+ });
137
+ }
106
138
  beforeEach(function () {
107
139
  jest.clearAllMocks();
140
+ mockGet.mockReset();
141
+ mockPost.mockReset();
142
+ mockCreateItem.mockReset();
143
+ mockCreateItem.mockImplementation(function () {
144
+ var _this = this;
145
+ return Promise.resolve({
146
+ toJson: function toJson() {
147
+ return {
148
+ id: 7,
149
+ cart: {
150
+ id: _this.cart.id
151
+ }
152
+ };
153
+ }
154
+ });
155
+ });
156
+ getCartCookie.mockReset();
108
157
  globalThis.IS_REACT_ACT_ENVIRONMENT = true;
109
158
  container = document.createElement('div');
110
159
  document.body.appendChild(container);
@@ -132,6 +181,7 @@ describe('cart load and replacement failures', function () {
132
181
  })));
133
182
  case 1:
134
183
  container.remove();
184
+ if (userAgentDescriptor) Object.defineProperty(navigator, 'userAgent', userAgentDescriptor);else delete navigator.userAgent;
135
185
  case 2:
136
186
  return _context2.a(2);
137
187
  }
@@ -141,15 +191,15 @@ describe('cart load and replacement failures', function () {
141
191
  return _mount.apply(this, arguments);
142
192
  }
143
193
  function _mount() {
144
- _mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(error) {
145
- return _regenerator().w(function (_context29) {
146
- while (1) switch (_context29.n) {
194
+ _mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(error) {
195
+ return _regenerator().w(function (_context60) {
196
+ while (1) switch (_context60.n) {
147
197
  case 0:
148
198
  mockGet.mockRejectedValue(error);
149
- _context29.n = 1;
150
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28() {
151
- return _regenerator().w(function (_context28) {
152
- while (1) switch (_context28.n) {
199
+ _context60.n = 1;
200
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59() {
201
+ return _regenerator().w(function (_context59) {
202
+ while (1) switch (_context59.n) {
153
203
  case 0:
154
204
  root.render(/*#__PURE__*/_jsx(CartProvider, {
155
205
  domainId: 5,
@@ -163,14 +213,14 @@ describe('cart load and replacement failures', function () {
163
213
  children: /*#__PURE__*/_jsx(Probe, {})
164
214
  }));
165
215
  case 1:
166
- return _context28.a(2);
216
+ return _context59.a(2);
167
217
  }
168
- }, _callee28);
218
+ }, _callee59);
169
219
  })));
170
220
  case 1:
171
- return _context29.a(2);
221
+ return _context60.a(2);
172
222
  }
173
- }, _callee29);
223
+ }, _callee60);
174
224
  }));
175
225
  return _mount.apply(this, arguments);
176
226
  }
@@ -178,9 +228,9 @@ describe('cart load and replacement failures', function () {
178
228
  return _mountSavedCart.apply(this, arguments);
179
229
  }
180
230
  function _mountSavedCart() {
181
- _mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
182
- return _regenerator().w(function (_context32) {
183
- while (1) switch (_context32.n) {
231
+ _mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63() {
232
+ return _regenerator().w(function (_context63) {
233
+ while (1) switch (_context63.n) {
184
234
  case 0:
185
235
  mockGet.mockResolvedValue({
186
236
  toJson: function toJson() {
@@ -193,10 +243,10 @@ describe('cart load and replacement failures', function () {
193
243
  };
194
244
  }
195
245
  });
196
- _context32.n = 1;
197
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
198
- return _regenerator().w(function (_context30) {
199
- while (1) switch (_context30.n) {
246
+ _context63.n = 1;
247
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61() {
248
+ return _regenerator().w(function (_context61) {
249
+ while (1) switch (_context61.n) {
200
250
  case 0:
201
251
  root.render(/*#__PURE__*/_jsx(CartProvider, {
202
252
  domainId: 5,
@@ -204,31 +254,548 @@ describe('cart load and replacement failures', function () {
204
254
  children: /*#__PURE__*/_jsx(Probe, {})
205
255
  }));
206
256
  case 1:
207
- return _context30.a(2);
257
+ return _context61.a(2);
208
258
  }
209
- }, _callee30);
259
+ }, _callee61);
210
260
  })));
211
261
  case 1:
212
- _context32.n = 2;
213
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31() {
214
- return _regenerator().w(function (_context31) {
215
- while (1) switch (_context31.n) {
262
+ _context63.n = 2;
263
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62() {
264
+ return _regenerator().w(function (_context62) {
265
+ while (1) switch (_context62.n) {
216
266
  case 0:
217
- return _context31.a(2, context.setActiveTabIndex(tabIdClearCart));
267
+ return _context62.a(2, context.setActiveTabIndex(tabIdClearCart));
218
268
  }
219
- }, _callee31);
269
+ }, _callee62);
220
270
  })));
221
271
  case 2:
222
- return _context32.a(2);
272
+ return _context63.a(2);
223
273
  }
224
- }, _callee32);
274
+ }, _callee63);
225
275
  }));
226
276
  return _mountSavedCart.apply(this, arguments);
227
277
  }
228
- it('shares cold initialization with opening the modal and concurrent getCart callers', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
278
+ it.each(['Mozilla/5.0 (X11; Linux x86_64) HeadlessChrome/153.0.8010.0 Safari/537.36', 'Mozilla/5.0 (compatible; Baiduspider-render/2.0)'])('does not create an unused cart on automated startup: %s', /*#__PURE__*/function () {
279
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(userAgent) {
280
+ return _regenerator().w(function (_context4) {
281
+ while (1) switch (_context4.n) {
282
+ case 0:
283
+ setUserAgent(userAgent);
284
+ getCartCookie.mockResolvedValue(undefined);
285
+ _context4.n = 1;
286
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
287
+ return _regenerator().w(function (_context3) {
288
+ while (1) switch (_context3.n) {
289
+ case 0:
290
+ return _context3.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
291
+ domainId: 5,
292
+ createCartAndCookie: function createCartAndCookie() {},
293
+ children: /*#__PURE__*/_jsx(Probe, {})
294
+ })));
295
+ }
296
+ }, _callee3);
297
+ })));
298
+ case 1:
299
+ expect(mockGet).not.toHaveBeenCalled();
300
+ expect(mockPost).not.toHaveBeenCalled();
301
+ expect(context.fetchingCart).toBe(false);
302
+ expect(reportCartFailure).not.toHaveBeenCalled();
303
+ case 2:
304
+ return _context4.a(2);
305
+ }
306
+ }, _callee4);
307
+ }));
308
+ return function (_x2) {
309
+ return _ref3.apply(this, arguments);
310
+ };
311
+ }());
312
+ it('allows explicit cart opening and concurrent callers in an automated browser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
313
+ return _regenerator().w(function (_context7) {
314
+ while (1) switch (_context7.n) {
315
+ case 0:
316
+ setUserAgent(headlessUserAgent);
317
+ getCartCookie.mockResolvedValue(undefined);
318
+ _context7.n = 1;
319
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
320
+ return _regenerator().w(function (_context5) {
321
+ while (1) switch (_context5.n) {
322
+ case 0:
323
+ return _context5.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
324
+ domainId: 5,
325
+ createCartAndCookie: function createCartAndCookie() {},
326
+ children: /*#__PURE__*/_jsx(Probe, {})
327
+ })));
328
+ }
329
+ }, _callee5);
330
+ })));
331
+ case 1:
332
+ expect(mockPost).not.toHaveBeenCalled();
333
+ _context7.n = 2;
334
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
335
+ return _regenerator().w(function (_context6) {
336
+ while (1) switch (_context6.n) {
337
+ case 0:
338
+ context.toggleCartModal();
339
+ _context6.n = 1;
340
+ return Promise.all([window.getCart(), window.refetchCart()]);
341
+ case 1:
342
+ return _context6.a(2);
343
+ }
344
+ }, _callee6);
345
+ })));
346
+ case 2:
347
+ expect(mockPost).toHaveBeenCalledTimes(1);
348
+ expect(context.cart.id).toBe(99);
349
+ case 3:
350
+ return _context7.a(2);
351
+ }
352
+ }, _callee7);
353
+ })));
354
+ it('creates once when explicit interaction joins a pending passive cookie lookup', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
355
+ var finishCookie, first, second;
356
+ return _regenerator().w(function (_context1) {
357
+ while (1) switch (_context1.n) {
358
+ case 0:
359
+ setUserAgent(headlessUserAgent);
360
+ getCartCookie.mockImplementationOnce(function () {
361
+ return new Promise(function (resolve) {
362
+ finishCookie = resolve;
363
+ });
364
+ }).mockResolvedValue(undefined);
365
+ _context1.n = 1;
366
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
367
+ return _regenerator().w(function (_context8) {
368
+ while (1) switch (_context8.n) {
369
+ case 0:
370
+ return _context8.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
371
+ domainId: 5,
372
+ createCartAndCookie: function createCartAndCookie() {},
373
+ children: /*#__PURE__*/_jsx(Probe, {})
374
+ })));
375
+ }
376
+ }, _callee8);
377
+ })));
378
+ case 1:
379
+ _context1.n = 2;
380
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
381
+ return _regenerator().w(function (_context9) {
382
+ while (1) switch (_context9.n) {
383
+ case 0:
384
+ first = window.getCart();
385
+ second = window.getCart();
386
+ context.toggleCartModal();
387
+ case 1:
388
+ return _context9.a(2);
389
+ }
390
+ }, _callee9);
391
+ })));
392
+ case 2:
393
+ expect(mockPost).not.toHaveBeenCalled();
394
+ _context1.n = 3;
395
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
396
+ return _regenerator().w(function (_context0) {
397
+ while (1) switch (_context0.n) {
398
+ case 0:
399
+ finishCookie(undefined);
400
+ _context0.n = 1;
401
+ return Promise.all([first, second]);
402
+ case 1:
403
+ return _context0.a(2);
404
+ }
405
+ }, _callee0);
406
+ })));
407
+ case 3:
408
+ expect(mockPost).toHaveBeenCalledTimes(1);
409
+ expect(context.cart.id).toBe(99);
410
+ case 4:
411
+ return _context1.a(2);
412
+ }
413
+ }, _callee1);
414
+ })));
415
+ it('restores saved carts for automated clients without duplicating an active read', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
416
+ var finish, read;
417
+ return _regenerator().w(function (_context13) {
418
+ while (1) switch (_context13.n) {
419
+ case 0:
420
+ setUserAgent(headlessUserAgent);
421
+ mockGet.mockImplementationOnce(function () {
422
+ return new Promise(function (resolve) {
423
+ finish = resolve;
424
+ });
425
+ });
426
+ _context13.n = 1;
427
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
428
+ return _regenerator().w(function (_context10) {
429
+ while (1) switch (_context10.n) {
430
+ case 0:
431
+ return _context10.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
432
+ domainId: 5,
433
+ createCartAndCookie: function createCartAndCookie() {},
434
+ children: /*#__PURE__*/_jsx(Probe, {})
435
+ })));
436
+ }
437
+ }, _callee10);
438
+ })));
439
+ case 1:
440
+ _context13.n = 2;
441
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
442
+ return _regenerator().w(function (_context11) {
443
+ while (1) switch (_context11.n) {
444
+ case 0:
445
+ read = window.getCart();
446
+ context.toggleCartModal();
447
+ case 1:
448
+ return _context11.a(2);
449
+ }
450
+ }, _callee11);
451
+ })));
452
+ case 2:
453
+ expect(mockGet).toHaveBeenCalledTimes(1);
454
+ _context13.n = 3;
455
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
456
+ return _regenerator().w(function (_context12) {
457
+ while (1) switch (_context12.n) {
458
+ case 0:
459
+ finish({
460
+ toJson: function toJson() {
461
+ return {
462
+ id: 42,
463
+ isTest: false,
464
+ cartItems: [{
465
+ id: 7
466
+ }]
467
+ };
468
+ }
469
+ });
470
+ _context12.n = 1;
471
+ return read;
472
+ case 1:
473
+ return _context12.a(2);
474
+ }
475
+ }, _callee12);
476
+ })));
477
+ case 3:
478
+ expect(mockPost).not.toHaveBeenCalled();
479
+ expect(context.cart.cartItems).toHaveLength(1);
480
+ case 4:
481
+ return _context13.a(2);
482
+ }
483
+ }, _callee13);
484
+ })));
485
+ it('keeps explicit retry available after an automated client creation fails', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
486
+ return _regenerator().w(function (_context17) {
487
+ while (1) switch (_context17.n) {
488
+ case 0:
489
+ setUserAgent(headlessUserAgent);
490
+ getCartCookie.mockResolvedValue(undefined);
491
+ mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
492
+ _context17.n = 1;
493
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
494
+ return _regenerator().w(function (_context14) {
495
+ while (1) switch (_context14.n) {
496
+ case 0:
497
+ return _context14.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
498
+ domainId: 5,
499
+ createCartAndCookie: function createCartAndCookie() {},
500
+ children: /*#__PURE__*/_jsx(Probe, {})
501
+ })));
502
+ }
503
+ }, _callee14);
504
+ })));
505
+ case 1:
506
+ expect(mockPost).not.toHaveBeenCalled();
507
+ _context17.n = 2;
508
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
509
+ return _regenerator().w(function (_context15) {
510
+ while (1) switch (_context15.n) {
511
+ case 0:
512
+ _context15.n = 1;
513
+ return window.getCart();
514
+ case 1:
515
+ return _context15.a(2);
516
+ }
517
+ }, _callee15);
518
+ })));
519
+ case 2:
520
+ expect(mockPost).toHaveBeenCalledTimes(1);
521
+ expect(context.fetchingCart).toBe(false);
522
+ _context17.n = 3;
523
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
524
+ return _regenerator().w(function (_context16) {
525
+ while (1) switch (_context16.n) {
526
+ case 0:
527
+ _context16.n = 1;
528
+ return window.getCart();
529
+ case 1:
530
+ return _context16.a(2);
531
+ }
532
+ }, _callee16);
533
+ })));
534
+ case 3:
535
+ expect(mockPost).toHaveBeenCalledTimes(2);
536
+ expect(context.cart.id).toBe(99);
537
+ case 4:
538
+ return _context17.a(2);
539
+ }
540
+ }, _callee17);
541
+ })));
542
+ it('initializes a cart for a direct item operation without a storefront readiness helper', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20() {
543
+ var onSuccess, onError;
544
+ return _regenerator().w(function (_context20) {
545
+ while (1) switch (_context20.n) {
546
+ case 0:
547
+ setUserAgent(headlessUserAgent);
548
+ getCartCookie.mockResolvedValue(undefined);
549
+ _context20.n = 1;
550
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
551
+ return _regenerator().w(function (_context18) {
552
+ while (1) switch (_context18.n) {
553
+ case 0:
554
+ return _context18.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
555
+ domainId: 5,
556
+ createCartAndCookie: function createCartAndCookie() {},
557
+ children: /*#__PURE__*/_jsx(Probe, {})
558
+ })));
559
+ }
560
+ }, _callee18);
561
+ })));
562
+ case 1:
563
+ onSuccess = jest.fn(), onError = jest.fn();
564
+ _context20.n = 2;
565
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
566
+ return _regenerator().w(function (_context19) {
567
+ while (1) switch (_context19.n) {
568
+ case 0:
569
+ _context19.n = 1;
570
+ return window.addCartItem({
571
+ product: {
572
+ id: 44
573
+ },
574
+ quantity: 100
575
+ }, onSuccess, onError);
576
+ case 1:
577
+ return _context19.a(2);
578
+ }
579
+ }, _callee19);
580
+ })));
581
+ case 2:
582
+ expect(mockPost).toHaveBeenCalledTimes(1);
583
+ expect(mockCreateItem).toHaveBeenCalledTimes(1);
584
+ expect(onSuccess).toHaveBeenCalledWith({
585
+ id: 7,
586
+ cart: {
587
+ id: 99
588
+ }
589
+ });
590
+ expect(onError).not.toHaveBeenCalled();
591
+ case 3:
592
+ return _context20.a(2);
593
+ }
594
+ }, _callee20);
595
+ })));
596
+ it('rejects a direct item operation when initialization fails without posting an item', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23() {
597
+ var onSuccess, onError;
598
+ return _regenerator().w(function (_context23) {
599
+ while (1) switch (_context23.n) {
600
+ case 0:
601
+ setUserAgent(headlessUserAgent);
602
+ getCartCookie.mockResolvedValue(undefined);
603
+ mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
604
+ _context23.n = 1;
605
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21() {
606
+ return _regenerator().w(function (_context21) {
607
+ while (1) switch (_context21.n) {
608
+ case 0:
609
+ return _context21.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
610
+ domainId: 5,
611
+ createCartAndCookie: function createCartAndCookie() {},
612
+ children: /*#__PURE__*/_jsx(Probe, {})
613
+ })));
614
+ }
615
+ }, _callee21);
616
+ })));
617
+ case 1:
618
+ onSuccess = jest.fn(), onError = jest.fn();
619
+ _context23.n = 2;
620
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22() {
621
+ return _regenerator().w(function (_context22) {
622
+ while (1) switch (_context22.n) {
623
+ case 0:
624
+ _context22.n = 1;
625
+ return window.addCartItem({
626
+ product: {
627
+ id: 44
628
+ },
629
+ quantity: 100
630
+ }, onSuccess, onError);
631
+ case 1:
632
+ return _context22.a(2);
633
+ }
634
+ }, _callee22);
635
+ })));
636
+ case 2:
637
+ expect(mockPost).toHaveBeenCalledTimes(1);
638
+ expect(mockCreateItem).not.toHaveBeenCalled();
639
+ expect(onSuccess).not.toHaveBeenCalled();
640
+ expect(onError).toHaveBeenCalledTimes(1);
641
+ expect(context.fetchingCart).toBe(false);
642
+ case 3:
643
+ return _context23.a(2);
644
+ }
645
+ }, _callee23);
646
+ })));
647
+ it('waits for ordinary startup before concurrent direct item operations', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27() {
648
+ var finish, onSuccess, onError, first, second;
649
+ return _regenerator().w(function (_context27) {
650
+ while (1) switch (_context27.n) {
651
+ case 0:
652
+ getCartCookie.mockResolvedValue(undefined);
653
+ mockPost.mockImplementationOnce(function () {
654
+ return new Promise(function (resolve) {
655
+ finish = resolve;
656
+ });
657
+ });
658
+ _context27.n = 1;
659
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24() {
660
+ return _regenerator().w(function (_context24) {
661
+ while (1) switch (_context24.n) {
662
+ case 0:
663
+ return _context24.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
664
+ domainId: 5,
665
+ createCartAndCookie: function createCartAndCookie() {},
666
+ children: /*#__PURE__*/_jsx(Probe, {})
667
+ })));
668
+ }
669
+ }, _callee24);
670
+ })));
671
+ case 1:
672
+ onSuccess = jest.fn(), onError = jest.fn();
673
+ _context27.n = 2;
674
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25() {
675
+ var job;
676
+ return _regenerator().w(function (_context25) {
677
+ while (1) switch (_context25.n) {
678
+ case 0:
679
+ job = {
680
+ product: {
681
+ id: 44
682
+ },
683
+ quantity: 100
684
+ };
685
+ first = window.addCartItem(job, onSuccess, onError);
686
+ second = window.addCartItem(job, onSuccess, onError);
687
+ case 1:
688
+ return _context25.a(2);
689
+ }
690
+ }, _callee25);
691
+ })));
692
+ case 2:
693
+ expect(mockCreateItem).not.toHaveBeenCalled();
694
+ _context27.n = 3;
695
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26() {
696
+ return _regenerator().w(function (_context26) {
697
+ while (1) switch (_context26.n) {
698
+ case 0:
699
+ finish({
700
+ cart: {
701
+ id: 99,
702
+ token: 'new-token'
703
+ }
704
+ });
705
+ _context26.n = 1;
706
+ return Promise.all([first, second]);
707
+ case 1:
708
+ return _context26.a(2);
709
+ }
710
+ }, _callee26);
711
+ })));
712
+ case 3:
713
+ expect(mockPost).toHaveBeenCalledTimes(1);
714
+ expect(onSuccess.mock.calls.map(function (call) {
715
+ return call[0].cart.id;
716
+ })).toEqual([99, 99]);
717
+ expect(onError).not.toHaveBeenCalled();
718
+ case 4:
719
+ return _context27.a(2);
720
+ }
721
+ }, _callee27);
722
+ })));
723
+ it('does not automatically repeat a failed item write after explicit initialization', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31() {
724
+ var onSuccess, onError, job;
725
+ return _regenerator().w(function (_context31) {
726
+ while (1) switch (_context31.n) {
727
+ case 0:
728
+ setUserAgent(headlessUserAgent);
729
+ getCartCookie.mockResolvedValue(undefined);
730
+ mockCreateItem.mockRejectedValueOnce(new TypeError('Failed to fetch'));
731
+ _context31.n = 1;
732
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28() {
733
+ return _regenerator().w(function (_context28) {
734
+ while (1) switch (_context28.n) {
735
+ case 0:
736
+ return _context28.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
737
+ domainId: 5,
738
+ createCartAndCookie: function createCartAndCookie() {},
739
+ children: /*#__PURE__*/_jsx(Probe, {})
740
+ })));
741
+ }
742
+ }, _callee28);
743
+ })));
744
+ case 1:
745
+ onSuccess = jest.fn(), onError = jest.fn();
746
+ job = {
747
+ product: {
748
+ id: 44
749
+ },
750
+ quantity: 100
751
+ };
752
+ _context31.n = 2;
753
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29() {
754
+ return _regenerator().w(function (_context29) {
755
+ while (1) switch (_context29.n) {
756
+ case 0:
757
+ _context29.n = 1;
758
+ return window.addCartItem(job, onSuccess, onError);
759
+ case 1:
760
+ return _context29.a(2);
761
+ }
762
+ }, _callee29);
763
+ })));
764
+ case 2:
765
+ expect(mockPost).toHaveBeenCalledTimes(1);
766
+ expect(mockCreateItem).toHaveBeenCalledTimes(1);
767
+ expect(onSuccess).not.toHaveBeenCalled();
768
+ expect(onError).toHaveBeenCalledTimes(1);
769
+ _context31.n = 3;
770
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
771
+ return _regenerator().w(function (_context30) {
772
+ while (1) switch (_context30.n) {
773
+ case 0:
774
+ _context30.n = 1;
775
+ return window.addCartItem(job, onSuccess, onError);
776
+ case 1:
777
+ return _context30.a(2);
778
+ }
779
+ }, _callee30);
780
+ })));
781
+ case 3:
782
+ expect(mockPost).toHaveBeenCalledTimes(1);
783
+ expect(mockCreateItem).toHaveBeenCalledTimes(2);
784
+ expect(onSuccess).toHaveBeenCalledWith({
785
+ id: 7,
786
+ cart: {
787
+ id: 99
788
+ }
789
+ });
790
+ case 4:
791
+ return _context31.a(2);
792
+ }
793
+ }, _callee31);
794
+ })));
795
+ it('shares cold initialization with opening the modal and concurrent getCart callers', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35() {
229
796
  var finish, first, second;
230
- return _regenerator().w(function (_context6) {
231
- while (1) switch (_context6.n) {
797
+ return _regenerator().w(function (_context35) {
798
+ while (1) switch (_context35.n) {
232
799
  case 0:
233
800
  getCartCookie.mockResolvedValue(undefined);
234
801
  mockPost.mockImplementationOnce(function () {
@@ -236,40 +803,40 @@ describe('cart load and replacement failures', function () {
236
803
  finish = resolve;
237
804
  });
238
805
  });
239
- _context6.n = 1;
240
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
241
- return _regenerator().w(function (_context3) {
242
- while (1) switch (_context3.n) {
806
+ _context35.n = 1;
807
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
808
+ return _regenerator().w(function (_context32) {
809
+ while (1) switch (_context32.n) {
243
810
  case 0:
244
- return _context3.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
811
+ return _context32.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
245
812
  domainId: 5,
246
813
  createCartAndCookie: function createCartAndCookie() {},
247
814
  children: /*#__PURE__*/_jsx(Probe, {})
248
815
  })));
249
816
  }
250
- }, _callee3);
817
+ }, _callee32);
251
818
  })));
252
819
  case 1:
253
- _context6.n = 2;
254
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
255
- return _regenerator().w(function (_context4) {
256
- while (1) switch (_context4.n) {
820
+ _context35.n = 2;
821
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33() {
822
+ return _regenerator().w(function (_context33) {
823
+ while (1) switch (_context33.n) {
257
824
  case 0:
258
825
  context.toggleCartModal();
259
826
  first = window.getCart();
260
827
  second = window.getCart();
261
828
  case 1:
262
- return _context4.a(2);
829
+ return _context33.a(2);
263
830
  }
264
- }, _callee4);
831
+ }, _callee33);
265
832
  })));
266
833
  case 2:
267
834
  expect(mockPost).toHaveBeenCalledTimes(1);
268
835
  expect(context.fetchingCart).toBe(true);
269
- _context6.n = 3;
270
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
271
- return _regenerator().w(function (_context5) {
272
- while (1) switch (_context5.n) {
836
+ _context35.n = 3;
837
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34() {
838
+ return _regenerator().w(function (_context34) {
839
+ while (1) switch (_context34.n) {
273
840
  case 0:
274
841
  finish({
275
842
  cart: {
@@ -277,26 +844,26 @@ describe('cart load and replacement failures', function () {
277
844
  token: 'new-token'
278
845
  }
279
846
  });
280
- _context5.n = 1;
847
+ _context34.n = 1;
281
848
  return Promise.all([first, second]);
282
849
  case 1:
283
- return _context5.a(2);
850
+ return _context34.a(2);
284
851
  }
285
- }, _callee5);
852
+ }, _callee34);
286
853
  })));
287
854
  case 3:
288
855
  expect(context.cart.id).toBe(99);
289
856
  expect(context.fetchingCart).toBe(false);
290
857
  expect(setCartCookie).toHaveBeenCalledTimes(1);
291
858
  case 4:
292
- return _context6.a(2);
859
+ return _context35.a(2);
293
860
  }
294
- }, _callee6);
861
+ }, _callee35);
295
862
  })));
296
- it('shares an active saved-cart read and allows a later refresh', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
863
+ it('shares an active saved-cart read and allows a later refresh', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40() {
297
864
  var finish, saved, read;
298
- return _regenerator().w(function (_context1) {
299
- while (1) switch (_context1.n) {
865
+ return _regenerator().w(function (_context40) {
866
+ while (1) switch (_context40.n) {
300
867
  case 0:
301
868
  saved = {
302
869
  toJson: function toJson() {
@@ -314,116 +881,116 @@ describe('cart load and replacement failures', function () {
314
881
  finish = resolve;
315
882
  });
316
883
  }).mockResolvedValue(saved);
317
- _context1.n = 1;
318
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
319
- return _regenerator().w(function (_context7) {
320
- while (1) switch (_context7.n) {
884
+ _context40.n = 1;
885
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36() {
886
+ return _regenerator().w(function (_context36) {
887
+ while (1) switch (_context36.n) {
321
888
  case 0:
322
- return _context7.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
889
+ return _context36.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
323
890
  domainId: 5,
324
891
  createCartAndCookie: function createCartAndCookie() {},
325
892
  children: /*#__PURE__*/_jsx(Probe, {})
326
893
  })));
327
894
  }
328
- }, _callee7);
895
+ }, _callee36);
329
896
  })));
330
897
  case 1:
331
- _context1.n = 2;
332
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
333
- return _regenerator().w(function (_context8) {
334
- while (1) switch (_context8.n) {
898
+ _context40.n = 2;
899
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37() {
900
+ return _regenerator().w(function (_context37) {
901
+ while (1) switch (_context37.n) {
335
902
  case 0:
336
903
  context.toggleCartModal();
337
904
  read = window.getCart();
338
905
  case 1:
339
- return _context8.a(2);
906
+ return _context37.a(2);
340
907
  }
341
- }, _callee8);
908
+ }, _callee37);
342
909
  })));
343
910
  case 2:
344
911
  expect(mockGet).toHaveBeenCalledTimes(1);
345
- _context1.n = 3;
346
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
347
- return _regenerator().w(function (_context9) {
348
- while (1) switch (_context9.n) {
912
+ _context40.n = 3;
913
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38() {
914
+ return _regenerator().w(function (_context38) {
915
+ while (1) switch (_context38.n) {
349
916
  case 0:
350
917
  finish(saved);
351
- _context9.n = 1;
918
+ _context38.n = 1;
352
919
  return read;
353
920
  case 1:
354
- return _context9.a(2);
921
+ return _context38.a(2);
355
922
  }
356
- }, _callee9);
923
+ }, _callee38);
357
924
  })));
358
925
  case 3:
359
- _context1.n = 4;
360
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
361
- return _regenerator().w(function (_context0) {
362
- while (1) switch (_context0.n) {
926
+ _context40.n = 4;
927
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39() {
928
+ return _regenerator().w(function (_context39) {
929
+ while (1) switch (_context39.n) {
363
930
  case 0:
364
- _context0.n = 1;
931
+ _context39.n = 1;
365
932
  return window.getCart();
366
933
  case 1:
367
- return _context0.a(2);
934
+ return _context39.a(2);
368
935
  }
369
- }, _callee0);
936
+ }, _callee39);
370
937
  })));
371
938
  case 4:
372
939
  expect(mockGet).toHaveBeenCalledTimes(2);
373
940
  expect(mockPost).not.toHaveBeenCalled();
374
941
  expect(context.cart.cartItems).toHaveLength(1);
375
942
  case 5:
376
- return _context1.a(2);
943
+ return _context40.a(2);
377
944
  }
378
- }, _callee1);
945
+ }, _callee40);
379
946
  })));
380
- it('releases failed initialization so an explicit retry can create the cart', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
381
- return _regenerator().w(function (_context12) {
382
- while (1) switch (_context12.n) {
947
+ it('releases failed initialization so an explicit retry can create the cart', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43() {
948
+ return _regenerator().w(function (_context43) {
949
+ while (1) switch (_context43.n) {
383
950
  case 0:
384
951
  getCartCookie.mockResolvedValue(undefined);
385
952
  mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
386
- _context12.n = 1;
387
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
388
- return _regenerator().w(function (_context10) {
389
- while (1) switch (_context10.n) {
953
+ _context43.n = 1;
954
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41() {
955
+ return _regenerator().w(function (_context41) {
956
+ while (1) switch (_context41.n) {
390
957
  case 0:
391
- return _context10.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
958
+ return _context41.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
392
959
  domainId: 5,
393
960
  createCartAndCookie: function createCartAndCookie() {},
394
961
  children: /*#__PURE__*/_jsx(Probe, {})
395
962
  })));
396
963
  }
397
- }, _callee10);
964
+ }, _callee41);
398
965
  })));
399
966
  case 1:
400
967
  expect(mockPost).toHaveBeenCalledTimes(1);
401
968
  expect(context.fetchingCart).toBe(false);
402
- _context12.n = 2;
403
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
404
- return _regenerator().w(function (_context11) {
405
- while (1) switch (_context11.n) {
969
+ _context43.n = 2;
970
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42() {
971
+ return _regenerator().w(function (_context42) {
972
+ while (1) switch (_context42.n) {
406
973
  case 0:
407
- _context11.n = 1;
974
+ _context42.n = 1;
408
975
  return Promise.all([window.getCart(), window.getCart()]);
409
976
  case 1:
410
- return _context11.a(2);
977
+ return _context42.a(2);
411
978
  }
412
- }, _callee11);
979
+ }, _callee42);
413
980
  })));
414
981
  case 2:
415
982
  expect(mockPost).toHaveBeenCalledTimes(2);
416
983
  expect(context.cart.id).toBe(99);
417
984
  expect(context.fetchingCart).toBe(false);
418
985
  case 3:
419
- return _context12.a(2);
986
+ return _context43.a(2);
420
987
  }
421
- }, _callee12);
988
+ }, _callee43);
422
989
  })));
423
- it('initializes a changed domain independently of the previous pending domain', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
990
+ it('initializes a changed domain independently of the previous pending domain', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49() {
424
991
  var finish, view, current;
425
- return _regenerator().w(function (_context18) {
426
- while (1) switch (_context18.n) {
992
+ return _regenerator().w(function (_context49) {
993
+ while (1) switch (_context49.n) {
427
994
  case 0:
428
995
  finish = {};
429
996
  getCartCookie.mockImplementation(function (id) {
@@ -441,33 +1008,33 @@ describe('cart load and replacement failures', function () {
441
1008
  children: /*#__PURE__*/_jsx(Probe, {})
442
1009
  });
443
1010
  };
444
- _context18.n = 1;
445
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
446
- return _regenerator().w(function (_context13) {
447
- while (1) switch (_context13.n) {
1011
+ _context49.n = 1;
1012
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44() {
1013
+ return _regenerator().w(function (_context44) {
1014
+ while (1) switch (_context44.n) {
448
1015
  case 0:
449
- return _context13.a(2, root.render(view(5)));
1016
+ return _context44.a(2, root.render(view(5)));
450
1017
  }
451
- }, _callee13);
1018
+ }, _callee44);
452
1019
  })));
453
1020
  case 1:
454
- _context18.n = 2;
455
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
456
- return _regenerator().w(function (_context14) {
457
- while (1) switch (_context14.n) {
1021
+ _context49.n = 2;
1022
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45() {
1023
+ return _regenerator().w(function (_context45) {
1024
+ while (1) switch (_context45.n) {
458
1025
  case 0:
459
- return _context14.a(2, root.render(view(6)));
1026
+ return _context45.a(2, root.render(view(6)));
460
1027
  }
461
- }, _callee14);
1028
+ }, _callee45);
462
1029
  })));
463
1030
  case 2:
464
1031
  expect(mockGet).toHaveBeenCalledTimes(2);
465
- _context18.n = 3;
466
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
467
- return _regenerator().w(function (_context15) {
468
- while (1) switch (_context15.n) {
1032
+ _context49.n = 3;
1033
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46() {
1034
+ return _regenerator().w(function (_context46) {
1035
+ while (1) switch (_context46.n) {
469
1036
  case 0:
470
- return _context15.a(2, finish[5]({
1037
+ return _context46.a(2, finish[5]({
471
1038
  toJson: function toJson() {
472
1039
  return {
473
1040
  id: 5,
@@ -476,26 +1043,26 @@ describe('cart load and replacement failures', function () {
476
1043
  }
477
1044
  }));
478
1045
  }
479
- }, _callee15);
1046
+ }, _callee46);
480
1047
  })));
481
1048
  case 3:
482
- _context18.n = 4;
483
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
484
- return _regenerator().w(function (_context16) {
485
- while (1) switch (_context16.n) {
1049
+ _context49.n = 4;
1050
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47() {
1051
+ return _regenerator().w(function (_context47) {
1052
+ while (1) switch (_context47.n) {
486
1053
  case 0:
487
1054
  current = window.getCart();
488
1055
  case 1:
489
- return _context16.a(2);
1056
+ return _context47.a(2);
490
1057
  }
491
- }, _callee16);
1058
+ }, _callee47);
492
1059
  })));
493
1060
  case 4:
494
1061
  expect(mockGet).toHaveBeenCalledTimes(2);
495
- _context18.n = 5;
496
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
497
- return _regenerator().w(function (_context17) {
498
- while (1) switch (_context17.n) {
1062
+ _context49.n = 5;
1063
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48() {
1064
+ return _regenerator().w(function (_context48) {
1065
+ while (1) switch (_context48.n) {
499
1066
  case 0:
500
1067
  finish[6]({
501
1068
  toJson: function toJson() {
@@ -505,19 +1072,19 @@ describe('cart load and replacement failures', function () {
505
1072
  };
506
1073
  }
507
1074
  });
508
- _context17.n = 1;
1075
+ _context48.n = 1;
509
1076
  return current;
510
1077
  case 1:
511
- return _context17.a(2);
1078
+ return _context48.a(2);
512
1079
  }
513
- }, _callee17);
1080
+ }, _callee48);
514
1081
  })));
515
1082
  case 5:
516
1083
  expect(context.cart.id).toBe(6);
517
1084
  case 6:
518
- return _context18.a(2);
1085
+ return _context49.a(2);
519
1086
  }
520
- }, _callee18);
1087
+ }, _callee49);
521
1088
  })));
522
1089
  it.each([new TypeError('Load failed'), {
523
1090
  statusCode: 502,
@@ -526,11 +1093,11 @@ describe('cart load and replacement failures', function () {
526
1093
  statusCode: 403,
527
1094
  message: 'Forbidden'
528
1095
  }])('preserves the saved cart and never POSTs a replacement after %s', /*#__PURE__*/function () {
529
- var _ref19 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(error) {
530
- return _regenerator().w(function (_context19) {
531
- while (1) switch (_context19.n) {
1096
+ var _ref50 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(error) {
1097
+ return _regenerator().w(function (_context50) {
1098
+ while (1) switch (_context50.n) {
532
1099
  case 0:
533
- _context19.n = 1;
1100
+ _context50.n = 1;
534
1101
  return mount(error);
535
1102
  case 1:
536
1103
  expect(getCartCookie).toHaveBeenCalledWith(5);
@@ -546,20 +1113,20 @@ describe('cart load and replacement failures', function () {
546
1113
  expect(context.fetchingCart).toBe(false);
547
1114
  expect(reportCartFailure).toHaveBeenCalledWith(error, CART_FAILURE_SOURCES.load);
548
1115
  case 2:
549
- return _context19.a(2);
1116
+ return _context50.a(2);
550
1117
  }
551
- }, _callee19);
1118
+ }, _callee50);
552
1119
  }));
553
- return function (_x2) {
554
- return _ref19.apply(this, arguments);
1120
+ return function (_x3) {
1121
+ return _ref50.apply(this, arguments);
555
1122
  };
556
1123
  }());
557
1124
  it.each([404, 410])('replaces a genuinely missing cart after HTTP %s', /*#__PURE__*/function () {
558
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(statusCode) {
559
- return _regenerator().w(function (_context20) {
560
- while (1) switch (_context20.n) {
1125
+ var _ref51 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(statusCode) {
1126
+ return _regenerator().w(function (_context51) {
1127
+ while (1) switch (_context51.n) {
561
1128
  case 0:
562
- _context20.n = 1;
1129
+ _context51.n = 1;
563
1130
  return mount({
564
1131
  statusCode: statusCode
565
1132
  });
@@ -570,19 +1137,19 @@ describe('cart load and replacement failures', function () {
570
1137
  }));
571
1138
  expect(setCartCookie).toHaveBeenCalledTimes(1);
572
1139
  case 2:
573
- return _context20.a(2);
1140
+ return _context51.a(2);
574
1141
  }
575
- }, _callee20);
1142
+ }, _callee51);
576
1143
  }));
577
- return function (_x3) {
578
- return _ref20.apply(this, arguments);
1144
+ return function (_x4) {
1145
+ return _ref51.apply(this, arguments);
579
1146
  };
580
1147
  }());
581
- it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22() {
582
- return _regenerator().w(function (_context22) {
583
- while (1) switch (_context22.n) {
1148
+ it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53() {
1149
+ return _regenerator().w(function (_context53) {
1150
+ while (1) switch (_context53.n) {
584
1151
  case 0:
585
- _context22.n = 1;
1152
+ _context53.n = 1;
586
1153
  return mount(new TypeError('Load failed'));
587
1154
  case 1:
588
1155
  mockGet.mockResolvedValue({
@@ -596,50 +1163,50 @@ describe('cart load and replacement failures', function () {
596
1163
  };
597
1164
  }
598
1165
  });
599
- _context22.n = 2;
600
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21() {
601
- return _regenerator().w(function (_context21) {
602
- while (1) switch (_context21.n) {
1166
+ _context53.n = 2;
1167
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52() {
1168
+ return _regenerator().w(function (_context52) {
1169
+ while (1) switch (_context52.n) {
603
1170
  case 0:
604
- _context21.n = 1;
1171
+ _context52.n = 1;
605
1172
  return window.getCart();
606
1173
  case 1:
607
- return _context21.a(2);
1174
+ return _context52.a(2);
608
1175
  }
609
- }, _callee21);
1176
+ }, _callee52);
610
1177
  })));
611
1178
  case 2:
612
1179
  expect(context.cart.id).toBe(42);
613
1180
  expect(context.cart.cartItems).toHaveLength(1);
614
1181
  expect(mockPost).not.toHaveBeenCalled();
615
1182
  case 3:
616
- return _context22.a(2);
1183
+ return _context53.a(2);
617
1184
  }
618
- }, _callee22);
1185
+ }, _callee53);
619
1186
  })));
620
1187
  it.each([new TypeError('Failed to fetch'), {
621
1188
  statusCode: 503,
622
1189
  message: 'Service unavailable'
623
1190
  }, null, undefined])('keeps the clear-cart panel and saved cart when replacement fails with %s', /*#__PURE__*/function () {
624
- var _ref23 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(error) {
625
- return _regenerator().w(function (_context24) {
626
- while (1) switch (_context24.n) {
1191
+ var _ref54 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(error) {
1192
+ return _regenerator().w(function (_context55) {
1193
+ while (1) switch (_context55.n) {
627
1194
  case 0:
628
- _context24.n = 1;
1195
+ _context55.n = 1;
629
1196
  return mountSavedCart();
630
1197
  case 1:
631
1198
  mockPost.mockRejectedValueOnce(error);
632
- _context24.n = 2;
633
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23() {
634
- return _regenerator().w(function (_context23) {
635
- while (1) switch (_context23.n) {
1199
+ _context55.n = 2;
1200
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54() {
1201
+ return _regenerator().w(function (_context54) {
1202
+ while (1) switch (_context54.n) {
636
1203
  case 0:
637
- _context23.n = 1;
1204
+ _context54.n = 1;
638
1205
  return context.clearCart();
639
1206
  case 1:
640
- return _context23.a(2);
1207
+ return _context54.a(2);
641
1208
  }
642
- }, _callee23);
1209
+ }, _callee54);
643
1210
  })));
644
1211
  case 2:
645
1212
  expect(context.activeTabIndex).toBe(tabIdClearCart);
@@ -657,47 +1224,47 @@ describe('cart load and replacement failures', function () {
657
1224
  expect(context.alert.message).toBe((error === null || error === void 0 ? void 0 : error.message) || 'Unable to fetch cart.');
658
1225
  expect(context.fetchingCart).toBe(false);
659
1226
  case 3:
660
- return _context24.a(2);
1227
+ return _context55.a(2);
661
1228
  }
662
- }, _callee24);
1229
+ }, _callee55);
663
1230
  }));
664
- return function (_x4) {
665
- return _ref23.apply(this, arguments);
1231
+ return function (_x5) {
1232
+ return _ref54.apply(this, arguments);
666
1233
  };
667
1234
  }());
668
- it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27() {
669
- return _regenerator().w(function (_context27) {
670
- while (1) switch (_context27.n) {
1235
+ it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58() {
1236
+ return _regenerator().w(function (_context58) {
1237
+ while (1) switch (_context58.n) {
671
1238
  case 0:
672
- _context27.n = 1;
1239
+ _context58.n = 1;
673
1240
  return mountSavedCart();
674
1241
  case 1:
675
1242
  mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
676
- _context27.n = 2;
677
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25() {
678
- return _regenerator().w(function (_context25) {
679
- while (1) switch (_context25.n) {
1243
+ _context58.n = 2;
1244
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56() {
1245
+ return _regenerator().w(function (_context56) {
1246
+ while (1) switch (_context56.n) {
680
1247
  case 0:
681
- _context25.n = 1;
1248
+ _context56.n = 1;
682
1249
  return context.clearCart();
683
1250
  case 1:
684
- return _context25.a(2);
1251
+ return _context56.a(2);
685
1252
  }
686
- }, _callee25);
1253
+ }, _callee56);
687
1254
  })));
688
1255
  case 2:
689
1256
  expect(context.activeTabIndex).toBe(tabIdClearCart);
690
- _context27.n = 3;
691
- return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26() {
692
- return _regenerator().w(function (_context26) {
693
- while (1) switch (_context26.n) {
1257
+ _context58.n = 3;
1258
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57() {
1259
+ return _regenerator().w(function (_context57) {
1260
+ while (1) switch (_context57.n) {
694
1261
  case 0:
695
- _context26.n = 1;
1262
+ _context57.n = 1;
696
1263
  return context.clearCart();
697
1264
  case 1:
698
- return _context26.a(2);
1265
+ return _context57.a(2);
699
1266
  }
700
- }, _callee26);
1267
+ }, _callee57);
701
1268
  })));
702
1269
  case 3:
703
1270
  expect(mockPost).toHaveBeenCalledTimes(2);
@@ -707,8 +1274,8 @@ describe('cart load and replacement failures', function () {
707
1274
  expect(context.alert.show).toBe(false);
708
1275
  expect(context.fetchingCart).toBe(false);
709
1276
  case 4:
710
- return _context27.a(2);
1277
+ return _context58.a(2);
711
1278
  }
712
- }, _callee27);
1279
+ }, _callee58);
713
1280
  })));
714
1281
  });