@reactionary/examples-node 0.1.13 → 0.2.1
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/package.json +4 -5
- package/src/basic/basic-node-setup.spec.ts +6 -2
- package/src/capabilities/cart.spec.ts +109 -65
- package/src/capabilities/category.spec.ts +80 -45
- package/src/capabilities/checkout.spec.ts +237 -168
- package/src/capabilities/identity.spec.ts +36 -10
- package/src/capabilities/inventory.spec.ts +20 -20
- package/src/capabilities/price.spec.ts +45 -35
- package/src/capabilities/product-search.spec.ts +82 -29
- package/src/capabilities/product.spec.ts +90 -76
- package/src/capabilities/profile.spec.ts +6 -3
- package/src/capabilities/store.spec.ts +6 -2
- package/src/utils.ts +0 -10
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
PaymentInstructionSchema,
|
|
5
5
|
ShippingInstructionSchema,
|
|
6
6
|
} from '@reactionary/core';
|
|
7
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
7
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
8
8
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
9
9
|
|
|
10
10
|
const testData = {
|
|
@@ -12,34 +12,38 @@ const testData = {
|
|
|
12
12
|
skuWithTiers: '0766623360203',
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
16
|
-
|
|
15
|
+
describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
16
|
+
'Checkout Capability - %s',
|
|
17
|
+
(provider) => {
|
|
18
|
+
let client: ReturnType<typeof createClient>;
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
client = createClient(provider);
|
|
22
|
+
});
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
describe('anonymous sessions', () => {
|
|
25
|
+
let cart: Cart;
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
cart: { key: '' },
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
const c = await client.cart.add({
|
|
29
29
|
variant: {
|
|
30
30
|
sku: testData.skuWithoutTiers,
|
|
31
31
|
},
|
|
32
32
|
quantity: 1,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!c.success) {
|
|
36
|
+
assert.fail();
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
cart = c.value;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('can create a checkout session from a cart', async () => {
|
|
43
|
+
// we have either an anonymous user, or an authenticated user.
|
|
44
|
+
// if it is anonymous, we assume you will have collected some basic info by now ?
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
{
|
|
46
|
+
const checkout = await client.checkout.initiateCheckoutForCart({
|
|
43
47
|
cart: cart,
|
|
44
48
|
billingAddress: {
|
|
45
49
|
countryCode: 'US',
|
|
@@ -53,21 +57,27 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Checkout Capability - %s', (prov
|
|
|
53
57
|
},
|
|
54
58
|
notificationEmail: 'sample@example.com',
|
|
55
59
|
notificationPhone: '+4512345678',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!checkout.success) {
|
|
63
|
+
assert.fail();
|
|
56
64
|
}
|
|
57
|
-
);
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
expect(checkout.value.identifier.key).toBeDefined();
|
|
67
|
+
expect(checkout.value.originalCartReference.key).toBe(
|
|
68
|
+
cart.identifier.key
|
|
69
|
+
);
|
|
70
|
+
expect(checkout.value.billingAddress?.firstName).toBe('John');
|
|
71
|
+
expect(checkout.value.items.length).toBe(1);
|
|
72
|
+
expect(checkout.value.items[0].variant.sku).toBe(
|
|
73
|
+
testData.skuWithoutTiers
|
|
74
|
+
);
|
|
75
|
+
});
|
|
65
76
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{
|
|
77
|
+
describe('checkout actions', () => {
|
|
78
|
+
let checkout: Checkout;
|
|
79
|
+
beforeEach(async () => {
|
|
80
|
+
const cc = await client.checkout.initiateCheckoutForCart({
|
|
71
81
|
cart: cart,
|
|
72
82
|
billingAddress: {
|
|
73
83
|
countryCode: 'US',
|
|
@@ -81,192 +91,251 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Checkout Capability - %s', (prov
|
|
|
81
91
|
},
|
|
82
92
|
notificationEmail: 'sample@example.com',
|
|
83
93
|
notificationPhone: '+4512345678',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (!cc.success) {
|
|
97
|
+
console.log(cc);
|
|
98
|
+
|
|
99
|
+
assert.fail();
|
|
84
100
|
}
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
checkout = cc.value;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('can list payment methods', async () => {
|
|
106
|
+
const paymentMethods =
|
|
107
|
+
await client.checkout.getAvailablePaymentMethods({
|
|
108
|
+
checkout: checkout.identifier,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!paymentMethods.success) {
|
|
112
|
+
assert.fail();
|
|
92
113
|
}
|
|
93
|
-
);
|
|
94
|
-
expect(paymentMethods.length).toBeGreaterThan(0);
|
|
95
|
-
expect(
|
|
96
|
-
paymentMethods.find((x) => x.identifier.method === 'stripe')
|
|
97
|
-
).toBeDefined();
|
|
98
|
-
});
|
|
99
114
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
expect(paymentMethods.value.length).toBeGreaterThan(0);
|
|
116
|
+
expect(
|
|
117
|
+
paymentMethods.value.find((x) => x.identifier.method === 'stripe')
|
|
118
|
+
).toBeDefined();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('can list shipping methods', async () => {
|
|
122
|
+
const shippingMethods =
|
|
123
|
+
await client.checkout.getAvailableShippingMethods({
|
|
124
|
+
checkout: checkout.identifier,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (!shippingMethods.success) {
|
|
128
|
+
assert.fail();
|
|
104
129
|
}
|
|
105
|
-
);
|
|
106
|
-
expect(shippingMethods.length).toBeGreaterThan(0);
|
|
107
|
-
expect(
|
|
108
|
-
shippingMethods.find((x) => x.identifier.key === 'us-delivery')
|
|
109
|
-
).toBeDefined();
|
|
110
|
-
});
|
|
111
130
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
expect(shippingMethods.value.length).toBeGreaterThan(0);
|
|
132
|
+
expect(
|
|
133
|
+
shippingMethods.value.find(
|
|
134
|
+
(x) => x.identifier.key === 'us-delivery'
|
|
135
|
+
)
|
|
136
|
+
).toBeDefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('can add a payment instruction', async () => {
|
|
140
|
+
const paymentMethods =
|
|
141
|
+
await client.checkout.getAvailablePaymentMethods({
|
|
142
|
+
checkout: checkout.identifier,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (!paymentMethods.success) {
|
|
146
|
+
assert.fail();
|
|
116
147
|
}
|
|
117
|
-
);
|
|
118
|
-
const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
|
|
119
|
-
expect(pm).toBeDefined();
|
|
120
148
|
|
|
121
|
-
|
|
122
|
-
|
|
149
|
+
const pm = paymentMethods.value.find(
|
|
150
|
+
(x) => x.identifier.method === 'stripe'
|
|
151
|
+
);
|
|
152
|
+
expect(pm).toBeDefined();
|
|
153
|
+
|
|
154
|
+
const checkoutWithPi = await client.checkout.addPaymentInstruction({
|
|
123
155
|
checkout: checkout.identifier,
|
|
124
156
|
paymentInstruction: PaymentInstructionSchema.parse({
|
|
125
157
|
paymentMethod: pm!.identifier,
|
|
126
158
|
amount: checkout.price.grandTotal,
|
|
127
159
|
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
128
160
|
identifier: {
|
|
129
|
-
key: 'pm1'
|
|
161
|
+
key: 'pm1',
|
|
130
162
|
},
|
|
131
|
-
status: 'pending'
|
|
132
|
-
} satisfies
|
|
163
|
+
status: 'pending',
|
|
164
|
+
} satisfies PaymentInstruction),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (!checkoutWithPi.success) {
|
|
168
|
+
assert.fail();
|
|
133
169
|
}
|
|
134
|
-
);
|
|
135
170
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
171
|
+
expect(checkoutWithPi.value.paymentInstructions.length).toBe(1);
|
|
172
|
+
expect(
|
|
173
|
+
checkoutWithPi.value.paymentInstructions[0].paymentMethod.method
|
|
174
|
+
).toBe('stripe');
|
|
175
|
+
expect(
|
|
176
|
+
checkoutWithPi.value.paymentInstructions[0].protocolData.find(
|
|
177
|
+
(x) => x.key === 'stripe_clientSecret'
|
|
178
|
+
)?.value
|
|
179
|
+
).toBeDefined();
|
|
180
|
+
});
|
|
141
181
|
|
|
142
|
-
|
|
182
|
+
it.skip('can cancel an in-progress payment', async () => {
|
|
183
|
+
const paymentMethods =
|
|
184
|
+
await client.checkout.getAvailablePaymentMethods({
|
|
185
|
+
checkout: checkout.identifier,
|
|
186
|
+
});
|
|
143
187
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{
|
|
147
|
-
checkout: checkout.identifier,
|
|
188
|
+
if (!paymentMethods.success) {
|
|
189
|
+
assert.fail();
|
|
148
190
|
}
|
|
149
|
-
);
|
|
150
|
-
const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
|
|
151
|
-
expect(pm).toBeDefined();
|
|
152
191
|
|
|
153
|
-
|
|
154
|
-
|
|
192
|
+
const pm = paymentMethods.value.find(
|
|
193
|
+
(x) => x.identifier.method === 'stripe'
|
|
194
|
+
);
|
|
195
|
+
expect(pm).toBeDefined();
|
|
196
|
+
|
|
197
|
+
const checkoutWithPi = await client.checkout.addPaymentInstruction({
|
|
155
198
|
checkout: checkout.identifier,
|
|
156
199
|
paymentInstruction: {
|
|
157
200
|
paymentMethod: pm!.identifier,
|
|
158
201
|
amount: checkout.price.grandTotal,
|
|
159
202
|
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
160
203
|
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (!checkoutWithPi.success) {
|
|
207
|
+
assert.fail();
|
|
161
208
|
}
|
|
162
|
-
);
|
|
163
209
|
|
|
164
|
-
|
|
210
|
+
expect(checkoutWithPi.value.paymentInstructions.length).toBe(1);
|
|
165
211
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
212
|
+
const checkoutAfterCancel =
|
|
213
|
+
await client.checkout.removePaymentInstruction({
|
|
214
|
+
checkout: checkout.identifier,
|
|
215
|
+
paymentInstruction:
|
|
216
|
+
checkoutWithPi.value.paymentInstructions[0].identifier,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (!checkoutAfterCancel.success) {
|
|
220
|
+
assert.fail();
|
|
171
221
|
}
|
|
172
|
-
);
|
|
173
222
|
|
|
174
|
-
|
|
175
|
-
|
|
223
|
+
expect(checkoutAfterCancel.value.paymentInstructions.length).toBe(0);
|
|
224
|
+
});
|
|
176
225
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
226
|
+
it('can set shipping address', async () => {
|
|
227
|
+
const checkoutWithShipping = await client.checkout.setShippingAddress(
|
|
228
|
+
{
|
|
229
|
+
checkout: checkout.identifier,
|
|
230
|
+
shippingAddress: {
|
|
231
|
+
countryCode: 'US',
|
|
232
|
+
firstName: 'Jane',
|
|
233
|
+
lastName: 'Doe',
|
|
234
|
+
streetAddress: '456 Other St',
|
|
235
|
+
streetNumber: '2B',
|
|
236
|
+
postalCode: '54321',
|
|
237
|
+
city: 'Othertown',
|
|
238
|
+
region: '',
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
if (!checkoutWithShipping.success) {
|
|
244
|
+
assert.fail();
|
|
191
245
|
}
|
|
192
|
-
);
|
|
193
246
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
247
|
+
expect(checkoutWithShipping.value.shippingAddress).toBeDefined();
|
|
248
|
+
expect(checkoutWithShipping.value.shippingAddress?.firstName).toBe('Jane');
|
|
249
|
+
});
|
|
197
250
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
251
|
+
it('can set shipping instructions', async () => {
|
|
252
|
+
const shippingMethods =
|
|
253
|
+
await client.checkout.getAvailableShippingMethods({
|
|
254
|
+
checkout: checkout.identifier,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (!shippingMethods.success) {
|
|
258
|
+
assert.fail();
|
|
202
259
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
260
|
+
|
|
261
|
+
const sm = shippingMethods.value.find(
|
|
262
|
+
(x) => x.identifier.key === 'us-delivery'
|
|
263
|
+
);
|
|
264
|
+
expect(sm).toBeDefined();
|
|
265
|
+
|
|
266
|
+
const shippingInstruction = ShippingInstructionSchema.parse({
|
|
267
|
+
shippingMethod: sm?.identifier || { key: '' },
|
|
268
|
+
amount: checkout.price.totalShipping,
|
|
269
|
+
instructions: 'Leave at front door if not home',
|
|
270
|
+
consentForUnattendedDelivery: true,
|
|
271
|
+
pickupPoint: '4190asx141', // this would be a real pickup point ID in a real scenario
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const checkoutWithShipping =
|
|
275
|
+
await client.checkout.setShippingInstruction({
|
|
276
|
+
checkout: checkout.identifier,
|
|
277
|
+
shippingInstruction,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
if (!checkoutWithShipping.success) {
|
|
281
|
+
assert.fail();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
expect(checkout.price.totalShipping.value).toBe(0);
|
|
285
|
+
expect(
|
|
286
|
+
checkoutWithShipping.value.price.totalShipping.value
|
|
287
|
+
).toBeGreaterThan(0);
|
|
288
|
+
expect(checkoutWithShipping.value.shippingInstruction).toBeDefined();
|
|
289
|
+
expect(
|
|
290
|
+
checkoutWithShipping.value.shippingInstruction?.shippingMethod.key
|
|
291
|
+
).toBe('us-delivery');
|
|
292
|
+
expect(checkoutWithShipping.value.shippingInstruction?.instructions).toBe(
|
|
293
|
+
'Leave at front door if not home'
|
|
294
|
+
);
|
|
295
|
+
expect(checkoutWithShipping.value.shippingInstruction?.pickupPoint).toBe(
|
|
296
|
+
'4190asx141'
|
|
297
|
+
);
|
|
298
|
+
expect(
|
|
299
|
+
checkoutWithShipping.value.shippingInstruction
|
|
300
|
+
?.consentForUnattendedDelivery
|
|
301
|
+
).toBe(true);
|
|
213
302
|
});
|
|
214
303
|
|
|
215
|
-
|
|
216
|
-
|
|
304
|
+
it.skip('wont report it finalizable until everything is paid/authorized', async () => {
|
|
305
|
+
expect(checkout.readyForFinalization).toBe(false);
|
|
306
|
+
const r = await client.checkout.getAvailablePaymentMethods({
|
|
217
307
|
checkout: checkout.identifier,
|
|
218
|
-
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
if (!r.success) {
|
|
311
|
+
assert.fail();
|
|
219
312
|
}
|
|
220
|
-
);
|
|
221
313
|
|
|
222
|
-
|
|
223
|
-
expect(checkoutWithShipping.price.totalShipping.value).toBeGreaterThan(0);
|
|
224
|
-
expect(checkoutWithShipping.shippingInstruction).toBeDefined();
|
|
225
|
-
expect(
|
|
226
|
-
checkoutWithShipping.shippingInstruction?.shippingMethod.key
|
|
227
|
-
).toBe('us-delivery');
|
|
228
|
-
expect(checkoutWithShipping.shippingInstruction?.instructions).toBe(
|
|
229
|
-
'Leave at front door if not home'
|
|
230
|
-
);
|
|
231
|
-
expect(checkoutWithShipping.shippingInstruction?.pickupPoint).toBe(
|
|
232
|
-
'4190asx141'
|
|
233
|
-
);
|
|
234
|
-
expect(
|
|
235
|
-
checkoutWithShipping.shippingInstruction?.consentForUnattendedDelivery
|
|
236
|
-
).toBe(true);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it.skip('wont report it finalizable until everything is paid/authorized', async () => {
|
|
240
|
-
expect(checkout.readyForFinalization).toBe(false);
|
|
241
|
-
const pm = (
|
|
242
|
-
await client.checkout.getAvailablePaymentMethods(
|
|
243
|
-
{
|
|
244
|
-
checkout: checkout.identifier,
|
|
245
|
-
}
|
|
246
|
-
)
|
|
247
|
-
).find((x) => x.identifier.method === 'stripe');
|
|
248
|
-
expect(pm).toBeDefined();
|
|
314
|
+
const pm = r.value.find((x) => x.identifier.method === 'stripe');
|
|
249
315
|
|
|
250
|
-
|
|
251
|
-
{
|
|
316
|
+
const checkoutWithPi = await client.checkout.addPaymentInstruction({
|
|
252
317
|
checkout: checkout.identifier,
|
|
253
318
|
paymentInstruction: {
|
|
254
319
|
paymentMethod: pm!.identifier,
|
|
255
320
|
amount: checkout.price.grandTotal,
|
|
256
321
|
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
257
322
|
},
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (!checkoutWithPi.success) {
|
|
326
|
+
assert.fail();
|
|
258
327
|
}
|
|
259
|
-
);
|
|
260
328
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
329
|
+
// do something to simulate payment authorization ?
|
|
330
|
+
const checkoutReady = await client.checkout.getById({
|
|
331
|
+
identifier: checkoutWithPi.value.identifier,
|
|
332
|
+
});
|
|
333
|
+
if (!checkoutReady.success) {
|
|
334
|
+
expect.fail('checkout not found');
|
|
335
|
+
}
|
|
336
|
+
expect(checkoutReady.value.readyForFinalization).toBe(true);
|
|
337
|
+
});
|
|
269
338
|
});
|
|
270
339
|
});
|
|
271
|
-
}
|
|
272
|
-
|
|
340
|
+
}
|
|
341
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
3
3
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
describe.each([PrimaryProvider.COMMERCETOOLS])('Identity Capability - %s', (provider) => {
|
|
@@ -12,14 +12,16 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Identity Capability - %s', (prov
|
|
|
12
12
|
it('should default to an anonymous identity if no operations have been performed', async () => {
|
|
13
13
|
const identity = await client.identity.getSelf({});
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
if (!identity.success) {
|
|
16
|
+
assert.fail();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(identity.value.type).toBe('Anonymous');
|
|
16
20
|
});
|
|
17
21
|
|
|
18
22
|
it('should automatically upgrade to guest the moment an operation is performed', async () => {
|
|
19
|
-
const cart = await client.cart.getActiveCartId();
|
|
20
23
|
const updatedCart = await client.cart.add(
|
|
21
24
|
{
|
|
22
|
-
cart,
|
|
23
25
|
quantity: 1,
|
|
24
26
|
variant: {
|
|
25
27
|
sku: '0766623301831'
|
|
@@ -29,7 +31,11 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Identity Capability - %s', (prov
|
|
|
29
31
|
|
|
30
32
|
const identity = await client.identity.getSelf({});
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
if (!identity.success) {
|
|
35
|
+
assert.fail();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expect(identity.value.type).toBe('Guest');
|
|
33
39
|
});
|
|
34
40
|
|
|
35
41
|
it('should be able to register a new customer', async () => {
|
|
@@ -41,10 +47,18 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Identity Capability - %s', (prov
|
|
|
41
47
|
}
|
|
42
48
|
);
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
if (!identity.success) {
|
|
51
|
+
assert.fail();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
expect(identity.value.type).toBe('Registered');
|
|
45
55
|
|
|
46
56
|
const refreshedIdentity = await client.identity.getSelf({});
|
|
47
|
-
|
|
57
|
+
|
|
58
|
+
if (!refreshedIdentity.success) {
|
|
59
|
+
assert.fail();
|
|
60
|
+
}
|
|
61
|
+
expect(refreshedIdentity.value.type).toBe('Registered');
|
|
48
62
|
});
|
|
49
63
|
|
|
50
64
|
it('should be able to log out from a Registered identity', async () => {
|
|
@@ -56,12 +70,24 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Identity Capability - %s', (prov
|
|
|
56
70
|
}
|
|
57
71
|
);
|
|
58
72
|
|
|
59
|
-
|
|
73
|
+
if (!identity.success) {
|
|
74
|
+
assert.fail();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
expect(identity.value.type).toBe('Registered');
|
|
60
78
|
|
|
61
79
|
const loggedOutIdentity = await client.identity.logout({});
|
|
62
|
-
|
|
80
|
+
|
|
81
|
+
if (!loggedOutIdentity.success) {
|
|
82
|
+
assert.fail();
|
|
83
|
+
}
|
|
84
|
+
expect(loggedOutIdentity.value.type).toBe('Anonymous');
|
|
63
85
|
|
|
64
86
|
const refreshedIdentity = await client.identity.getSelf({});
|
|
65
|
-
|
|
87
|
+
|
|
88
|
+
if (!refreshedIdentity.success) {
|
|
89
|
+
assert.fail();
|
|
90
|
+
}
|
|
91
|
+
expect(refreshedIdentity.value.type).toBe('Anonymous');
|
|
66
92
|
});
|
|
67
93
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
3
3
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider) => {
|
|
@@ -9,7 +9,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider
|
|
|
9
9
|
client = createClient(provider);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
it('should return
|
|
12
|
+
it('should return NotFound for unknown SKU', async () => {
|
|
13
13
|
const inventory = await client.inventory.getBySKU({
|
|
14
14
|
variant: {
|
|
15
15
|
sku: 'GMCT-01x',
|
|
@@ -19,16 +19,14 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(inventory.
|
|
27
|
-
expect(inventory.quantity).toBe(0);
|
|
28
|
-
expect(inventory.meta.placeholder).toBe(true);
|
|
22
|
+
if (inventory.success) {
|
|
23
|
+
assert.fail();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
expect(inventory.error.type).toBe('NotFound');
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
it('should return
|
|
29
|
+
it('should return NotFound for unknown ffmcenter', async () => {
|
|
32
30
|
const inventory = await client.inventory.getBySKU({
|
|
33
31
|
variant: {
|
|
34
32
|
sku: 'GMCT-01',
|
|
@@ -38,15 +36,13 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider
|
|
|
38
36
|
},
|
|
39
37
|
});
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
);
|
|
45
|
-
expect(inventory.status).toBe('outOfStock');
|
|
46
|
-
expect(inventory.quantity).toBe(0);
|
|
47
|
-
expect(inventory.meta.placeholder).toBe(true);
|
|
39
|
+
if (inventory.success) {
|
|
40
|
+
assert.fail();
|
|
41
|
+
}
|
|
48
42
|
|
|
43
|
+
expect(inventory.error.type).toBe('NotFound');
|
|
49
44
|
});
|
|
45
|
+
|
|
50
46
|
it('should be able to fetch inventory for a given SKU and Fulfillment Center', async () => {
|
|
51
47
|
const inventory = await client.inventory.getBySKU({
|
|
52
48
|
variant: {
|
|
@@ -57,10 +53,14 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider
|
|
|
57
53
|
},
|
|
58
54
|
});
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (!inventory.success) {
|
|
57
|
+
assert.fail();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
expect(inventory.value.identifier.variant.sku).toBe('GMCT-01');
|
|
61
|
+
expect(inventory.value.identifier.fulfillmentCenter.key).toBe(
|
|
62
62
|
'solteqPhysicalStore'
|
|
63
63
|
);
|
|
64
|
-
expect(inventory.quantity).toBe(42);
|
|
64
|
+
expect(inventory.value.quantity).toBe(42);
|
|
65
65
|
});
|
|
66
66
|
});
|