@reactionary/examples-node 0.3.13 → 0.3.15
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.15",
|
|
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.15",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.3.15",
|
|
9
|
+
"@reactionary/provider-algolia": "0.3.15",
|
|
10
|
+
"@reactionary/provider-medusa": "0.3.15",
|
|
11
|
+
"@reactionary/provider-meilisearch": "0.3.15",
|
|
12
|
+
"@reactionary/provider-fake": "0.3.15"
|
|
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
|
+
});
|
|
@@ -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,6 +138,7 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
136
138
|
order: true,
|
|
137
139
|
price: true,
|
|
138
140
|
productSearch: true,
|
|
141
|
+
productAssociations: true,
|
|
139
142
|
productReviews: true,
|
|
140
143
|
orderSearch: true,
|
|
141
144
|
store: true,
|