@reactionary/examples-node 0.3.17 → 0.3.18

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@reactionary/examples-node",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.17",
8
- "@reactionary/provider-commercetools": "0.3.17",
9
- "@reactionary/provider-algolia": "0.3.17",
10
- "@reactionary/provider-medusa": "0.3.17",
11
- "@reactionary/provider-meilisearch": "0.3.17",
12
- "@reactionary/provider-fake": "0.3.17"
7
+ "@reactionary/core": "0.3.18",
8
+ "@reactionary/provider-commercetools": "0.3.18",
9
+ "@reactionary/provider-algolia": "0.3.18",
10
+ "@reactionary/provider-medusa": "0.3.18",
11
+ "@reactionary/provider-meilisearch": "0.3.18",
12
+ "@reactionary/provider-fake": "0.3.18"
13
13
  },
14
14
  "type": "module"
15
15
  }
@@ -8,7 +8,7 @@ const testData = {
8
8
  skuWithTiers: '0766623360203',
9
9
  };
10
10
 
11
- describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider) => {
11
+ describe.each([ PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])('Cart Capability - %s', (provider) => {
12
12
  let client: ReturnType<typeof createClient>;
13
13
 
14
14
  beforeEach(() => {
@@ -37,7 +37,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
37
37
  });
38
38
 
39
39
  if (!cart.success) {
40
- assert.fail();
40
+ assert.fail(JSON.stringify(cart.error));
41
41
  }
42
42
 
43
43
  expect(cart.value.identifier.key).toBeDefined();
@@ -61,9 +61,8 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
61
61
  },
62
62
  quantity: 1,
63
63
  });
64
-
65
64
  if (!cart.success) {
66
- assert.fail();
65
+ assert.fail(JSON.stringify(cart.error));
67
66
  }
68
67
 
69
68
  const updatedCart = await client.cart.add({
@@ -75,7 +74,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
75
74
  });
76
75
 
77
76
  if (!updatedCart.success) {
78
- assert.fail();
77
+ assert.fail(JSON.stringify(updatedCart.error) );
79
78
  }
80
79
 
81
80
  expect(updatedCart.value.items.length).toBe(2);
@@ -94,7 +93,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
94
93
  });
95
94
 
96
95
  if (!cart.success) {
97
- assert.fail();
96
+ assert.fail (JSON.stringify(cart.error) );
98
97
  }
99
98
 
100
99
  const updatedCart = await client.cart.changeQuantity({
@@ -104,7 +103,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
104
103
  });
105
104
 
106
105
  if (!updatedCart.success) {
107
- assert.fail();
106
+ assert.fail(JSON.stringify(updatedCart.error));
108
107
  }
109
108
 
110
109
  expect(updatedCart.value.items.length).toBe(1);
@@ -127,7 +126,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
127
126
  });
128
127
 
129
128
  if (!cart.success) {
130
- assert.fail();
129
+ assert.fail(JSON.stringify(cart.error));
131
130
  }
132
131
 
133
132
  const updatedCart = await client.cart.remove({
@@ -136,13 +135,15 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
136
135
  });
137
136
 
138
137
  if (!updatedCart.success) {
139
- assert.fail();
138
+ assert.fail(JSON.stringify(updatedCart.error));
140
139
  }
141
140
 
142
141
  expect(updatedCart.value.items.length).toBe(0);
143
142
  });
144
143
 
145
144
  it('should be able to delete a cart', async () => {
145
+
146
+
146
147
  const cart = await client.cart.add({
147
148
  variant: {
148
149
  sku: testData.skuWithoutTiers,
@@ -151,22 +152,38 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
151
152
  });
152
153
 
153
154
  if (!cart.success) {
154
- assert.fail();
155
+ assert.fail(JSON.stringify(cart.error) );
155
156
  }
156
157
 
157
158
  expect(cart.value.items.length).toBe(1);
158
159
  expect(cart.value.identifier.key).toBeTruthy();
159
160
 
160
- await client.cart.deleteCart({
161
+ const deleteCartResponse = await client.cart.deleteCart({
161
162
  cart: cart.value.identifier,
162
163
  });
163
164
 
165
+ if (!deleteCartResponse.success) {
166
+ assert.fail(JSON.stringify(deleteCartResponse.error));
167
+ }
168
+
169
+
164
170
  const originalCart = await client.cart.getById({
165
171
  cart: cart.value.identifier,
166
172
  });
167
173
 
174
+
175
+ if (provider === PrimaryProvider.MEDUSA) {
176
+ // medusa can't delete a cart, so we just empty it.
177
+ if (!originalCart.success) {
178
+ assert.fail(JSON.stringify(originalCart.error));
179
+ }
180
+
181
+ expect(originalCart.value.items.length).toBe(0);
182
+ return;
183
+ }
184
+
168
185
  if (originalCart.success) {
169
- assert.fail();
186
+ assert.fail(JSON.stringify(originalCart.value));
170
187
  }
171
188
  expect(originalCart.error.type).toBe('NotFound');
172
189
  });
@@ -180,7 +197,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
180
197
  });
181
198
 
182
199
  if (!cart.success) {
183
- assert.fail();
200
+ assert.fail(JSON.stringify(cart.error));
184
201
  }
185
202
 
186
203
  expect(cart.value.items[0].variant).toBeDefined();
@@ -190,7 +207,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
190
207
  });
191
208
 
192
209
  if (!product.success) {
193
- assert.fail();
210
+ assert.fail(JSON.stringify(product.error));
194
211
  }
195
212
 
196
213
  expect(product).toBeTruthy();
@@ -201,6 +218,71 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
201
218
  }
202
219
  });
203
220
 
221
+ it('can apply a coupon code to a cart', async () => {
222
+ const cart = await client.cart.add({
223
+ variant: {
224
+ sku: testData.skuWithoutTiers,
225
+ },
226
+ quantity: 1,
227
+ });
228
+
229
+ if (!cart.success) {
230
+ assert.fail(JSON.stringify(cart.error));
231
+ }
232
+ expect(cart.value.price.totalDiscount.value).toBe(0);
233
+
234
+ const updatedCart = await client.cart.applyCouponCode({
235
+ cart: cart.value.identifier,
236
+ couponCode: 'TESTCODE1',
237
+ });
238
+
239
+ if (!updatedCart.success) {
240
+ assert.fail(JSON.stringify(updatedCart.error));
241
+ }
242
+
243
+ expect(updatedCart.value.price.grandTotal.value).toBeLessThan(cart.value.price.grandTotal.value);
244
+ expect(updatedCart.value.price.totalDiscount.value).toBeGreaterThan(0);
245
+
246
+ expect(updatedCart.value.appliedPromotions.find(promo => promo.code === 'TESTCODE1' && promo.isCouponCode === true)).toBeTruthy();
247
+
248
+ });
249
+
250
+ it('can remove a coupon code from a cart', async () => {
251
+ const cart = await client.cart.add({
252
+ variant: {
253
+ sku: testData.skuWithoutTiers,
254
+ },
255
+ quantity: 1,
256
+ });
257
+
258
+ if (!cart.success) {
259
+ assert.fail(JSON.stringify(cart.error));
260
+ }
261
+ const updatedCart = await client.cart.applyCouponCode({
262
+ cart: cart.value.identifier,
263
+ couponCode: 'TESTCODE1',
264
+ });
265
+
266
+ if (!updatedCart.success) {
267
+ assert.fail(JSON.stringify(updatedCart.error));
268
+ }
269
+
270
+ expect(updatedCart.value.price.grandTotal.value).toBeLessThan(cart.value.price.grandTotal.value);
271
+
272
+ const removedCouponCart = await client.cart.removeCouponCode({
273
+ cart: cart.value.identifier,
274
+ couponCode: 'TESTCODE1',
275
+ });
276
+
277
+ if (!removedCouponCart.success) {
278
+ assert.fail(JSON.stringify(removedCouponCart.error));
279
+ }
280
+
281
+ expect(removedCouponCart.value.price.grandTotal.value).toBeGreaterThan(updatedCart.value.price.grandTotal.value);
282
+ expect(removedCouponCart.value.price.grandTotal.value).toBe(cart.value.price.grandTotal.value);
283
+ });
284
+
285
+
204
286
  it('should be able to add an 50 items to a cart in less than 30 seconds', async () => {
205
287
  const searchResult = await client.productSearch.queryByTerm(
206
288
  ProductSearchQueryByTermSchema.parse({
@@ -217,7 +299,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
217
299
  );
218
300
 
219
301
  if (!searchResult.success) {
220
- assert.fail();
302
+ assert.fail(JSON.stringify(searchResult.error) );
221
303
  }
222
304
 
223
305
  let cartIdentifier = undefined;
@@ -24,7 +24,7 @@ const testData = {
24
24
  breadCrumb: ['2833', '225'],
25
25
  };
26
26
 
27
- describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (provider) => {
27
+ describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])('Category Capability - %s', (provider) => {
28
28
  let client: ReturnType<typeof createClient>;
29
29
 
30
30
  beforeEach(() => {
@@ -37,7 +37,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
37
37
  });
38
38
 
39
39
  if (!result.success) {
40
- assert.fail();
40
+ assert.fail(JSON.stringify(result.error));
41
41
  }
42
42
 
43
43
  expect(result.value.items.length).toBeGreaterThan(0);
@@ -55,23 +55,26 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
55
55
  });
56
56
 
57
57
  if (!result.success) {
58
- assert.fail();
58
+ assert.fail(JSON.stringify(result.error));
59
59
  }
60
60
 
61
61
  expect(result.value.items.length).toBeGreaterThan(0);
62
- expect(result.value.items[0].identifier.key).toBe(
63
- testData.childCategoriesOfFirstTopcategory[0].key
64
- );
65
- expect(result.value.items[0].name).toBe(
66
- testData.childCategoriesOfFirstTopcategory[0].name
67
- );
62
+ expect(result.value.items).toEqual(
68
63
 
69
- expect(result.value.items[1].identifier.key).toBe(
70
- testData.childCategoriesOfFirstTopcategory[1].key
71
- );
72
- expect(result.value.items[1].name).toBe(
73
- testData.childCategoriesOfFirstTopcategory[1].name
64
+ expect.arrayContaining([
65
+ expect.objectContaining({
66
+ identifier: { key: testData.childCategoriesOfFirstTopcategory[0].key },
67
+ name: testData.childCategoriesOfFirstTopcategory[0].name,
68
+ }),
69
+
70
+ expect.objectContaining({
71
+ identifier: { key: testData.childCategoriesOfFirstTopcategory[1].key },
72
+ name: testData.childCategoriesOfFirstTopcategory[1].name,
73
+ }),
74
+
75
+ ])
74
76
  );
77
+
75
78
  });
76
79
 
77
80
  it('should be able to get child categories for a category, paged', async () => {
@@ -79,43 +82,35 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
79
82
  parentId: { key: testData.topCategories[0].key },
80
83
  paginationOptions: { pageSize: 1, pageNumber: 1 },
81
84
  });
82
-
85
+
83
86
  if (!result.success) {
84
- assert.fail();
87
+ assert.fail(JSON.stringify(result.error));
85
88
  }
86
89
 
87
90
  expect(result.value.items.length).toBeGreaterThan(0);
88
- expect(result.value.items[0].identifier.key).toBe(
89
- testData.childCategoriesOfFirstTopcategory[0].key
90
- );
91
- expect(result.value.items[0].name).toBe(
92
- testData.childCategoriesOfFirstTopcategory[0].name
93
- );
94
91
  expect(result.value.totalCount).toBe(3);
95
92
  expect(result.value.totalPages).toBe(3);
96
93
  expect(result.value.pageSize).toBe(1);
97
94
  expect(result.value.pageNumber).toBe(1);
98
95
 
96
+ const idFrom1 = result.value.items[0].identifier.key;
97
+
99
98
  result = await client.category.findChildCategories({
100
99
  parentId: { key: testData.topCategories[0].key },
101
100
  paginationOptions: { pageSize: 1, pageNumber: 2 },
102
101
  });
103
102
 
104
103
  if (!result.success) {
105
- assert.fail();
104
+ assert.fail(JSON.stringify(result.error) );
106
105
  }
107
106
 
108
107
  expect(result.value.items.length).toBeGreaterThan(0);
109
- expect(result.value.items[0].identifier.key).toBe(
110
- testData.childCategoriesOfFirstTopcategory[1].key
111
- );
112
- expect(result.value.items[0].name).toBe(
113
- testData.childCategoriesOfFirstTopcategory[1].name
114
- );
115
108
  expect(result.value.totalCount).toBe(3);
116
109
  expect(result.value.totalPages).toBe(3);
117
110
  expect(result.value.pageSize).toBe(1);
118
111
  expect(result.value.pageNumber).toBe(2);
112
+
113
+ expect(result.value.items[0].identifier.key).not.toBe(idFrom1);
119
114
  });
120
115
 
121
116
  it('can load all breadcrumbs for a category', async () => {
@@ -138,7 +133,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
138
133
  const result = await client.category.getBySlug({
139
134
  slug: testData.topCategories[0].slug!,
140
135
  });
141
-
136
+
142
137
  if (!result.success) {
143
138
  assert.fail();
144
139
  }
@@ -154,7 +149,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
154
149
 
155
150
  it('returns NotFound if looking for slug that does not exist', async () => {
156
151
  const result = await client.category.getBySlug({ slug: 'non-existent-slug' });
157
-
152
+
158
153
  if (result.success) {
159
154
  assert.fail();
160
155
  }
@@ -183,7 +178,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
183
178
  const result = await client.category.getById({
184
179
  id: { key: 'non-existent-category' },
185
180
  });
186
-
181
+
187
182
  if (result.success) {
188
183
  assert.fail();
189
184
  }
@@ -12,7 +12,7 @@ const testData = {
12
12
  skuWithTiers: '0766623360203',
13
13
  };
14
14
 
15
- describe.each([PrimaryProvider.COMMERCETOOLS])(
15
+ describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])(
16
16
  'Checkout Capability - %s',
17
17
  (provider) => {
18
18
  let client: ReturnType<typeof createClient>;
@@ -46,7 +46,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
46
46
  const checkout = await client.checkout.initiateCheckoutForCart({
47
47
  cart: cart,
48
48
  billingAddress: {
49
- countryCode: 'US',
49
+ countryCode: 'DK',
50
50
  firstName: 'John',
51
51
  lastName: 'Doe',
52
52
  streetAddress: '123 Main St',
@@ -80,7 +80,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
80
80
  const cc = await client.checkout.initiateCheckoutForCart({
81
81
  cart: cart,
82
82
  billingAddress: {
83
- countryCode: 'US',
83
+ countryCode: 'DK',
84
84
  firstName: 'John',
85
85
  lastName: 'Doe',
86
86
  streetAddress: '123 Main St',
@@ -114,7 +114,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
114
114
 
115
115
  expect(paymentMethods.value.length).toBeGreaterThan(0);
116
116
  expect(
117
- paymentMethods.value.find((x) => x.identifier.method === 'stripe')
117
+ paymentMethods.value.find((x) => x.identifier.method === 'stripe' || x.identifier.method.includes('stripe'))
118
118
  ).toBeDefined();
119
119
  });
120
120
 
@@ -306,7 +306,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
306
306
  const r = await client.checkout.getAvailablePaymentMethods({
307
307
  checkout: checkout.identifier,
308
308
  });
309
-
309
+
310
310
  if (!r.success) {
311
311
  assert.fail();
312
312
  }
@@ -2,6 +2,10 @@ import 'dotenv/config';
2
2
  import { describe, expect, it, beforeEach, assert } from 'vitest';
3
3
  import { createClient, PrimaryProvider } from '../utils.js';
4
4
 
5
+ const testData = {
6
+ sku: '0766623301831'
7
+ }
8
+
5
9
  describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])('Identity Capability - %s', (provider) => {
6
10
  let client: ReturnType<typeof createClient>;
7
11
 
@@ -24,7 +28,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])('Identity
24
28
  {
25
29
  quantity: 1,
26
30
  variant: {
27
- sku: '0766623301831'
31
+ sku: testData.sku
28
32
  },
29
33
  }
30
34
  );
@@ -2,7 +2,7 @@ import 'dotenv/config';
2
2
  import { describe, expect, it, beforeEach, assert } from 'vitest';
3
3
  import { createClient, PrimaryProvider } from '../utils.js';
4
4
 
5
- describe.each([PrimaryProvider.COMMERCETOOLS])('Inventory Capability', (provider) => {
5
+ describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])('Inventory Capability', (provider) => {
6
6
  let client: ReturnType<typeof createClient>;
7
7
 
8
8
  beforeEach(() => {