@merchi/cart 1.4.84 → 1.4.86
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.
- package/esm/CartProvider.js +80 -49
- package/esm/CartProvider.load.test.js +418 -71
- package/esm/forms/FormShipmentAddressAndNotes.js +51 -20
- package/esm/panels/PanelPaymentSuccess.js +22 -15
- package/esm/panels/PanelPaymentSuccess.test.js +68 -0
- package/esm/utilities/checkoutCartClient.js +32 -0
- package/esm/utilities/test_checkout.js +2 -18
- package/lib/CartProvider.js +80 -49
- package/lib/forms/FormShipmentAddressAndNotes.js +51 -20
- package/lib/panels/PanelPaymentSuccess.js +22 -14
- package/lib/utilities/checkoutCartClient.d.ts +5 -0
- package/lib/utilities/checkoutCartClient.js +38 -0
- package/lib/utilities/test_checkout.d.ts +1 -4
- package/lib/utilities/test_checkout.js +25 -20
- package/package.json +2 -2
- package/src/CartProvider.load.test.tsx +110 -7
- package/src/CartProvider.tsx +34 -23
- package/src/forms/FormShipmentAddressAndNotes.tsx +21 -6
- package/src/panels/PanelPaymentSuccess.test.tsx +36 -0
- package/src/panels/PanelPaymentSuccess.tsx +20 -12
- package/src/utilities/checkoutCartClient.ts +16 -0
- package/src/utilities/test_checkout.ts +2 -19
|
@@ -12,7 +12,8 @@ import * as React from 'react';
|
|
|
12
12
|
import { createRoot } from 'react-dom/client';
|
|
13
13
|
import { act } from 'react-dom/test-utils';
|
|
14
14
|
import CartProvider, { useCartContext } from './CartProvider';
|
|
15
|
-
import {
|
|
15
|
+
import { ActiveFormShipmentAddressAndNotes } from './forms/FormShipmentAddressAndNotes';
|
|
16
|
+
import { getCartCookie, getCartCookieToken, setCartCookie } from './utilities/cookie';
|
|
16
17
|
import { cartNeedsSourceUpdate } from './utilities/job_source';
|
|
17
18
|
import { reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
|
|
18
19
|
import { tabIdClearCart, tabIdItems } from './utilities/tabs';
|
|
@@ -20,22 +21,43 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
20
21
|
var mockGet = jest.fn();
|
|
21
22
|
var mockPost = jest.fn();
|
|
22
23
|
var mockCreateItem = jest.fn();
|
|
24
|
+
var mockSaveCart = jest.fn();
|
|
25
|
+
var mockShipmentQuotes = jest.fn();
|
|
23
26
|
jest.mock('@merchi/sdk', function () {
|
|
24
27
|
return {
|
|
25
|
-
Merchi: jest.fn().mockImplementation(function () {
|
|
28
|
+
Merchi: jest.fn().mockImplementation(function (_session, _client, _invoice, cartToken) {
|
|
26
29
|
return {
|
|
27
|
-
Cart: {
|
|
30
|
+
Cart: Object.assign(jest.fn(function () {
|
|
31
|
+
return {
|
|
32
|
+
fromJson: function fromJson(cart) {
|
|
33
|
+
return {
|
|
34
|
+
save: function save() {
|
|
35
|
+
return mockSaveCart(cart.id, cartToken);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}), {
|
|
28
41
|
get: function get() {
|
|
29
42
|
return mockGet.apply(void 0, arguments);
|
|
30
43
|
}
|
|
31
|
-
},
|
|
44
|
+
}),
|
|
32
45
|
authenticatedFetch: function authenticatedFetch() {
|
|
33
|
-
|
|
46
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
47
|
+
args[_key] = arguments[_key];
|
|
48
|
+
}
|
|
49
|
+
return cartToken ? mockShipmentQuotes.apply(void 0, [cartToken].concat(args)) : mockPost.apply(void 0, args);
|
|
34
50
|
}
|
|
35
51
|
};
|
|
36
52
|
})
|
|
37
53
|
};
|
|
38
54
|
});
|
|
55
|
+
jest.mock('./utilities/address', function () {
|
|
56
|
+
return {
|
|
57
|
+
makeAddress: jest.fn(),
|
|
58
|
+
sanitizeAddressFields: jest.fn()
|
|
59
|
+
};
|
|
60
|
+
});
|
|
39
61
|
jest.mock('./utilities/product', function () {
|
|
40
62
|
return {
|
|
41
63
|
makeProduct: jest.fn(function (json) {
|
|
@@ -52,8 +74,11 @@ jest.mock('./utilities/job', function () {
|
|
|
52
74
|
});
|
|
53
75
|
jest.mock('./utilities/cart', function () {
|
|
54
76
|
return {
|
|
55
|
-
makeCart: function makeCart(json) {
|
|
77
|
+
makeCart: function makeCart(json, _makeDirty, cartToken) {
|
|
56
78
|
return _objectSpread(_objectSpread({}, json), {}, {
|
|
79
|
+
save: function save() {
|
|
80
|
+
return mockSaveCart(json.id, cartToken);
|
|
81
|
+
},
|
|
57
82
|
toFormData: function toFormData() {
|
|
58
83
|
return new FormData();
|
|
59
84
|
},
|
|
@@ -86,9 +111,25 @@ jest.mock('./utilities/cookie', function () {
|
|
|
86
111
|
};
|
|
87
112
|
});
|
|
88
113
|
jest.mock('./utilities/local_storage', function () {
|
|
89
|
-
return {
|
|
114
|
+
return _objectSpread(_objectSpread({}, jest.requireActual('./utilities/local_storage')), {}, {
|
|
90
115
|
getSavedCheckoutCustomer: function getSavedCheckoutCustomer() {
|
|
91
116
|
return null;
|
|
117
|
+
},
|
|
118
|
+
saveCheckoutAddress: jest.fn()
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
jest.mock('./forms/InputsAddress', function () {
|
|
122
|
+
return {
|
|
123
|
+
__esModule: true,
|
|
124
|
+
"default": function _default() {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
jest.mock('./components', function () {
|
|
130
|
+
return {
|
|
131
|
+
Title: function Title() {
|
|
132
|
+
return null;
|
|
92
133
|
}
|
|
93
134
|
};
|
|
94
135
|
});
|
|
@@ -116,7 +157,8 @@ jest.mock('./utilities/reportFailure', function () {
|
|
|
116
157
|
}),
|
|
117
158
|
CART_FAILURE_SOURCES: {
|
|
118
159
|
load: 'cart.load',
|
|
119
|
-
create: 'cart.create'
|
|
160
|
+
create: 'cart.create',
|
|
161
|
+
update: 'cart.update'
|
|
120
162
|
}
|
|
121
163
|
};
|
|
122
164
|
});
|
|
@@ -198,15 +240,15 @@ describe('cart load and replacement failures', function () {
|
|
|
198
240
|
return _mount.apply(this, arguments);
|
|
199
241
|
}
|
|
200
242
|
function _mount() {
|
|
201
|
-
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
202
|
-
return _regenerator().w(function (
|
|
203
|
-
while (1) switch (
|
|
243
|
+
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(error) {
|
|
244
|
+
return _regenerator().w(function (_context100) {
|
|
245
|
+
while (1) switch (_context100.n) {
|
|
204
246
|
case 0:
|
|
205
247
|
mockGet.mockRejectedValue(error);
|
|
206
|
-
|
|
207
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
208
|
-
return _regenerator().w(function (
|
|
209
|
-
while (1) switch (
|
|
248
|
+
_context100.n = 1;
|
|
249
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98() {
|
|
250
|
+
return _regenerator().w(function (_context99) {
|
|
251
|
+
while (1) switch (_context99.n) {
|
|
210
252
|
case 0:
|
|
211
253
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
212
254
|
domainId: 5,
|
|
@@ -220,14 +262,14 @@ describe('cart load and replacement failures', function () {
|
|
|
220
262
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
221
263
|
}));
|
|
222
264
|
case 1:
|
|
223
|
-
return
|
|
265
|
+
return _context99.a(2);
|
|
224
266
|
}
|
|
225
|
-
},
|
|
267
|
+
}, _callee98);
|
|
226
268
|
})));
|
|
227
269
|
case 1:
|
|
228
|
-
return
|
|
270
|
+
return _context100.a(2);
|
|
229
271
|
}
|
|
230
|
-
},
|
|
272
|
+
}, _callee99);
|
|
231
273
|
}));
|
|
232
274
|
return _mount.apply(this, arguments);
|
|
233
275
|
}
|
|
@@ -235,9 +277,9 @@ describe('cart load and replacement failures', function () {
|
|
|
235
277
|
return _mountSavedCart.apply(this, arguments);
|
|
236
278
|
}
|
|
237
279
|
function _mountSavedCart() {
|
|
238
|
-
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
239
|
-
return _regenerator().w(function (
|
|
240
|
-
while (1) switch (
|
|
280
|
+
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102() {
|
|
281
|
+
return _regenerator().w(function (_context103) {
|
|
282
|
+
while (1) switch (_context103.n) {
|
|
241
283
|
case 0:
|
|
242
284
|
mockGet.mockResolvedValue({
|
|
243
285
|
toJson: function toJson() {
|
|
@@ -250,10 +292,10 @@ describe('cart load and replacement failures', function () {
|
|
|
250
292
|
};
|
|
251
293
|
}
|
|
252
294
|
});
|
|
253
|
-
|
|
254
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
255
|
-
return _regenerator().w(function (
|
|
256
|
-
while (1) switch (
|
|
295
|
+
_context103.n = 1;
|
|
296
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100() {
|
|
297
|
+
return _regenerator().w(function (_context101) {
|
|
298
|
+
while (1) switch (_context101.n) {
|
|
257
299
|
case 0:
|
|
258
300
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
259
301
|
domainId: 5,
|
|
@@ -261,24 +303,24 @@ describe('cart load and replacement failures', function () {
|
|
|
261
303
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
262
304
|
}));
|
|
263
305
|
case 1:
|
|
264
|
-
return
|
|
306
|
+
return _context101.a(2);
|
|
265
307
|
}
|
|
266
|
-
},
|
|
308
|
+
}, _callee100);
|
|
267
309
|
})));
|
|
268
310
|
case 1:
|
|
269
|
-
|
|
270
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
271
|
-
return _regenerator().w(function (
|
|
272
|
-
while (1) switch (
|
|
311
|
+
_context103.n = 2;
|
|
312
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101() {
|
|
313
|
+
return _regenerator().w(function (_context102) {
|
|
314
|
+
while (1) switch (_context102.n) {
|
|
273
315
|
case 0:
|
|
274
|
-
return
|
|
316
|
+
return _context102.a(2, context.setActiveTabIndex(tabIdClearCart));
|
|
275
317
|
}
|
|
276
|
-
},
|
|
318
|
+
}, _callee101);
|
|
277
319
|
})));
|
|
278
320
|
case 2:
|
|
279
|
-
return
|
|
321
|
+
return _context103.a(2);
|
|
280
322
|
}
|
|
281
|
-
},
|
|
323
|
+
}, _callee102);
|
|
282
324
|
}));
|
|
283
325
|
return _mountSavedCart.apply(this, arguments);
|
|
284
326
|
}
|
|
@@ -1677,29 +1719,334 @@ describe('cart load and replacement failures', function () {
|
|
|
1677
1719
|
}
|
|
1678
1720
|
}, _callee79);
|
|
1679
1721
|
})));
|
|
1722
|
+
it('updates the displayed cart when another tab has replaced the cart cookie', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82() {
|
|
1723
|
+
return _regenerator().w(function (_context82) {
|
|
1724
|
+
while (1) switch (_context82.n) {
|
|
1725
|
+
case 0:
|
|
1726
|
+
mockGet.mockResolvedValue({
|
|
1727
|
+
toJson: function toJson() {
|
|
1728
|
+
return {
|
|
1729
|
+
id: 42,
|
|
1730
|
+
token: 'visible-token',
|
|
1731
|
+
cartItems: [{
|
|
1732
|
+
id: 7
|
|
1733
|
+
}]
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
_context82.n = 1;
|
|
1738
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80() {
|
|
1739
|
+
return _regenerator().w(function (_context80) {
|
|
1740
|
+
while (1) switch (_context80.n) {
|
|
1741
|
+
case 0:
|
|
1742
|
+
return _context80.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
1743
|
+
domainId: 5,
|
|
1744
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
1745
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
1746
|
+
})));
|
|
1747
|
+
}
|
|
1748
|
+
}, _callee80);
|
|
1749
|
+
})));
|
|
1750
|
+
case 1:
|
|
1751
|
+
getCartCookie.mockResolvedValue(['99', 'new-token']);
|
|
1752
|
+
getCartCookieToken.mockResolvedValue('new-token');
|
|
1753
|
+
mockSaveCart.mockImplementation(function (id, token) {
|
|
1754
|
+
return token === 'visible-token' ? Promise.resolve({
|
|
1755
|
+
toJson: function toJson() {
|
|
1756
|
+
return {
|
|
1757
|
+
id: id,
|
|
1758
|
+
token: token,
|
|
1759
|
+
receiverAddress: {
|
|
1760
|
+
city: 'Melbourne'
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
}) : Promise.reject(Object.assign(new Error('Authentication required'), {
|
|
1765
|
+
statusCode: 401
|
|
1766
|
+
}));
|
|
1767
|
+
});
|
|
1768
|
+
mockShipmentQuotes.mockResolvedValue({
|
|
1769
|
+
shipmentGroups: [{
|
|
1770
|
+
id: 1
|
|
1771
|
+
}]
|
|
1772
|
+
});
|
|
1773
|
+
_context82.n = 2;
|
|
1774
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81() {
|
|
1775
|
+
return _regenerator().w(function (_context81) {
|
|
1776
|
+
while (1) switch (_context81.n) {
|
|
1777
|
+
case 0:
|
|
1778
|
+
_context81.n = 1;
|
|
1779
|
+
return context.updateCartShipmentAddress({
|
|
1780
|
+
city: 'Melbourne'
|
|
1781
|
+
});
|
|
1782
|
+
case 1:
|
|
1783
|
+
return _context81.a(2);
|
|
1784
|
+
}
|
|
1785
|
+
}, _callee81);
|
|
1786
|
+
})));
|
|
1787
|
+
case 2:
|
|
1788
|
+
expect(mockSaveCart).toHaveBeenCalledWith(42, 'visible-token');
|
|
1789
|
+
expect(mockShipmentQuotes).toHaveBeenCalledWith('visible-token', '/generate-cart-shipment-quotes/42/', {
|
|
1790
|
+
method: 'GET'
|
|
1791
|
+
});
|
|
1792
|
+
expect(context.cart).toMatchObject({
|
|
1793
|
+
id: 42,
|
|
1794
|
+
receiverAddress: {
|
|
1795
|
+
city: 'Melbourne'
|
|
1796
|
+
},
|
|
1797
|
+
shipmentGroups: [{
|
|
1798
|
+
id: 1
|
|
1799
|
+
}]
|
|
1800
|
+
});
|
|
1801
|
+
expect(reportCartFailure).not.toHaveBeenCalled();
|
|
1802
|
+
case 3:
|
|
1803
|
+
return _context82.a(2);
|
|
1804
|
+
}
|
|
1805
|
+
}, _callee82);
|
|
1806
|
+
})));
|
|
1807
|
+
it('uses the matching checkout cookie when the cart response has no token', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84() {
|
|
1808
|
+
return _regenerator().w(function (_context84) {
|
|
1809
|
+
while (1) switch (_context84.n) {
|
|
1810
|
+
case 0:
|
|
1811
|
+
_context84.n = 1;
|
|
1812
|
+
return mountSavedCart();
|
|
1813
|
+
case 1:
|
|
1814
|
+
mockSaveCart.mockResolvedValue({
|
|
1815
|
+
toJson: function toJson() {
|
|
1816
|
+
return {
|
|
1817
|
+
id: 42
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
mockShipmentQuotes.mockResolvedValue({
|
|
1822
|
+
shipmentGroups: []
|
|
1823
|
+
});
|
|
1824
|
+
_context84.n = 2;
|
|
1825
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83() {
|
|
1826
|
+
return _regenerator().w(function (_context83) {
|
|
1827
|
+
while (1) switch (_context83.n) {
|
|
1828
|
+
case 0:
|
|
1829
|
+
_context83.n = 1;
|
|
1830
|
+
return context.updateCartShipmentAddress({
|
|
1831
|
+
city: 'Melbourne'
|
|
1832
|
+
});
|
|
1833
|
+
case 1:
|
|
1834
|
+
return _context83.a(2);
|
|
1835
|
+
}
|
|
1836
|
+
}, _callee83);
|
|
1837
|
+
})));
|
|
1838
|
+
case 2:
|
|
1839
|
+
expect(mockSaveCart).toHaveBeenCalledWith(42, 'saved-token');
|
|
1840
|
+
expect(mockShipmentQuotes).toHaveBeenCalledWith('saved-token', '/generate-cart-shipment-quotes/42/', {
|
|
1841
|
+
method: 'GET'
|
|
1842
|
+
});
|
|
1843
|
+
case 3:
|
|
1844
|
+
return _context84.a(2);
|
|
1845
|
+
}
|
|
1846
|
+
}, _callee84);
|
|
1847
|
+
})));
|
|
1848
|
+
it('refreshes shipment options with the displayed cart token when the cookie changes', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87() {
|
|
1849
|
+
return _regenerator().w(function (_context88) {
|
|
1850
|
+
while (1) switch (_context88.n) {
|
|
1851
|
+
case 0:
|
|
1852
|
+
mockGet.mockResolvedValue({
|
|
1853
|
+
toJson: function toJson() {
|
|
1854
|
+
return {
|
|
1855
|
+
id: 42,
|
|
1856
|
+
token: 'visible-token',
|
|
1857
|
+
cartItems: [{
|
|
1858
|
+
id: 7
|
|
1859
|
+
}]
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
_context88.n = 1;
|
|
1864
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85() {
|
|
1865
|
+
return _regenerator().w(function (_context85) {
|
|
1866
|
+
while (1) switch (_context85.n) {
|
|
1867
|
+
case 0:
|
|
1868
|
+
return _context85.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
1869
|
+
domainId: 5,
|
|
1870
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
1871
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
1872
|
+
})));
|
|
1873
|
+
}
|
|
1874
|
+
}, _callee85);
|
|
1875
|
+
})));
|
|
1876
|
+
case 1:
|
|
1877
|
+
getCartCookie.mockResolvedValue(['99', 'new-token']);
|
|
1878
|
+
mockShipmentQuotes.mockResolvedValue({
|
|
1879
|
+
shipmentGroups: [{
|
|
1880
|
+
id: 1
|
|
1881
|
+
}]
|
|
1882
|
+
});
|
|
1883
|
+
_context88.n = 2;
|
|
1884
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86() {
|
|
1885
|
+
var _context$getCartShipm, _context86;
|
|
1886
|
+
return _regenerator().w(function (_context87) {
|
|
1887
|
+
while (1) switch (_context87.n) {
|
|
1888
|
+
case 0:
|
|
1889
|
+
_context87.n = 1;
|
|
1890
|
+
return (_context$getCartShipm = (_context86 = context).getCartShipmentOptions) === null || _context$getCartShipm === void 0 ? void 0 : _context$getCartShipm.call(_context86);
|
|
1891
|
+
case 1:
|
|
1892
|
+
return _context87.a(2);
|
|
1893
|
+
}
|
|
1894
|
+
}, _callee86);
|
|
1895
|
+
})));
|
|
1896
|
+
case 2:
|
|
1897
|
+
expect(mockShipmentQuotes).toHaveBeenCalledWith('visible-token', '/generate-cart-shipment-quotes/42/', {
|
|
1898
|
+
method: 'GET'
|
|
1899
|
+
});
|
|
1900
|
+
expect(context.cart).toMatchObject({
|
|
1901
|
+
id: 42,
|
|
1902
|
+
cartItems: [{
|
|
1903
|
+
id: 7
|
|
1904
|
+
}],
|
|
1905
|
+
shipmentGroups: [{
|
|
1906
|
+
id: 1
|
|
1907
|
+
}]
|
|
1908
|
+
});
|
|
1909
|
+
case 3:
|
|
1910
|
+
return _context88.a(2);
|
|
1911
|
+
}
|
|
1912
|
+
}, _callee87);
|
|
1913
|
+
})));
|
|
1914
|
+
it('keeps the cart intact when only a different cart’s token is available', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89() {
|
|
1915
|
+
return _regenerator().w(function (_context90) {
|
|
1916
|
+
while (1) switch (_context90.n) {
|
|
1917
|
+
case 0:
|
|
1918
|
+
_context90.n = 1;
|
|
1919
|
+
return mountSavedCart();
|
|
1920
|
+
case 1:
|
|
1921
|
+
getCartCookie.mockResolvedValue(['99', 'new-token']);
|
|
1922
|
+
getCartCookieToken.mockResolvedValue('new-token');
|
|
1923
|
+
mockSaveCart.mockRejectedValue(Object.assign(new Error('Authentication required'), {
|
|
1924
|
+
statusCode: 401
|
|
1925
|
+
}));
|
|
1926
|
+
_context90.n = 2;
|
|
1927
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88() {
|
|
1928
|
+
return _regenerator().w(function (_context89) {
|
|
1929
|
+
while (1) switch (_context89.n) {
|
|
1930
|
+
case 0:
|
|
1931
|
+
_context89.n = 1;
|
|
1932
|
+
return context.updateCartShipmentAddress({
|
|
1933
|
+
city: 'Melbourne'
|
|
1934
|
+
});
|
|
1935
|
+
case 1:
|
|
1936
|
+
return _context89.a(2);
|
|
1937
|
+
}
|
|
1938
|
+
}, _callee88);
|
|
1939
|
+
})));
|
|
1940
|
+
case 2:
|
|
1941
|
+
expect(mockSaveCart).not.toHaveBeenCalled();
|
|
1942
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
1943
|
+
expect(mockShipmentQuotes).not.toHaveBeenCalled();
|
|
1944
|
+
expect(context.cart.id).toBe(42);
|
|
1945
|
+
expect(context.alert.message).toContain('Reload checkout');
|
|
1946
|
+
case 3:
|
|
1947
|
+
return _context90.a(2);
|
|
1948
|
+
}
|
|
1949
|
+
}, _callee89);
|
|
1950
|
+
})));
|
|
1951
|
+
it.each(['visible-token', undefined])('submits the displayed checkout cart after another tab replaces its cookie (%s)', /*#__PURE__*/function () {
|
|
1952
|
+
var _ref90 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(token) {
|
|
1953
|
+
var form;
|
|
1954
|
+
return _regenerator().w(function (_context93) {
|
|
1955
|
+
while (1) switch (_context93.n) {
|
|
1956
|
+
case 0:
|
|
1957
|
+
mockGet.mockResolvedValue({
|
|
1958
|
+
toJson: function toJson() {
|
|
1959
|
+
return {
|
|
1960
|
+
id: 42,
|
|
1961
|
+
token: token,
|
|
1962
|
+
cartItems: [{
|
|
1963
|
+
id: 7
|
|
1964
|
+
}]
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
_context93.n = 1;
|
|
1969
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90() {
|
|
1970
|
+
return _regenerator().w(function (_context91) {
|
|
1971
|
+
while (1) switch (_context91.n) {
|
|
1972
|
+
case 0:
|
|
1973
|
+
return _context91.a(2, root.render(/*#__PURE__*/_jsxs(CartProvider, {
|
|
1974
|
+
domainId: 5,
|
|
1975
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
1976
|
+
children: [/*#__PURE__*/_jsx(Probe, {}), /*#__PURE__*/_jsx(ActiveFormShipmentAddressAndNotes, {})]
|
|
1977
|
+
})));
|
|
1978
|
+
}
|
|
1979
|
+
}, _callee90);
|
|
1980
|
+
})));
|
|
1981
|
+
case 1:
|
|
1982
|
+
getCartCookie.mockResolvedValue(['99', 'new-token']);
|
|
1983
|
+
getCartCookieToken.mockResolvedValue('new-token');
|
|
1984
|
+
mockSaveCart.mockImplementation(function (id, cartToken) {
|
|
1985
|
+
return cartToken === 'visible-token' ? Promise.resolve({
|
|
1986
|
+
toJson: function toJson() {
|
|
1987
|
+
return {
|
|
1988
|
+
id: id,
|
|
1989
|
+
token: cartToken
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
}) : Promise.reject(Object.assign(new Error('Authentication required'), {
|
|
1993
|
+
statusCode: 401
|
|
1994
|
+
}));
|
|
1995
|
+
});
|
|
1996
|
+
form = container.querySelector('form');
|
|
1997
|
+
_context93.n = 2;
|
|
1998
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91() {
|
|
1999
|
+
return _regenerator().w(function (_context92) {
|
|
2000
|
+
while (1) switch (_context92.n) {
|
|
2001
|
+
case 0:
|
|
2002
|
+
return _context92.a(2, form.dispatchEvent(new Event('submit', {
|
|
2003
|
+
bubbles: true,
|
|
2004
|
+
cancelable: true
|
|
2005
|
+
})));
|
|
2006
|
+
}
|
|
2007
|
+
}, _callee91);
|
|
2008
|
+
})));
|
|
2009
|
+
case 2:
|
|
2010
|
+
if (token) {
|
|
2011
|
+
expect(mockSaveCart).toHaveBeenCalledTimes(1);
|
|
2012
|
+
expect(mockSaveCart).toHaveBeenCalledWith(42, token);
|
|
2013
|
+
} else {
|
|
2014
|
+
expect(mockSaveCart).not.toHaveBeenCalled();
|
|
2015
|
+
expect(context.alert.message).toContain('Reload checkout');
|
|
2016
|
+
}
|
|
2017
|
+
expect(context.cart.id).toBe(42);
|
|
2018
|
+
case 3:
|
|
2019
|
+
return _context93.a(2);
|
|
2020
|
+
}
|
|
2021
|
+
}, _callee92);
|
|
2022
|
+
}));
|
|
2023
|
+
return function (_x5) {
|
|
2024
|
+
return _ref90.apply(this, arguments);
|
|
2025
|
+
};
|
|
2026
|
+
}());
|
|
1680
2027
|
it.each([new TypeError('Failed to fetch'), {
|
|
1681
2028
|
statusCode: 503,
|
|
1682
2029
|
message: 'Service unavailable'
|
|
1683
2030
|
}, null, undefined])('keeps the clear-cart panel and saved cart when replacement fails with %s', /*#__PURE__*/function () {
|
|
1684
|
-
var
|
|
1685
|
-
return _regenerator().w(function (
|
|
1686
|
-
while (1) switch (
|
|
2031
|
+
var _ref93 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(error) {
|
|
2032
|
+
return _regenerator().w(function (_context95) {
|
|
2033
|
+
while (1) switch (_context95.n) {
|
|
1687
2034
|
case 0:
|
|
1688
|
-
|
|
2035
|
+
_context95.n = 1;
|
|
1689
2036
|
return mountSavedCart();
|
|
1690
2037
|
case 1:
|
|
1691
2038
|
mockPost.mockRejectedValueOnce(error);
|
|
1692
|
-
|
|
1693
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1694
|
-
return _regenerator().w(function (
|
|
1695
|
-
while (1) switch (
|
|
2039
|
+
_context95.n = 2;
|
|
2040
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93() {
|
|
2041
|
+
return _regenerator().w(function (_context94) {
|
|
2042
|
+
while (1) switch (_context94.n) {
|
|
1696
2043
|
case 0:
|
|
1697
|
-
|
|
2044
|
+
_context94.n = 1;
|
|
1698
2045
|
return context.clearCart();
|
|
1699
2046
|
case 1:
|
|
1700
|
-
return
|
|
2047
|
+
return _context94.a(2);
|
|
1701
2048
|
}
|
|
1702
|
-
},
|
|
2049
|
+
}, _callee93);
|
|
1703
2050
|
})));
|
|
1704
2051
|
case 2:
|
|
1705
2052
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
@@ -1717,47 +2064,47 @@ describe('cart load and replacement failures', function () {
|
|
|
1717
2064
|
expect(context.alert.message).toBe((error === null || error === void 0 ? void 0 : error.message) || 'Unable to fetch cart.');
|
|
1718
2065
|
expect(context.fetchingCart).toBe(false);
|
|
1719
2066
|
case 3:
|
|
1720
|
-
return
|
|
2067
|
+
return _context95.a(2);
|
|
1721
2068
|
}
|
|
1722
|
-
},
|
|
2069
|
+
}, _callee94);
|
|
1723
2070
|
}));
|
|
1724
|
-
return function (
|
|
1725
|
-
return
|
|
2071
|
+
return function (_x6) {
|
|
2072
|
+
return _ref93.apply(this, arguments);
|
|
1726
2073
|
};
|
|
1727
2074
|
}());
|
|
1728
|
-
it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1729
|
-
return _regenerator().w(function (
|
|
1730
|
-
while (1) switch (
|
|
2075
|
+
it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97() {
|
|
2076
|
+
return _regenerator().w(function (_context98) {
|
|
2077
|
+
while (1) switch (_context98.n) {
|
|
1731
2078
|
case 0:
|
|
1732
|
-
|
|
2079
|
+
_context98.n = 1;
|
|
1733
2080
|
return mountSavedCart();
|
|
1734
2081
|
case 1:
|
|
1735
2082
|
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
1736
|
-
|
|
1737
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1738
|
-
return _regenerator().w(function (
|
|
1739
|
-
while (1) switch (
|
|
2083
|
+
_context98.n = 2;
|
|
2084
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95() {
|
|
2085
|
+
return _regenerator().w(function (_context96) {
|
|
2086
|
+
while (1) switch (_context96.n) {
|
|
1740
2087
|
case 0:
|
|
1741
|
-
|
|
2088
|
+
_context96.n = 1;
|
|
1742
2089
|
return context.clearCart();
|
|
1743
2090
|
case 1:
|
|
1744
|
-
return
|
|
2091
|
+
return _context96.a(2);
|
|
1745
2092
|
}
|
|
1746
|
-
},
|
|
2093
|
+
}, _callee95);
|
|
1747
2094
|
})));
|
|
1748
2095
|
case 2:
|
|
1749
2096
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
1750
|
-
|
|
1751
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1752
|
-
return _regenerator().w(function (
|
|
1753
|
-
while (1) switch (
|
|
2097
|
+
_context98.n = 3;
|
|
2098
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96() {
|
|
2099
|
+
return _regenerator().w(function (_context97) {
|
|
2100
|
+
while (1) switch (_context97.n) {
|
|
1754
2101
|
case 0:
|
|
1755
|
-
|
|
2102
|
+
_context97.n = 1;
|
|
1756
2103
|
return context.clearCart();
|
|
1757
2104
|
case 1:
|
|
1758
|
-
return
|
|
2105
|
+
return _context97.a(2);
|
|
1759
2106
|
}
|
|
1760
|
-
},
|
|
2107
|
+
}, _callee96);
|
|
1761
2108
|
})));
|
|
1762
2109
|
case 3:
|
|
1763
2110
|
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
@@ -1767,8 +2114,8 @@ describe('cart load and replacement failures', function () {
|
|
|
1767
2114
|
expect(context.alert.show).toBe(false);
|
|
1768
2115
|
expect(context.fetchingCart).toBe(false);
|
|
1769
2116
|
case 4:
|
|
1770
|
-
return
|
|
2117
|
+
return _context98.a(2);
|
|
1771
2118
|
}
|
|
1772
|
-
},
|
|
2119
|
+
}, _callee97);
|
|
1773
2120
|
})));
|
|
1774
2121
|
});
|