@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.
@@ -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])('Checkout Capability - %s', (provider) => {
16
- let client: ReturnType<typeof createClient>;
15
+ describe.each([PrimaryProvider.COMMERCETOOLS])(
16
+ 'Checkout Capability - %s',
17
+ (provider) => {
18
+ let client: ReturnType<typeof createClient>;
17
19
 
18
- beforeEach(() => {
19
- client = createClient(provider);
20
- });
20
+ beforeEach(() => {
21
+ client = createClient(provider);
22
+ });
21
23
 
22
- describe('anonymous sessions', () => {
23
- let cart: Cart;
24
+ describe('anonymous sessions', () => {
25
+ let cart: Cart;
24
26
 
25
- beforeEach(async () => {
26
- cart = await client.cart.add(
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
- it('can create a checkout session from a cart', async () => {
38
- // we have either an anonymous user, or an authenticated user.
39
- // if it is anonymous, we assume you will have collected some basic info by now ?
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
- const checkout = await client.checkout.initiateCheckoutForCart(
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
- expect(checkout.identifier.key).toBeDefined();
60
- expect(checkout.originalCartReference.key).toBe(cart.identifier.key);
61
- expect(checkout.billingAddress?.firstName).toBe('John');
62
- expect(checkout.items.length).toBe(1);
63
- expect(checkout.items[0].variant.sku).toBe(testData.skuWithoutTiers);
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
- describe('checkout actions', () => {
67
- let checkout: Checkout;
68
- beforeEach(async () => {
69
- checkout = await client.checkout.initiateCheckoutForCart(
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
- it('can list payment methods', async () => {
89
- const paymentMethods = await client.checkout.getAvailablePaymentMethods(
90
- {
91
- checkout: checkout.identifier,
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
- it('can list shipping methods', async () => {
101
- const shippingMethods = await client.checkout.getAvailableShippingMethods(
102
- {
103
- checkout: checkout.identifier,
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
- it('can add a payment instruction', async () => {
113
- const paymentMethods = await client.checkout.getAvailablePaymentMethods(
114
- {
115
- checkout: checkout.identifier,
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
- const checkoutWithPi = await client.checkout.addPaymentInstruction(
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 Omit<PaymentInstruction, 'meta'>),
163
+ status: 'pending',
164
+ } satisfies PaymentInstruction),
165
+ });
166
+
167
+ if (!checkoutWithPi.success) {
168
+ assert.fail();
133
169
  }
134
- );
135
170
 
136
- expect(checkoutWithPi.paymentInstructions.length).toBe(1);
137
- expect(checkoutWithPi.paymentInstructions[0].paymentMethod.method).toBe(
138
- 'stripe'
139
- );
140
- expect(checkoutWithPi.paymentInstructions[0].protocolData.find(x => x.key === 'stripe_clientSecret')?.value).toBeDefined();
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
- it.skip('can cancel an in-progress payment', async () => {
145
- const paymentMethods = await client.checkout.getAvailablePaymentMethods(
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
- const checkoutWithPi = await client.checkout.addPaymentInstruction(
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
- expect(checkoutWithPi.paymentInstructions.length).toBe(1);
210
+ expect(checkoutWithPi.value.paymentInstructions.length).toBe(1);
165
211
 
166
- const checkoutAfterCancel = await client.checkout.removePaymentInstruction(
167
- {
168
- checkout: checkout.identifier,
169
- paymentInstruction:
170
- checkoutWithPi.paymentInstructions[0].identifier,
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
- expect(checkoutAfterCancel.paymentInstructions.length).toBe(0);
175
- });
223
+ expect(checkoutAfterCancel.value.paymentInstructions.length).toBe(0);
224
+ });
176
225
 
177
- it('can set shipping address', async () => {
178
- const checkoutWithShipping = await client.checkout.setShippingAddress(
179
- {
180
- checkout: checkout.identifier,
181
- shippingAddress: {
182
- countryCode: 'US',
183
- firstName: 'Jane',
184
- lastName: 'Doe',
185
- streetAddress: '456 Other St',
186
- streetNumber: '2B',
187
- postalCode: '54321',
188
- city: 'Othertown',
189
- region: '',
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
- expect(checkoutWithShipping.shippingAddress).toBeDefined();
195
- expect(checkoutWithShipping.shippingAddress?.firstName).toBe('Jane');
196
- });
247
+ expect(checkoutWithShipping.value.shippingAddress).toBeDefined();
248
+ expect(checkoutWithShipping.value.shippingAddress?.firstName).toBe('Jane');
249
+ });
197
250
 
198
- it('can set shipping instructions', async () => {
199
- const shippingMethods = await client.checkout.getAvailableShippingMethods(
200
- {
201
- checkout: checkout.identifier,
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
- const sm = shippingMethods.find((x) => x.identifier.key === 'us-delivery');
205
- expect(sm).toBeDefined();
206
-
207
- const shippingInstruction = ShippingInstructionSchema.parse({
208
- shippingMethod: sm?.identifier || { key: '' },
209
- amount: checkout.price.totalShipping,
210
- instructions: 'Leave at front door if not home',
211
- consentForUnattendedDelivery: true,
212
- pickupPoint: '4190asx141', // this would be a real pickup point ID in a real scenario
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
- const checkoutWithShipping = await client.checkout.setShippingInstruction(
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
- shippingInstruction,
308
+ });
309
+
310
+ if (!r.success) {
311
+ assert.fail();
219
312
  }
220
- );
221
313
 
222
- expect(checkout.price.totalShipping.value).toBe(0);
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
- const checkoutWithPi = await client.checkout.addPaymentInstruction(
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
- // do something to simulate payment authorization ?
262
- const checkoutReady = await client.checkout.getById(
263
- { identifier: checkoutWithPi.identifier },
264
- );
265
- if (!checkoutReady) {
266
- expect.fail('checkout not found');
267
- }
268
- expect(checkoutReady.readyForFinalization).toBe(true);
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
- expect(identity.type).toBe('Anonymous');
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
- expect(identity.type).toBe('Guest');
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
- expect(identity.type).toBe('Registered');
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
- expect(refreshedIdentity.type).toBe('Registered');
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
- expect(identity.type).toBe('Registered');
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
- expect(loggedOutIdentity.type).toBe('Anonymous');
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
- expect(refreshedIdentity.type).toBe('Anonymous');
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 unavailable for unknown SKU', async () => {
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
- expect(inventory.identifier.variant.sku).toBe('GMCT-01x');
23
- expect(inventory.identifier.fulfillmentCenter.key).toBe(
24
- 'solteqPhysicalStore'
25
- );
26
- expect(inventory.status).toBe('outOfStock');
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 unavailable for unknown ffmcenter', async () => {
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
- expect(inventory.identifier.variant.sku).toBe('GMCT-01');
42
- expect(inventory.identifier.fulfillmentCenter.key).toBe(
43
- 'unknown-ffmcenter'
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
- expect(inventory.identifier.variant.sku).toBe('GMCT-01');
61
- expect(inventory.identifier.fulfillmentCenter.key).toBe(
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
  });