@reactionary/examples-node 0.1.5 → 0.1.7
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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/examples-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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.
|
|
7
|
+
"@reactionary/core": "0.1.7",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.1.7",
|
|
9
|
+
"@reactionary/provider-algolia": "0.1.7",
|
|
10
|
+
"@reactionary/provider-medusa": "0.1.7"
|
|
11
11
|
},
|
|
12
12
|
"type": "module"
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
|
+
import type { ProductSearchQueryCreateNavigationFilter } from '@reactionary/core';
|
|
4
5
|
|
|
5
6
|
const testData = {
|
|
6
7
|
searchTerm: 'manhattan',
|
|
@@ -145,5 +146,94 @@ describe.each([PrimaryProvider.ALGOLIA, PrimaryProvider.COMMERCETOOLS])(
|
|
|
145
146
|
expect(facet.values.length).toBeGreaterThan(0);
|
|
146
147
|
}
|
|
147
148
|
});
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
it('can apply a category facet', async () => {
|
|
152
|
+
const result = await client.productSearch.queryByTerm({
|
|
153
|
+
search: {
|
|
154
|
+
term: "*",
|
|
155
|
+
paginationOptions: {
|
|
156
|
+
pageNumber: 1,
|
|
157
|
+
pageSize: 10,
|
|
158
|
+
},
|
|
159
|
+
facets: [],
|
|
160
|
+
filters: [],
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const categoryFacet = result.facets.find(
|
|
165
|
+
(f) => f.identifier.key === 'categories'
|
|
166
|
+
);
|
|
167
|
+
expect(categoryFacet).toBeDefined();
|
|
168
|
+
const chosenFacet = categoryFacet!.values[0]!;
|
|
169
|
+
|
|
170
|
+
const narrowedResult = await client.productSearch.queryByTerm({
|
|
171
|
+
search: {
|
|
172
|
+
term: "*",
|
|
173
|
+
paginationOptions: {
|
|
174
|
+
pageNumber: 1,
|
|
175
|
+
pageSize: 10,
|
|
176
|
+
},
|
|
177
|
+
facets: [chosenFacet.identifier],
|
|
178
|
+
filters: [],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
expect(narrowedResult.totalCount).toBeLessThan(result.totalCount);
|
|
182
|
+
expect(narrowedResult.totalCount).toBeGreaterThan(0);
|
|
183
|
+
expect(narrowedResult.totalCount).toBe(chosenFacet.count);
|
|
184
|
+
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
it('can apply a top level category filter', async () => {
|
|
190
|
+
// First, get a category to filter on
|
|
191
|
+
const categories = await client.category.findTopCategories({
|
|
192
|
+
paginationOptions: {
|
|
193
|
+
pageNumber: 1,
|
|
194
|
+
pageSize: 2,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
const unfilteredSearch = await client.productSearch.queryByTerm({
|
|
200
|
+
search: {
|
|
201
|
+
term: "",
|
|
202
|
+
paginationOptions: {
|
|
203
|
+
pageNumber: 1,
|
|
204
|
+
pageSize: 1,
|
|
205
|
+
},
|
|
206
|
+
facets: [],
|
|
207
|
+
filters: [],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(unfilteredSearch.totalCount).toBeGreaterThan(0);
|
|
212
|
+
|
|
213
|
+
const breadCrumb = await client.category.getBreadcrumbPathToCategory({
|
|
214
|
+
id: categories.items[1].identifier,
|
|
215
|
+
});
|
|
216
|
+
expect(breadCrumb.length).toBeGreaterThan(0);
|
|
217
|
+
|
|
218
|
+
const categoryFilter = await client.productSearch.createCategoryNavigationFilter({
|
|
219
|
+
categoryPath: breadCrumb,
|
|
220
|
+
} satisfies ProductSearchQueryCreateNavigationFilter);
|
|
221
|
+
|
|
222
|
+
const filteredSearch = await client.productSearch.queryByTerm({
|
|
223
|
+
search: {
|
|
224
|
+
term: "",
|
|
225
|
+
categoryFilter: categoryFilter,
|
|
226
|
+
paginationOptions: {
|
|
227
|
+
pageNumber: 1,
|
|
228
|
+
pageSize: 1,
|
|
229
|
+
},
|
|
230
|
+
facets: [],
|
|
231
|
+
filters: [],
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(filteredSearch.totalCount).toBeLessThan(unfilteredSearch.totalCount);
|
|
236
|
+
expect(filteredSearch.totalCount).toBeGreaterThan(0);
|
|
237
|
+
});
|
|
148
238
|
}
|
|
149
239
|
);
|