@reactionary/examples-node 0.3.14 → 0.3.16
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.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.3.
|
|
8
|
-
"@reactionary/provider-commercetools": "0.3.
|
|
9
|
-
"@reactionary/provider-algolia": "0.3.
|
|
10
|
-
"@reactionary/provider-medusa": "0.3.
|
|
11
|
-
"@reactionary/provider-meilisearch": "0.3.
|
|
12
|
-
"@reactionary/provider-fake": "0.3.
|
|
7
|
+
"@reactionary/core": "0.3.16",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.3.16",
|
|
9
|
+
"@reactionary/provider-algolia": "0.3.16",
|
|
10
|
+
"@reactionary/provider-medusa": "0.3.16",
|
|
11
|
+
"@reactionary/provider-meilisearch": "0.3.16",
|
|
12
|
+
"@reactionary/provider-fake": "0.3.16"
|
|
13
13
|
},
|
|
14
14
|
"type": "module"
|
|
15
15
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
|
+
import type { ProductSearchQueryCreateNavigationFilter } from '@reactionary/core';
|
|
5
|
+
|
|
6
|
+
const testData = {
|
|
7
|
+
productWithAssociations: {
|
|
8
|
+
id: 'product_102456',
|
|
9
|
+
},
|
|
10
|
+
productWithoutAssociations: {
|
|
11
|
+
id: 'product_100201',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe.each([PrimaryProvider.FAKE, PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA] )(
|
|
16
|
+
'Product Associations - %s',
|
|
17
|
+
(provider) => {
|
|
18
|
+
let client: ReturnType<typeof createClient>;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
client = createClient(provider);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('Accessories', () => {
|
|
25
|
+
it('should be able to return a list of accessories for a product that has them', async () => {
|
|
26
|
+
const result = await client.productAssociations.getAccessories({
|
|
27
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
28
|
+
numberOfAccessories: 4,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
assert.fail(JSON.stringify(result.error));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
36
|
+
const firstResult = result.value[0];
|
|
37
|
+
expect(firstResult.associationReturnType).toBe('productSearchResultItem');
|
|
38
|
+
if (firstResult.associationReturnType === 'productSearchResultItem') {
|
|
39
|
+
expect(firstResult.product.identifier.key).toBeDefined();
|
|
40
|
+
expect(firstResult.product.name).toBeDefined();
|
|
41
|
+
expect(firstResult.product.slug).toBeDefined();
|
|
42
|
+
expect(firstResult.product.variants).toBeDefined();
|
|
43
|
+
expect(firstResult.product.variants.length).toBeGreaterThan(0);
|
|
44
|
+
expect(firstResult.product.variants[0].variant.sku).toBeDefined();
|
|
45
|
+
expect(firstResult.product.variants[0].image.sourceUrl).toBeDefined();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('can return a subset of the full list', async () => {
|
|
50
|
+
const result = await client.productAssociations.getAccessories({
|
|
51
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
52
|
+
numberOfAccessories: 2,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (!result.success) {
|
|
56
|
+
assert.fail(JSON.stringify(result.error));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
expect(result.value.length).toBe(2);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
it('should return an empty list for a product that has no accessories', async () => {
|
|
64
|
+
const result = await client.productAssociations.getAccessories({
|
|
65
|
+
forProduct: { key: testData.productWithoutAssociations.id },
|
|
66
|
+
numberOfAccessories: 4,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!result.success) {
|
|
70
|
+
assert.fail(JSON.stringify(result.error));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
expect(result.value.length).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should return an empty result for an unknown product', async () => {
|
|
77
|
+
const result = await client.productAssociations.getAccessories({
|
|
78
|
+
forProduct: {
|
|
79
|
+
key: 'unknown-product-id',
|
|
80
|
+
},
|
|
81
|
+
numberOfAccessories: 4,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (!result.success) {
|
|
85
|
+
assert.fail(JSON.stringify(result.error));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
expect(result.value.length).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
describe('Spareparts', () => {
|
|
95
|
+
it('should be able to return a list of spareparts for a product that has them', async () => {
|
|
96
|
+
const result = await client.productAssociations.getSpareparts({
|
|
97
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
98
|
+
numberOfSpareparts: 4,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (!result.success) {
|
|
102
|
+
assert.fail(JSON.stringify(result.error));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
106
|
+
const firstResult = result.value[0];
|
|
107
|
+
expect(firstResult.associationReturnType).toBe('productSearchResultItem');
|
|
108
|
+
if (firstResult.associationReturnType === 'productSearchResultItem') {
|
|
109
|
+
expect(firstResult.product.identifier.key).toBeDefined();
|
|
110
|
+
expect(firstResult.product.name).toBeDefined();
|
|
111
|
+
expect(firstResult.product.slug).toBeDefined();
|
|
112
|
+
expect(firstResult.product.variants).toBeDefined();
|
|
113
|
+
expect(firstResult.product.variants.length).toBeGreaterThan(0);
|
|
114
|
+
expect(firstResult.product.variants[0].variant.sku).toBeDefined();
|
|
115
|
+
expect(firstResult.product.variants[0].image.sourceUrl).toBeDefined();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('can return a subset of the full list', async () => {
|
|
120
|
+
const result = await client.productAssociations.getSpareparts({
|
|
121
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
122
|
+
numberOfSpareparts: 1,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (!result.success) {
|
|
126
|
+
assert.fail(JSON.stringify(result.error));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
expect(result.value.length).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
it('should return an empty list for a product that has no spareparts', async () => {
|
|
134
|
+
const result = await client.productAssociations.getSpareparts({
|
|
135
|
+
forProduct: { key: testData.productWithoutAssociations.id },
|
|
136
|
+
numberOfSpareparts: 4,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (!result.success) {
|
|
140
|
+
assert.fail(JSON.stringify(result.error));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
expect(result.value.length).toBe(0);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should return an empty result for an unknown product', async () => {
|
|
147
|
+
const result = await client.productAssociations.getSpareparts({
|
|
148
|
+
forProduct: {
|
|
149
|
+
key: 'unknown-product-id',
|
|
150
|
+
},
|
|
151
|
+
numberOfSpareparts: 4,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!result.success) {
|
|
155
|
+
assert.fail(JSON.stringify(result.error));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
expect(result.value.length).toBe(0);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
describe('Replacements', () => {
|
|
166
|
+
it.skip('should be able to return a list of replacements for a product that has them', async () => {
|
|
167
|
+
const result = await client.productAssociations.getReplacements({
|
|
168
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
169
|
+
numberOfReplacements: 4,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (!result.success) {
|
|
173
|
+
assert.fail(JSON.stringify(result.error));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
177
|
+
const firstResult = result.value[0];
|
|
178
|
+
expect(firstResult.associationReturnType).toBe('productSearchResultItem');
|
|
179
|
+
if (firstResult.associationReturnType === 'productSearchResultItem') {
|
|
180
|
+
expect(firstResult.product.identifier.key).toBeDefined();
|
|
181
|
+
expect(firstResult.product.name).toBeDefined();
|
|
182
|
+
expect(firstResult.product.slug).toBeDefined();
|
|
183
|
+
expect(firstResult.product.variants).toBeDefined();
|
|
184
|
+
expect(firstResult.product.variants.length).toBeGreaterThan(0);
|
|
185
|
+
expect(firstResult.product.variants[0].variant.sku).toBeDefined();
|
|
186
|
+
expect(firstResult.product.variants[0].image.sourceUrl).toBeDefined();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it.skip('can return a subset of the full list', async () => {
|
|
191
|
+
const result = await client.productAssociations.getReplacements({
|
|
192
|
+
forProduct: { key: testData.productWithAssociations.id },
|
|
193
|
+
numberOfReplacements: 1,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (!result.success) {
|
|
197
|
+
assert.fail(JSON.stringify(result.error));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
expect(result.value.length).toBe(1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
it('should return an empty list for a product that has no replacements', async () => {
|
|
205
|
+
const result = await client.productAssociations.getReplacements({
|
|
206
|
+
forProduct: { key: testData.productWithoutAssociations.id },
|
|
207
|
+
numberOfReplacements: 4,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (!result.success) {
|
|
211
|
+
assert.fail(JSON.stringify(result.error));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
expect(result.value.length).toBe(0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('should return an empty result for an unknown product', async () => {
|
|
218
|
+
const result = await client.productAssociations.getReplacements({
|
|
219
|
+
forProduct: {
|
|
220
|
+
key: 'unknown-product-id',
|
|
221
|
+
},
|
|
222
|
+
numberOfReplacements: 4,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
if (!result.success) {
|
|
226
|
+
assert.fail(JSON.stringify(result.error));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
expect(result.value.length).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
});
|
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
|
+
import type {
|
|
5
|
+
ProductList,
|
|
6
|
+
ProductSearchQueryCreateNavigationFilter,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
|
|
9
|
+
const testData = {
|
|
10
|
+
product1: {
|
|
11
|
+
sku: '0766623170703',
|
|
12
|
+
},
|
|
13
|
+
product2: {
|
|
14
|
+
sku: '0766623301831',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
19
|
+
'Product List - %s',
|
|
20
|
+
(provider) => {
|
|
21
|
+
let client: ReturnType<typeof createClient>;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
client = createClient(provider);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('Lists', () => {
|
|
28
|
+
describe('Anonymous', () => {
|
|
29
|
+
it('cannot create a new favorite list', async () => {
|
|
30
|
+
const result = await client.productList.addList({
|
|
31
|
+
list: {
|
|
32
|
+
type: 'favorite',
|
|
33
|
+
name: 'My favorite list',
|
|
34
|
+
published: true,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(result.success).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('Registered', () => {
|
|
42
|
+
beforeEach(async () => {
|
|
43
|
+
// create new user and set context to that user, so we have a clean slate for the product lists
|
|
44
|
+
const user = await client.identity.register({
|
|
45
|
+
username: `test-${Math.random()}@example.com`,
|
|
46
|
+
password: 'password',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!user.success) {
|
|
50
|
+
assert.fail('Failed to create user for testing product lists');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const self = await client.identity.getSelf({});
|
|
54
|
+
if (!self.success) {
|
|
55
|
+
assert.fail('Failed to get self for testing product lists');
|
|
56
|
+
}
|
|
57
|
+
if (self.value.type !== 'Registered') {
|
|
58
|
+
assert.fail('User is not registered');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('can create a new favorite list', async () => {
|
|
63
|
+
const result = await client.productList.addList({
|
|
64
|
+
list: {
|
|
65
|
+
type: 'favorite',
|
|
66
|
+
name: 'My favorite list',
|
|
67
|
+
published: true,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
expect(result.success).toBe(true);
|
|
71
|
+
if (!result.success) {
|
|
72
|
+
assert.fail(JSON.stringify(result.error));
|
|
73
|
+
}
|
|
74
|
+
expect(result.value.name).toBe('My favorite list');
|
|
75
|
+
expect(result.value.type).toBe('favorite');
|
|
76
|
+
expect(result.value.published).toBe(true);
|
|
77
|
+
expect(result.value.identifier).toBeDefined();
|
|
78
|
+
expect(result.value.identifier.key).toBeDefined();
|
|
79
|
+
expect(result.value.identifier.listType).toBe('favorite');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('can create a new wishlist', async () => {
|
|
83
|
+
const result = await client.productList.addList({
|
|
84
|
+
list: {
|
|
85
|
+
type: 'wish',
|
|
86
|
+
name: 'My wishlist',
|
|
87
|
+
published: true,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
expect(result.success).toBe(true);
|
|
91
|
+
if (!result.success) {
|
|
92
|
+
assert.fail(JSON.stringify(result.error));
|
|
93
|
+
}
|
|
94
|
+
expect(result.value.name).toBe('My wishlist');
|
|
95
|
+
expect(result.value.type).toBe('wish');
|
|
96
|
+
expect(result.value.published).toBe(true);
|
|
97
|
+
expect(result.value.identifier).toBeDefined();
|
|
98
|
+
expect(result.value.identifier.key).toBeDefined();
|
|
99
|
+
expect(result.value.identifier.listType).toBe('wish');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('can create a new shopping list', async () => {
|
|
103
|
+
const result = await client.productList.addList({
|
|
104
|
+
list: {
|
|
105
|
+
type: 'shopping',
|
|
106
|
+
name: 'My shopping list',
|
|
107
|
+
published: true,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
expect(result.success).toBe(true);
|
|
111
|
+
if (!result.success) {
|
|
112
|
+
assert.fail(JSON.stringify(result.error));
|
|
113
|
+
}
|
|
114
|
+
expect(result.value.name).toBe('My shopping list');
|
|
115
|
+
expect(result.value.type).toBe('shopping');
|
|
116
|
+
expect(result.value.published).toBe(true);
|
|
117
|
+
expect(result.value.identifier).toBeDefined();
|
|
118
|
+
expect(result.value.identifier.key).toBeDefined();
|
|
119
|
+
expect(result.value.identifier.listType).toBe('shopping');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('can create a new requisition list', async () => {
|
|
123
|
+
const result = await client.productList.addList({
|
|
124
|
+
list: {
|
|
125
|
+
type: 'requisition',
|
|
126
|
+
name: 'My requisition list',
|
|
127
|
+
published: true,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
expect(result.success).toBe(true);
|
|
131
|
+
if (!result.success) {
|
|
132
|
+
assert.fail(JSON.stringify(result.error));
|
|
133
|
+
}
|
|
134
|
+
expect(result.value.name).toBe('My requisition list');
|
|
135
|
+
expect(result.value.type).toBe('requisition');
|
|
136
|
+
expect(result.value.published).toBe(true);
|
|
137
|
+
expect(result.value.identifier).toBeDefined();
|
|
138
|
+
expect(result.value.identifier.key).toBeDefined();
|
|
139
|
+
expect(result.value.identifier.listType).toBe('requisition');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('can get a list by id', async () => {
|
|
143
|
+
const result = await client.productList.addList({
|
|
144
|
+
list: {
|
|
145
|
+
type: 'requisition',
|
|
146
|
+
name: 'My requisition list',
|
|
147
|
+
published: true,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(result.success).toBe(true);
|
|
151
|
+
if (!result.success) {
|
|
152
|
+
assert.fail(JSON.stringify(result.error));
|
|
153
|
+
}
|
|
154
|
+
const createdList = await client.productList.getById({
|
|
155
|
+
identifier: result.value.identifier,
|
|
156
|
+
});
|
|
157
|
+
expect(createdList.success).toBe(true);
|
|
158
|
+
if (!createdList.success) {
|
|
159
|
+
assert.fail(JSON.stringify(createdList.error));
|
|
160
|
+
}
|
|
161
|
+
expect(createdList.value.name).toBe('My requisition list');
|
|
162
|
+
expect(createdList.value.type).toBe('requisition');
|
|
163
|
+
expect(createdList.value.published).toBe(true);
|
|
164
|
+
expect(createdList.value.identifier).toEqual(result.value.identifier);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('can filter lists by type', async () => {
|
|
168
|
+
const result = await client.productList.addList({
|
|
169
|
+
list: {
|
|
170
|
+
type: 'shopping',
|
|
171
|
+
name: 'My shopping list',
|
|
172
|
+
published: true,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
const result2 = await client.productList.addList({
|
|
176
|
+
list: {
|
|
177
|
+
type: 'wish',
|
|
178
|
+
name: 'My wishlist',
|
|
179
|
+
published: true,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
expect(result.success).toBe(true);
|
|
184
|
+
expect(result2.success).toBe(true);
|
|
185
|
+
|
|
186
|
+
if (result.success && result2.success) {
|
|
187
|
+
const shoppingLists = await client.productList.queryLists({
|
|
188
|
+
search: {
|
|
189
|
+
listType: 'shopping',
|
|
190
|
+
paginationOptions: {
|
|
191
|
+
pageNumber: 1,
|
|
192
|
+
pageSize: 10,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
expect(shoppingLists.success).toBe(true);
|
|
197
|
+
if (shoppingLists.success) {
|
|
198
|
+
expect(shoppingLists.value.items.length).toBe(1);
|
|
199
|
+
expect(shoppingLists.value.items[0].type).toBe('shopping');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const wishLists = await client.productList.queryLists({
|
|
203
|
+
search: {
|
|
204
|
+
listType: 'wish',
|
|
205
|
+
paginationOptions: {
|
|
206
|
+
pageNumber: 1,
|
|
207
|
+
pageSize: 10,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
expect(wishLists.success).toBe(true);
|
|
212
|
+
if (!wishLists.success) {
|
|
213
|
+
assert.fail(JSON.stringify(wishLists.error));
|
|
214
|
+
}
|
|
215
|
+
expect(wishLists.value.items.length).toBe(1);
|
|
216
|
+
expect(wishLists.value.items[0].type).toBe('wish');
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('can pageinate through lists', async () => {
|
|
221
|
+
for (let i = 0; i < 3; i++) {
|
|
222
|
+
const result = await client.productList.addList({
|
|
223
|
+
list: {
|
|
224
|
+
type: 'favorite',
|
|
225
|
+
name: `My favorite list ${i}`,
|
|
226
|
+
published: true,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
expect(result.success).toBe(true);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const paginatedResult = await client.productList.queryLists({
|
|
233
|
+
search: {
|
|
234
|
+
listType: 'favorite',
|
|
235
|
+
paginationOptions: {
|
|
236
|
+
pageNumber: 1,
|
|
237
|
+
pageSize: 2,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(paginatedResult.success).toBe(true);
|
|
243
|
+
if (!paginatedResult.success) {
|
|
244
|
+
assert.fail(JSON.stringify(paginatedResult.error));
|
|
245
|
+
}
|
|
246
|
+
expect(paginatedResult.value.items.length).toBe(2);
|
|
247
|
+
expect(paginatedResult.value.pageNumber).toBe(1);
|
|
248
|
+
expect(paginatedResult.value.pageSize).toBe(2);
|
|
249
|
+
expect(paginatedResult.value.totalCount).toBeGreaterThanOrEqual(3);
|
|
250
|
+
expect(paginatedResult.value.totalPages).toBeGreaterThanOrEqual(2);
|
|
251
|
+
|
|
252
|
+
const page2 = await client.productList.queryLists({
|
|
253
|
+
search: {
|
|
254
|
+
...paginatedResult.value.identifier,
|
|
255
|
+
paginationOptions: {
|
|
256
|
+
pageNumber: 2,
|
|
257
|
+
pageSize: 2,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
expect(page2.success).toBe(true);
|
|
263
|
+
if (!page2.success) {
|
|
264
|
+
assert.fail(JSON.stringify(page2.error));
|
|
265
|
+
}
|
|
266
|
+
expect(page2.value.items.length).toBeGreaterThanOrEqual(1);
|
|
267
|
+
expect(page2.value.pageNumber).toBe(2);
|
|
268
|
+
expect(page2.value.pageSize).toBe(2);
|
|
269
|
+
expect(page2.value.totalCount).toBeGreaterThanOrEqual(3);
|
|
270
|
+
expect(page2.value.totalPages).toBeGreaterThanOrEqual(2);
|
|
271
|
+
|
|
272
|
+
expect(page2.value.items[0].identifier).not.toEqual(
|
|
273
|
+
paginatedResult.value.items[0].identifier,
|
|
274
|
+
);
|
|
275
|
+
expect(page2.value.items[0].identifier).not.toEqual(
|
|
276
|
+
paginatedResult.value.items[1].identifier,
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('can rename a list', async () => {
|
|
281
|
+
const result = await client.productList.addList({
|
|
282
|
+
list: {
|
|
283
|
+
type: 'favorite',
|
|
284
|
+
name: `My favorite list`,
|
|
285
|
+
published: true,
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
expect(result.success).toBe(true);
|
|
290
|
+
if (!result.success) {
|
|
291
|
+
assert.fail(JSON.stringify(result.error));
|
|
292
|
+
}
|
|
293
|
+
const updatedList = await client.productList.updateList({
|
|
294
|
+
list: result.value.identifier,
|
|
295
|
+
name: 'My renamed favorite list',
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
expect(updatedList.success).toBe(true);
|
|
299
|
+
if (updatedList.success) {
|
|
300
|
+
expect(updatedList.value.name).toBe('My renamed favorite list');
|
|
301
|
+
expect(updatedList.value.identifier).toEqual(
|
|
302
|
+
result.value.identifier,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('can update the description and other metadata of a list', async () => {
|
|
308
|
+
const result = await client.productList.addList({
|
|
309
|
+
list: {
|
|
310
|
+
type: 'favorite',
|
|
311
|
+
name: `My favorite list`,
|
|
312
|
+
published: true,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
expect(result.success).toBe(true);
|
|
317
|
+
if (!result.success) {
|
|
318
|
+
assert.fail(JSON.stringify(result.error));
|
|
319
|
+
}
|
|
320
|
+
const updatedList = await client.productList.updateList({
|
|
321
|
+
list: result.value.identifier,
|
|
322
|
+
description: 'my description of the list',
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
expect(updatedList.success).toBe(true);
|
|
326
|
+
if (!updatedList.success) {
|
|
327
|
+
assert.fail(JSON.stringify(updatedList.error));
|
|
328
|
+
}
|
|
329
|
+
expect(updatedList.value.description).toBe(
|
|
330
|
+
'my description of the list',
|
|
331
|
+
);
|
|
332
|
+
expect(updatedList.value.identifier).toEqual(result.value.identifier);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('can delete a list', async () => {
|
|
336
|
+
const result = await client.productList.addList({
|
|
337
|
+
list: {
|
|
338
|
+
type: 'favorite',
|
|
339
|
+
name: `My favorite list`,
|
|
340
|
+
published: true,
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
expect(result.success).toBe(true);
|
|
345
|
+
if (!result.success) {
|
|
346
|
+
assert.fail(JSON.stringify(result.error));
|
|
347
|
+
}
|
|
348
|
+
const deleteResult = await client.productList.deleteList({
|
|
349
|
+
list: result.value.identifier,
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
if (!deleteResult.success) {
|
|
353
|
+
assert.fail(JSON.stringify(deleteResult.error));
|
|
354
|
+
}
|
|
355
|
+
const getResult = await client.productList.getById({
|
|
356
|
+
identifier: result.value.identifier,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(getResult.success).toBe(false);
|
|
360
|
+
if (getResult.success) {
|
|
361
|
+
assert.fail('Should not be able to get a deleted list');
|
|
362
|
+
}
|
|
363
|
+
expect(getResult.error.type).toBe('NotFound');
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe('Items', () => {
|
|
369
|
+
let list: ProductList;
|
|
370
|
+
|
|
371
|
+
beforeEach(async () => {
|
|
372
|
+
// create new user and set context to that user, so we have a clean slate for the product lists
|
|
373
|
+
const user = await client.identity.register({
|
|
374
|
+
username: `test-${Math.random()}@example.com`,
|
|
375
|
+
password: 'password',
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
if (!user.success) {
|
|
379
|
+
assert.fail('Failed to create user for testing product lists');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const self = await client.identity.getSelf({});
|
|
383
|
+
if (!self.success) {
|
|
384
|
+
assert.fail('Failed to get self for testing product lists');
|
|
385
|
+
}
|
|
386
|
+
if (self.value.type !== 'Registered') {
|
|
387
|
+
assert.fail('User is not registered');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const result = await client.productList.addList({
|
|
391
|
+
list: {
|
|
392
|
+
type: 'favorite',
|
|
393
|
+
name: `My favorite list`,
|
|
394
|
+
published: true,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
expect(result.success).toBe(true);
|
|
398
|
+
if (!result.success) {
|
|
399
|
+
assert.fail(JSON.stringify(result.error));
|
|
400
|
+
}
|
|
401
|
+
list = result.value;
|
|
402
|
+
expect(list.identifier).toBeDefined();
|
|
403
|
+
expect(list.identifier.key).toBeDefined();
|
|
404
|
+
expect(list.identifier.listType).toBe('favorite');
|
|
405
|
+
expect(list.type).toBe('favorite');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('can query items in an empty list', async () => {
|
|
409
|
+
const result = await client.productList.queryListItems({
|
|
410
|
+
search: {
|
|
411
|
+
list: list.identifier,
|
|
412
|
+
paginationOptions: {
|
|
413
|
+
pageNumber: 1,
|
|
414
|
+
pageSize: 10,
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
expect(result.success).toBe(true);
|
|
420
|
+
if (!result.success) {
|
|
421
|
+
assert.fail(JSON.stringify(result.error));
|
|
422
|
+
}
|
|
423
|
+
expect(result.value.items.length).toBe(0);
|
|
424
|
+
expect(result.value.pageNumber).toBe(1);
|
|
425
|
+
expect(result.value.pageSize).toBe(10);
|
|
426
|
+
expect(result.value.totalCount).toBe(0);
|
|
427
|
+
expect(result.value.totalPages).toBe(0);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('can add an item to a list', async () => {
|
|
431
|
+
const result = await client.productList.addItem({
|
|
432
|
+
list: list.identifier,
|
|
433
|
+
listItem: {
|
|
434
|
+
variant: {
|
|
435
|
+
sku: testData.product1.sku,
|
|
436
|
+
},
|
|
437
|
+
quantity: 2,
|
|
438
|
+
notes: 'This is a note about the item',
|
|
439
|
+
order: 0,
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
if (!result.success) {
|
|
444
|
+
assert.fail(JSON.stringify(result.error));
|
|
445
|
+
}
|
|
446
|
+
expect(result.value.identifier).toBeDefined();
|
|
447
|
+
expect(result.value.identifier.key).toBeDefined();
|
|
448
|
+
expect(result.value.identifier.list).toEqual(list.identifier);
|
|
449
|
+
expect(result.value.variant.sku).toBe(testData.product1.sku);
|
|
450
|
+
expect(result.value.quantity).toBe(2);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it('can query items in an non-empty list', async () => {
|
|
454
|
+
const result = await client.productList.addItem({
|
|
455
|
+
list: list.identifier,
|
|
456
|
+
listItem: {
|
|
457
|
+
variant: {
|
|
458
|
+
sku: testData.product1.sku,
|
|
459
|
+
},
|
|
460
|
+
quantity: 2,
|
|
461
|
+
notes: 'This is a note about the item',
|
|
462
|
+
order: 0,
|
|
463
|
+
},
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
if (!result.success) {
|
|
467
|
+
assert.fail(JSON.stringify(result.error));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const result2 = await client.productList.queryListItems({
|
|
471
|
+
search: {
|
|
472
|
+
list: list.identifier,
|
|
473
|
+
paginationOptions: {
|
|
474
|
+
pageNumber: 1,
|
|
475
|
+
pageSize: 10,
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
if (!result2.success) {
|
|
481
|
+
assert.fail(JSON.stringify(result2.error));
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
expect(result2.success).toBe(true);
|
|
485
|
+
expect(result2.value.items.length).toBe(1);
|
|
486
|
+
expect(result2.value.pageNumber).toBe(1);
|
|
487
|
+
expect(result2.value.pageSize).toBe(10);
|
|
488
|
+
expect(result2.value.totalCount).toBe(1);
|
|
489
|
+
expect(result2.value.totalPages).toBe(1);
|
|
490
|
+
|
|
491
|
+
expect(result2.value.items[0].identifier).toEqual(
|
|
492
|
+
result.value.identifier,
|
|
493
|
+
);
|
|
494
|
+
expect(result2.value.items[0].variant.sku).toBe(testData.product1.sku);
|
|
495
|
+
expect(result2.value.items[0].quantity).toBe(2);
|
|
496
|
+
expect(result2.value.items[0].notes).toBe(
|
|
497
|
+
'This is a note about the item',
|
|
498
|
+
);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it('can remove an item from a list', async () => {
|
|
502
|
+
const addResult = await client.productList.addItem({
|
|
503
|
+
list: list.identifier,
|
|
504
|
+
listItem: {
|
|
505
|
+
variant: {
|
|
506
|
+
sku: testData.product1.sku,
|
|
507
|
+
},
|
|
508
|
+
quantity: 2,
|
|
509
|
+
notes: 'This is a note about the item',
|
|
510
|
+
order: 0,
|
|
511
|
+
},
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
expect(addResult.success).toBe(true);
|
|
515
|
+
if (!addResult.success) {
|
|
516
|
+
assert.fail(JSON.stringify(addResult.error));
|
|
517
|
+
}
|
|
518
|
+
const deleteResult = await client.productList.deleteItem({
|
|
519
|
+
listItem: addResult.value.identifier,
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
if (!deleteResult.success) {
|
|
523
|
+
assert.fail(JSON.stringify(deleteResult.error));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const result2 = await client.productList.queryListItems({
|
|
527
|
+
search: {
|
|
528
|
+
list: list.identifier,
|
|
529
|
+
paginationOptions: {
|
|
530
|
+
pageNumber: 1,
|
|
531
|
+
pageSize: 10,
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
if (!result2.success) {
|
|
537
|
+
assert.fail(JSON.stringify(result2.error));
|
|
538
|
+
}
|
|
539
|
+
expect(result2.value.items.length).toBe(0);
|
|
540
|
+
expect(result2.value.pageNumber).toBe(1);
|
|
541
|
+
expect(result2.value.pageSize).toBe(10);
|
|
542
|
+
expect(result2.value.totalCount).toBe(0);
|
|
543
|
+
expect(result2.value.totalPages).toBe(0);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it('can update the quantity of an item in a list', async () => {
|
|
547
|
+
const result = await client.productList.addItem({
|
|
548
|
+
list: list.identifier,
|
|
549
|
+
listItem: {
|
|
550
|
+
variant: {
|
|
551
|
+
sku: testData.product1.sku,
|
|
552
|
+
},
|
|
553
|
+
quantity: 2,
|
|
554
|
+
notes: 'This is a note about the item',
|
|
555
|
+
order: 0,
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
if (!result.success) {
|
|
559
|
+
assert.fail(JSON.stringify(result.error));
|
|
560
|
+
}
|
|
561
|
+
const updatedItem = await client.productList.updateItem({
|
|
562
|
+
listItem: result.value.identifier,
|
|
563
|
+
quantity: 5,
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
if (!updatedItem.success) {
|
|
567
|
+
console.log(updatedItem.error);
|
|
568
|
+
assert.fail();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
expect(updatedItem.value.quantity).toBe(5);
|
|
572
|
+
expect(updatedItem.value.identifier).toEqual(result.value.identifier);
|
|
573
|
+
|
|
574
|
+
const result2 = await client.productList.queryListItems({
|
|
575
|
+
search: {
|
|
576
|
+
list: list.identifier,
|
|
577
|
+
paginationOptions: {
|
|
578
|
+
pageNumber: 1,
|
|
579
|
+
pageSize: 10,
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
if (!result2.success) {
|
|
585
|
+
assert.fail(JSON.stringify(result2.error));
|
|
586
|
+
}
|
|
587
|
+
expect(result2.value.items.length).toBe(1);
|
|
588
|
+
expect(result2.value.pageNumber).toBe(1);
|
|
589
|
+
expect(result2.value.pageSize).toBe(10);
|
|
590
|
+
expect(result2.value.totalCount).toBe(1);
|
|
591
|
+
expect(result2.value.totalPages).toBe(1);
|
|
592
|
+
|
|
593
|
+
expect(result2.value.items[0].identifier).toEqual(
|
|
594
|
+
result.value.identifier,
|
|
595
|
+
);
|
|
596
|
+
expect(result2.value.items[0].variant.sku).toBe(testData.product1.sku);
|
|
597
|
+
expect(result2.value.items[0].quantity).toBe(5);
|
|
598
|
+
expect(result2.value.items[0].notes).toBe(
|
|
599
|
+
'This is a note about the item',
|
|
600
|
+
);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('can update the notes of an item in a list', async () => {
|
|
604
|
+
const result = await client.productList.addItem({
|
|
605
|
+
list: list.identifier,
|
|
606
|
+
listItem: {
|
|
607
|
+
variant: {
|
|
608
|
+
sku: testData.product1.sku,
|
|
609
|
+
},
|
|
610
|
+
quantity: 2,
|
|
611
|
+
notes: 'This is a note about the item',
|
|
612
|
+
order: 0,
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
if (!result.success) {
|
|
616
|
+
assert.fail(JSON.stringify(result.error));
|
|
617
|
+
}
|
|
618
|
+
const updatedItem = await client.productList.updateItem({
|
|
619
|
+
listItem: result.value.identifier,
|
|
620
|
+
notes: 'This is an updated note about the item',
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
if (!updatedItem.success) {
|
|
624
|
+
console.log(updatedItem.error);
|
|
625
|
+
assert.fail();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
expect(updatedItem.value.notes).toBe('This is an updated note about the item');
|
|
629
|
+
expect(updatedItem.value.identifier).toEqual(result.value.identifier);
|
|
630
|
+
|
|
631
|
+
const result2 = await client.productList.queryListItems({
|
|
632
|
+
search: {
|
|
633
|
+
list: list.identifier,
|
|
634
|
+
paginationOptions: {
|
|
635
|
+
pageNumber: 1,
|
|
636
|
+
pageSize: 10,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
if (!result2.success) {
|
|
642
|
+
assert.fail(JSON.stringify(result2.error));
|
|
643
|
+
}
|
|
644
|
+
expect(result2.value.items.length).toBe(1);
|
|
645
|
+
expect(result2.value.pageNumber).toBe(1);
|
|
646
|
+
expect(result2.value.pageSize).toBe(10);
|
|
647
|
+
expect(result2.value.totalCount).toBe(1);
|
|
648
|
+
expect(result2.value.totalPages).toBe(1);
|
|
649
|
+
|
|
650
|
+
expect(result2.value.items[0].identifier).toEqual(
|
|
651
|
+
result.value.identifier,
|
|
652
|
+
);
|
|
653
|
+
expect(result2.value.items[0].variant.sku).toBe(testData.product1.sku);
|
|
654
|
+
expect(result2.value.items[0].quantity).toBe(2);
|
|
655
|
+
expect(result2.value.items[0].notes).toBe(
|
|
656
|
+
'This is an updated note about the item',
|
|
657
|
+
);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
it('cannot have a quantity of 0 or less', async () => {
|
|
661
|
+
const result = await client.productList.addItem({
|
|
662
|
+
list: list.identifier,
|
|
663
|
+
listItem: {
|
|
664
|
+
variant: {
|
|
665
|
+
sku: testData.product1.sku,
|
|
666
|
+
},
|
|
667
|
+
quantity: 0,
|
|
668
|
+
notes: 'This is a note about the item',
|
|
669
|
+
order: 0,
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
if (result.success) {
|
|
673
|
+
assert.fail('Should not be able to add an item with quantity of 0');
|
|
674
|
+
}
|
|
675
|
+
expect(result.success).toBe(false);
|
|
676
|
+
console.dir(result.error, { depth: null });
|
|
677
|
+
expect(result.error.type).toBe('InvalidInput');
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
});
|
|
681
|
+
},
|
|
682
|
+
);
|
|
@@ -15,7 +15,7 @@ const testData = {
|
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
18
|
+
describe.each([PrimaryProvider.COMMERCETOOLS, PrimaryProvider.MEDUSA])(
|
|
19
19
|
'Product Capability - %s',
|
|
20
20
|
(provider) => {
|
|
21
21
|
let client: ReturnType<typeof createClient>;
|
|
@@ -45,7 +45,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
|
45
45
|
const response = await client.product.getBySlug({
|
|
46
46
|
slug: testData.product.slug,
|
|
47
47
|
});
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
if (!response.success) {
|
|
50
50
|
assert.fail();
|
|
51
51
|
}
|
|
@@ -111,7 +111,7 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
|
111
111
|
|
|
112
112
|
it('should return an error of NotFound for unknown slug', async () => {
|
|
113
113
|
const response = await client.product.getBySlug({ slug: 'unknown-slug' });
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
if (response.success) {
|
|
116
116
|
assert.fail();
|
|
117
117
|
}
|
package/src/utils.ts
CHANGED
|
@@ -109,6 +109,7 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
109
109
|
price: true,
|
|
110
110
|
productSearch: true,
|
|
111
111
|
productRecommendations: true,
|
|
112
|
+
productAssociations: true,
|
|
112
113
|
orderSearch: true,
|
|
113
114
|
store: true,
|
|
114
115
|
profile: true
|
|
@@ -119,7 +120,8 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
119
120
|
if (provider === PrimaryProvider.FAKE) {
|
|
120
121
|
builder = builder.withCapability(
|
|
121
122
|
withFakeCapabilities( getFakeConfiguration() , {
|
|
122
|
-
productReviews: true
|
|
123
|
+
productReviews: true,
|
|
124
|
+
productAssociations: true,
|
|
123
125
|
}
|
|
124
126
|
))
|
|
125
127
|
}
|
|
@@ -136,7 +138,9 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
136
138
|
order: true,
|
|
137
139
|
price: true,
|
|
138
140
|
productSearch: true,
|
|
141
|
+
productAssociations: true,
|
|
139
142
|
productReviews: true,
|
|
143
|
+
productList: true,
|
|
140
144
|
orderSearch: true,
|
|
141
145
|
store: true,
|
|
142
146
|
profile: true,
|