@reactionary/examples-node 0.1.12 → 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
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/examples-node",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.1
|
|
8
|
-
"@reactionary/provider-commercetools": "0.1
|
|
9
|
-
"@reactionary/provider-algolia": "0.1
|
|
10
|
-
"@reactionary/provider-medusa": "0.1.12"
|
|
7
|
+
"@reactionary/core": "0.2.1",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.2.1",
|
|
9
|
+
"@reactionary/provider-algolia": "0.2.1"
|
|
11
10
|
},
|
|
12
11
|
"type": "module"
|
|
13
12
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type RequestContext,
|
|
8
8
|
} from '@reactionary/core';
|
|
9
9
|
import { withFakeCapabilities } from '@reactionary/provider-fake';
|
|
10
|
-
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
10
|
+
import { assert, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
11
11
|
|
|
12
12
|
describe('basic node setup', () => {
|
|
13
13
|
let client: Partial<Client>;
|
|
@@ -47,8 +47,12 @@ describe('basic node setup', () => {
|
|
|
47
47
|
slug: '1234',
|
|
48
48
|
}
|
|
49
49
|
);
|
|
50
|
+
|
|
51
|
+
if (!product.success) {
|
|
52
|
+
assert.fail();
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
expect(product).toBeDefined();
|
|
52
|
-
expect(product
|
|
56
|
+
expect(product.value.slug).toBe('1234');
|
|
53
57
|
});
|
|
54
58
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
3
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
3
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
4
4
|
import { ProductSearchQueryByTermSchema, type ProductSearchQueryByTerm } from '@reactionary/core';
|
|
5
5
|
|
|
6
6
|
const testData = {
|
|
@@ -16,161 +16,192 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
describe('anonymous sessions', () => {
|
|
19
|
-
it('should
|
|
19
|
+
it('should get a NotFound for an unknown cart ID', async () => {
|
|
20
20
|
const cart = await client.cart.getById({
|
|
21
21
|
cart: { key: '' },
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (cart.success) {
|
|
25
|
+
assert.fail();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
expect(cart.error.type).toBe('NotFound');
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
it('should be able to add an item to a cart', async () => {
|
|
30
32
|
const cart = await client.cart.add({
|
|
31
|
-
cart: { key: '' },
|
|
32
33
|
variant: {
|
|
33
34
|
sku: testData.skuWithoutTiers,
|
|
34
35
|
},
|
|
35
36
|
quantity: 1,
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
expect(cart.items[0].quantity).toBe(1);
|
|
39
|
+
if (!cart.success) {
|
|
40
|
+
assert.fail();
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
expect(cart.
|
|
43
|
+
expect(cart.value.identifier.key).toBeDefined();
|
|
44
|
+
expect(cart.value.items.length).toBe(1);
|
|
45
|
+
expect(cart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
46
|
+
expect(cart.value.items[0].quantity).toBe(1);
|
|
44
47
|
|
|
45
|
-
expect(cart.price.
|
|
48
|
+
expect(cart.value.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
46
49
|
|
|
47
|
-
expect(cart.price.grandTotal.value).
|
|
48
|
-
cart.items[0].price.totalPrice.value
|
|
49
|
-
);
|
|
50
|
+
expect(cart.value.price.grandTotal.value).toBeGreaterThan(0);
|
|
50
51
|
|
|
51
|
-
expect(cart.
|
|
52
|
+
expect(cart.value.price.grandTotal.value).toBe(
|
|
53
|
+
cart.value.items[0].price.totalPrice.value
|
|
54
|
+
);
|
|
52
55
|
});
|
|
53
56
|
|
|
54
57
|
it('can add multiple different items to a cart', async () => {
|
|
55
58
|
const cart = await client.cart.add({
|
|
56
|
-
cart: { key: '' },
|
|
57
59
|
variant: {
|
|
58
60
|
sku: testData.skuWithoutTiers,
|
|
59
61
|
},
|
|
60
62
|
quantity: 1,
|
|
61
63
|
});
|
|
64
|
+
|
|
65
|
+
if (!cart.success) {
|
|
66
|
+
assert.fail();
|
|
67
|
+
}
|
|
62
68
|
|
|
63
69
|
const updatedCart = await client.cart.add({
|
|
64
|
-
cart: cart.identifier,
|
|
70
|
+
cart: cart.value.identifier,
|
|
65
71
|
variant: {
|
|
66
72
|
sku: testData.skuWithTiers,
|
|
67
73
|
},
|
|
68
74
|
quantity: 2,
|
|
69
75
|
});
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
expect(updatedCart.items
|
|
77
|
+
if (!updatedCart.success) {
|
|
78
|
+
assert.fail();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
expect(updatedCart.value.items.length).toBe(2);
|
|
82
|
+
expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
83
|
+
expect(updatedCart.value.items[0].quantity).toBe(1);
|
|
84
|
+
expect(updatedCart.value.items[1].variant.sku).toBe(testData.skuWithTiers);
|
|
85
|
+
expect(updatedCart.value.items[1].quantity).toBe(2);
|
|
76
86
|
});
|
|
77
87
|
|
|
78
88
|
it('should be able to change quantity of an item in a cart', async () => {
|
|
79
89
|
const cart = await client.cart.add({
|
|
80
|
-
cart: { key: '' },
|
|
81
90
|
variant: {
|
|
82
91
|
sku: testData.skuWithoutTiers,
|
|
83
92
|
},
|
|
84
93
|
quantity: 1,
|
|
85
94
|
});
|
|
86
95
|
|
|
96
|
+
if (!cart.success) {
|
|
97
|
+
assert.fail();
|
|
98
|
+
}
|
|
99
|
+
|
|
87
100
|
const updatedCart = await client.cart.changeQuantity({
|
|
88
|
-
cart: cart.identifier,
|
|
89
|
-
item: cart.items[0].identifier,
|
|
101
|
+
cart: cart.value.identifier,
|
|
102
|
+
item: cart.value.items[0].identifier,
|
|
90
103
|
quantity: 3,
|
|
91
104
|
});
|
|
92
105
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
if (!updatedCart.success) {
|
|
107
|
+
assert.fail();
|
|
108
|
+
}
|
|
96
109
|
|
|
97
|
-
expect(updatedCart.items
|
|
98
|
-
|
|
110
|
+
expect(updatedCart.value.items.length).toBe(1);
|
|
111
|
+
expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
112
|
+
expect(updatedCart.value.items[0].quantity).toBe(3);
|
|
113
|
+
expect(updatedCart.value.items[0].price.totalPrice.value).toBeGreaterThan(
|
|
114
|
+
cart.value.items[0].price.totalPrice.value
|
|
99
115
|
);
|
|
100
|
-
expect(updatedCart.items[0].price.unitPrice.value).toBe(
|
|
101
|
-
cart.items[0].price.unitPrice.value
|
|
116
|
+
expect(updatedCart.value.items[0].price.unitPrice.value).toBe(
|
|
117
|
+
cart.value.items[0].price.unitPrice.value
|
|
102
118
|
);
|
|
103
119
|
});
|
|
104
120
|
|
|
105
121
|
it('should be able to remove an item from a cart', async () => {
|
|
106
122
|
const cart = await client.cart.add({
|
|
107
|
-
cart: { key: '' },
|
|
108
123
|
variant: {
|
|
109
124
|
sku: testData.skuWithoutTiers,
|
|
110
125
|
},
|
|
111
126
|
quantity: 1,
|
|
112
127
|
});
|
|
113
128
|
|
|
129
|
+
if (!cart.success) {
|
|
130
|
+
assert.fail();
|
|
131
|
+
}
|
|
132
|
+
|
|
114
133
|
const updatedCart = await client.cart.remove({
|
|
115
|
-
cart: cart.identifier,
|
|
116
|
-
item: cart.items[0].identifier,
|
|
134
|
+
cart: cart.value.identifier,
|
|
135
|
+
item: cart.value.items[0].identifier,
|
|
117
136
|
});
|
|
118
137
|
|
|
119
|
-
|
|
138
|
+
if (!updatedCart.success) {
|
|
139
|
+
assert.fail();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
expect(updatedCart.value.items.length).toBe(0);
|
|
120
143
|
});
|
|
121
144
|
|
|
122
145
|
it('should be able to delete a cart', async () => {
|
|
123
146
|
const cart = await client.cart.add({
|
|
124
|
-
cart: { key: '' },
|
|
125
147
|
variant: {
|
|
126
148
|
sku: testData.skuWithoutTiers,
|
|
127
149
|
},
|
|
128
150
|
quantity: 1,
|
|
129
151
|
});
|
|
130
152
|
|
|
131
|
-
|
|
132
|
-
|
|
153
|
+
if (!cart.success) {
|
|
154
|
+
assert.fail();
|
|
155
|
+
}
|
|
133
156
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
157
|
+
expect(cart.value.items.length).toBe(1);
|
|
158
|
+
expect(cart.value.identifier.key).toBeTruthy();
|
|
137
159
|
|
|
138
|
-
|
|
139
|
-
|
|
160
|
+
await client.cart.deleteCart({
|
|
161
|
+
cart: cart.value.identifier,
|
|
162
|
+
});
|
|
140
163
|
|
|
141
164
|
const originalCart = await client.cart.getById({
|
|
142
|
-
cart: cart.identifier,
|
|
165
|
+
cart: cart.value.identifier,
|
|
143
166
|
});
|
|
144
167
|
|
|
145
|
-
|
|
168
|
+
if (originalCart.success) {
|
|
169
|
+
assert.fail();
|
|
170
|
+
}
|
|
171
|
+
expect(originalCart.error.type).toBe('NotFound');
|
|
146
172
|
});
|
|
147
173
|
|
|
148
174
|
it('can load the product information for cart items', async () => {
|
|
149
175
|
const cart = await client.cart.add({
|
|
150
|
-
cart: { key: '' },
|
|
151
176
|
variant: {
|
|
152
177
|
sku: testData.skuWithoutTiers,
|
|
153
178
|
},
|
|
154
179
|
quantity: 1,
|
|
155
180
|
});
|
|
156
|
-
|
|
181
|
+
|
|
182
|
+
if (!cart.success) {
|
|
183
|
+
assert.fail();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
expect(cart.value.items[0].variant).toBeDefined();
|
|
157
187
|
|
|
158
188
|
const product = await client.product.getBySKU({
|
|
159
|
-
variant: cart.items[0].variant,
|
|
189
|
+
variant: cart.value.items[0].variant,
|
|
160
190
|
});
|
|
191
|
+
|
|
192
|
+
if (!product.success) {
|
|
193
|
+
assert.fail();
|
|
194
|
+
}
|
|
195
|
+
|
|
161
196
|
expect(product).toBeTruthy();
|
|
162
197
|
if (product) {
|
|
163
|
-
expect(product.mainVariant.identifier.sku).toEqual(
|
|
164
|
-
cart.items[0].variant.sku
|
|
198
|
+
expect(product.value.mainVariant.identifier.sku).toEqual(
|
|
199
|
+
cart.value.items[0].variant.sku
|
|
165
200
|
);
|
|
166
201
|
}
|
|
167
202
|
});
|
|
168
203
|
|
|
169
204
|
it('should be able to add an 50 items to a cart in less than 30 seconds', async () => {
|
|
170
|
-
let cart = await client.cart.getById({
|
|
171
|
-
cart: { key: '' },
|
|
172
|
-
});
|
|
173
|
-
|
|
174
205
|
const searchResult = await client.productSearch.queryByTerm(
|
|
175
206
|
ProductSearchQueryByTermSchema.parse({
|
|
176
207
|
search: {
|
|
@@ -184,25 +215,38 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Cart Capability - %s', (provider
|
|
|
184
215
|
},
|
|
185
216
|
} satisfies ProductSearchQueryByTerm)
|
|
186
217
|
);
|
|
187
|
-
expect(searchResult.items.length).toBeGreaterThanOrEqual(8);
|
|
188
218
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
219
|
+
if (!searchResult.success) {
|
|
220
|
+
assert.fail();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let cartIdentifier = undefined;
|
|
224
|
+
let cart = undefined;
|
|
225
|
+
expect(searchResult.value.items.length).toBeGreaterThanOrEqual(8);
|
|
226
|
+
|
|
227
|
+
for (const product of searchResult.value.items) {
|
|
228
|
+
const updated = await client.cart.add({
|
|
229
|
+
cart: cartIdentifier,
|
|
192
230
|
variant: {
|
|
193
231
|
sku: product.variants[0].variant.sku,
|
|
194
232
|
},
|
|
195
233
|
quantity: 1,
|
|
196
234
|
});
|
|
235
|
+
|
|
236
|
+
if (!updated.success) {
|
|
237
|
+
assert.fail();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
cart = updated;
|
|
241
|
+
cartIdentifier = updated.value.identifier;
|
|
197
242
|
}
|
|
198
243
|
|
|
199
244
|
if (cart) {
|
|
200
|
-
expect(cart.identifier.key).toBeDefined();
|
|
201
|
-
expect(cart.items.length).toBe(8);
|
|
245
|
+
expect(cart.value.identifier.key).toBeDefined();
|
|
246
|
+
expect(cart.value.items.length).toBe(8);
|
|
202
247
|
|
|
203
|
-
expect(cart.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
204
|
-
expect(cart.price.grandTotal.value).toBeGreaterThan(0);
|
|
205
|
-
expect(cart.meta?.placeholder).toBeFalsy();
|
|
248
|
+
expect(cart.value.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
249
|
+
expect(cart.value.price.grandTotal.value).toBeGreaterThan(0);
|
|
206
250
|
} else {
|
|
207
251
|
throw new Error('Cart is undefined');
|
|
208
252
|
}
|
|
@@ -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
|
const testData = {
|
|
@@ -36,12 +36,16 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
36
36
|
paginationOptions: { pageSize: 10, pageNumber: 1 },
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (!result.success) {
|
|
40
|
+
assert.fail();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
44
|
+
expect(result.value.items[0].identifier.key).toBe(testData.topCategories[0].key);
|
|
45
|
+
expect(result.value.items[0].name).toBe(testData.topCategories[0].name);
|
|
42
46
|
|
|
43
|
-
expect(result.items[1].identifier.key).toBe(testData.topCategories[1].key);
|
|
44
|
-
expect(result.items[1].name).toBe(testData.topCategories[1].name);
|
|
47
|
+
expect(result.value.items[1].identifier.key).toBe(testData.topCategories[1].key);
|
|
48
|
+
expect(result.value.items[1].name).toBe(testData.topCategories[1].name);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
it('should be able to get child categories for a category', async () => {
|
|
@@ -50,18 +54,22 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
50
54
|
paginationOptions: { pageSize: 10, pageNumber: 1 },
|
|
51
55
|
});
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
if (!result.success) {
|
|
58
|
+
assert.fail();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
62
|
+
expect(result.value.items[0].identifier.key).toBe(
|
|
55
63
|
testData.childCategoriesOfFirstTopcategory[0].key
|
|
56
64
|
);
|
|
57
|
-
expect(result.items[0].name).toBe(
|
|
65
|
+
expect(result.value.items[0].name).toBe(
|
|
58
66
|
testData.childCategoriesOfFirstTopcategory[0].name
|
|
59
67
|
);
|
|
60
68
|
|
|
61
|
-
expect(result.items[1].identifier.key).toBe(
|
|
69
|
+
expect(result.value.items[1].identifier.key).toBe(
|
|
62
70
|
testData.childCategoriesOfFirstTopcategory[1].key
|
|
63
71
|
);
|
|
64
|
-
expect(result.items[1].name).toBe(
|
|
72
|
+
expect(result.value.items[1].name).toBe(
|
|
65
73
|
testData.childCategoriesOfFirstTopcategory[1].name
|
|
66
74
|
);
|
|
67
75
|
});
|
|
@@ -71,35 +79,43 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
71
79
|
parentId: { key: testData.topCategories[0].key },
|
|
72
80
|
paginationOptions: { pageSize: 1, pageNumber: 1 },
|
|
73
81
|
});
|
|
82
|
+
|
|
83
|
+
if (!result.success) {
|
|
84
|
+
assert.fail();
|
|
85
|
+
}
|
|
74
86
|
|
|
75
|
-
expect(result.items.length).toBeGreaterThan(0);
|
|
76
|
-
expect(result.items[0].identifier.key).toBe(
|
|
87
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
88
|
+
expect(result.value.items[0].identifier.key).toBe(
|
|
77
89
|
testData.childCategoriesOfFirstTopcategory[0].key
|
|
78
90
|
);
|
|
79
|
-
expect(result.items[0].name).toBe(
|
|
91
|
+
expect(result.value.items[0].name).toBe(
|
|
80
92
|
testData.childCategoriesOfFirstTopcategory[0].name
|
|
81
93
|
);
|
|
82
|
-
expect(result.totalCount).toBe(3);
|
|
83
|
-
expect(result.totalPages).toBe(3);
|
|
84
|
-
expect(result.pageSize).toBe(1);
|
|
85
|
-
expect(result.pageNumber).toBe(1);
|
|
94
|
+
expect(result.value.totalCount).toBe(3);
|
|
95
|
+
expect(result.value.totalPages).toBe(3);
|
|
96
|
+
expect(result.value.pageSize).toBe(1);
|
|
97
|
+
expect(result.value.pageNumber).toBe(1);
|
|
86
98
|
|
|
87
99
|
result = await client.category.findChildCategories({
|
|
88
100
|
parentId: { key: testData.topCategories[0].key },
|
|
89
101
|
paginationOptions: { pageSize: 1, pageNumber: 2 },
|
|
90
102
|
});
|
|
91
103
|
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
if (!result.success) {
|
|
105
|
+
assert.fail();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
109
|
+
expect(result.value.items[0].identifier.key).toBe(
|
|
94
110
|
testData.childCategoriesOfFirstTopcategory[1].key
|
|
95
111
|
);
|
|
96
|
-
expect(result.items[0].name).toBe(
|
|
112
|
+
expect(result.value.items[0].name).toBe(
|
|
97
113
|
testData.childCategoriesOfFirstTopcategory[1].name
|
|
98
114
|
);
|
|
99
|
-
expect(result.totalCount).toBe(3);
|
|
100
|
-
expect(result.totalPages).toBe(3);
|
|
101
|
-
expect(result.pageSize).toBe(1);
|
|
102
|
-
expect(result.pageNumber).toBe(2);
|
|
115
|
+
expect(result.value.totalCount).toBe(3);
|
|
116
|
+
expect(result.value.totalPages).toBe(3);
|
|
117
|
+
expect(result.value.pageSize).toBe(1);
|
|
118
|
+
expect(result.value.pageNumber).toBe(2);
|
|
103
119
|
});
|
|
104
120
|
|
|
105
121
|
it('can load all breadcrumbs for a category', async () => {
|
|
@@ -108,9 +124,13 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
108
124
|
id: { key: leaf! },
|
|
109
125
|
});
|
|
110
126
|
|
|
111
|
-
|
|
127
|
+
if (!result.success) {
|
|
128
|
+
assert.fail();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
expect(result.value.length).toBe(testData.breadCrumb.length);
|
|
112
132
|
for (let i = 0; i < testData.breadCrumb.length; i++) {
|
|
113
|
-
expect(result[i].identifier.key).toBe(testData.breadCrumb[i]);
|
|
133
|
+
expect(result.value[i].identifier.key).toBe(testData.breadCrumb[i]);
|
|
114
134
|
}
|
|
115
135
|
});
|
|
116
136
|
|
|
@@ -118,20 +138,28 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
118
138
|
const result = await client.category.getBySlug({
|
|
119
139
|
slug: testData.topCategories[0].slug!,
|
|
120
140
|
});
|
|
121
|
-
|
|
141
|
+
|
|
142
|
+
if (!result.success) {
|
|
143
|
+
assert.fail();
|
|
144
|
+
}
|
|
145
|
+
|
|
122
146
|
if (result) {
|
|
123
|
-
expect(result.identifier.key).toBe(testData.topCategories[0].key);
|
|
124
|
-
expect(result.name).toBe(testData.topCategories[0].name);
|
|
125
|
-
expect(result.slug).toBe(testData.topCategories[0].slug);
|
|
126
|
-
expect(result.parentCategory).toBeUndefined();
|
|
127
|
-
expect(result.text).not.toBe('');
|
|
128
|
-
expect(result.meta.placeholder).toBe(false);
|
|
147
|
+
expect(result.value.identifier.key).toBe(testData.topCategories[0].key);
|
|
148
|
+
expect(result.value.name).toBe(testData.topCategories[0].name);
|
|
149
|
+
expect(result.value.slug).toBe(testData.topCategories[0].slug);
|
|
150
|
+
expect(result.value.parentCategory).toBeUndefined();
|
|
151
|
+
expect(result.value.text).not.toBe('');
|
|
129
152
|
}
|
|
130
153
|
});
|
|
131
154
|
|
|
132
|
-
it('returns
|
|
155
|
+
it('returns NotFound if looking for slug that does not exist', async () => {
|
|
133
156
|
const result = await client.category.getBySlug({ slug: 'non-existent-slug' });
|
|
134
|
-
|
|
157
|
+
|
|
158
|
+
if (result.success) {
|
|
159
|
+
assert.fail();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
expect(result.error.type).toBe('NotFound');
|
|
135
163
|
});
|
|
136
164
|
|
|
137
165
|
it('should be able to get a category by id', async () => {
|
|
@@ -139,20 +167,27 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Category Capability - %s', (prov
|
|
|
139
167
|
id: { key: testData.topCategories[0].key },
|
|
140
168
|
});
|
|
141
169
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
170
|
+
if (!result.success) {
|
|
171
|
+
assert.fail();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
expect(result.value.identifier.key).toBe(testData.topCategories[0].key);
|
|
175
|
+
expect(result.value.name).toBe(testData.topCategories[0].name);
|
|
176
|
+
expect(result.value.slug).toBe(testData.topCategories[0].slug);
|
|
177
|
+
expect(result.value.parentCategory).toBeUndefined();
|
|
146
178
|
|
|
147
|
-
expect(result.text).toBe(testData.topCategories[0].text);
|
|
148
|
-
expect(result.meta.placeholder).toBe(false);
|
|
179
|
+
expect(result.value.text).toBe(testData.topCategories[0].text);
|
|
149
180
|
});
|
|
150
181
|
|
|
151
|
-
it('returns
|
|
182
|
+
it('returns NotFound if you search for a category that does not exist', async () => {
|
|
152
183
|
const result = await client.category.getById({
|
|
153
184
|
id: { key: 'non-existent-category' },
|
|
154
185
|
});
|
|
155
|
-
|
|
156
|
-
|
|
186
|
+
|
|
187
|
+
if (result.success) {
|
|
188
|
+
assert.fail();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
expect(result.error.type).toBe('NotFound');
|
|
157
192
|
});
|
|
158
193
|
});
|