@reactionary/examples-node 0.3.1 → 0.3.3
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,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/examples-node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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.
|
|
7
|
+
"@reactionary/core": "0.3.3",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.3.3",
|
|
9
|
+
"@reactionary/provider-algolia": "0.3.3",
|
|
10
|
+
"@reactionary/provider-medusa": "0.3.3",
|
|
11
|
+
"@reactionary/provider-meilisearch": "0.3.3"
|
|
12
12
|
},
|
|
13
13
|
"type": "module"
|
|
14
14
|
}
|
|
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { ClientBuilder, createInitialRequestContext, NoOpCache } from '@reactionary/core';
|
|
3
3
|
import { FakeProductProvider, withFakeCapabilities } from '@reactionary/provider-fake';
|
|
4
4
|
import { CommercetoolsCartProvider, withCommercetoolsCapabilities } from '@reactionary/provider-commercetools';
|
|
5
|
-
import {
|
|
5
|
+
import { AlgoliaProductSearchProvider, withAlgoliaCapabilities } from '@reactionary/provider-algolia';
|
|
6
6
|
|
|
7
7
|
describe('client creation', () => {
|
|
8
8
|
it('should be able to mix providers and get a valid, typed client', async () => {
|
|
@@ -48,6 +48,6 @@ describe('client creation', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(client.cart).toBeInstanceOf(CommercetoolsCartProvider);
|
|
50
50
|
expect(client.product).toBeInstanceOf(FakeProductProvider);
|
|
51
|
-
expect(client.productSearch).toBeInstanceOf(
|
|
51
|
+
expect(client.productSearch).toBeInstanceOf(AlgoliaProductSearchProvider);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
product: {
|
|
8
|
+
id: 'product_10959528',
|
|
9
|
+
name: 'Manhattan 170703 cable accessory Cable kit',
|
|
10
|
+
image: 'https://images.icecat.biz/img/norm/high/10959528-2837.jpg',
|
|
11
|
+
sku: '0766623170703',
|
|
12
|
+
slug: 'manhattan-170703-cable-accessory-cable-kit-10959528',
|
|
13
|
+
},
|
|
14
|
+
productWithMultiVariants: {
|
|
15
|
+
slug: 'hp-gk859aa-mouse-office-bluetooth-laser-1600-dpi-1377612',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe.each([PrimaryProvider.MEDUSA])(
|
|
20
|
+
'Product Recommendations - Collections - %s',
|
|
21
|
+
(provider) => {
|
|
22
|
+
let client: ReturnType<typeof createClient>;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
client = createClient(provider);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should be able to return a list of products for a collection', async () => {
|
|
29
|
+
const result = await client.productRecommendations.getCollection({
|
|
30
|
+
collectionName: 'newest-arrivals',
|
|
31
|
+
numberOfRecommendations: 10,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!result.success) {
|
|
35
|
+
assert.fail(JSON.stringify(result.error));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return an empty result for an unknown collection', async () => {
|
|
42
|
+
const result = await client.productRecommendations.getCollection({
|
|
43
|
+
collectionName: 'Unknown Collection',
|
|
44
|
+
numberOfRecommendations: 10,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
assert.fail(JSON.stringify(result.error));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
expect(result.value.length).toBe(0);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
describe.each([PrimaryProvider.MEILISEARCH])(
|
|
57
|
+
'Product Recommendations - Similar - %s',
|
|
58
|
+
(provider) => {
|
|
59
|
+
let client: ReturnType<typeof createClient>;
|
|
60
|
+
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
client = createClient(provider);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should be able to return a list of products for recommendation - Similar ', async () => {
|
|
66
|
+
const result = await client.productRecommendations.getRecommendations({
|
|
67
|
+
algorithm: 'similar',
|
|
68
|
+
sourceProduct: {
|
|
69
|
+
key: testData.product.id,
|
|
70
|
+
},
|
|
71
|
+
numberOfRecommendations: 10,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
assert.fail(JSON.stringify(result.error));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should return an empty result for an unknown sku', async () => {
|
|
82
|
+
const result = await client.productRecommendations.getRecommendations({
|
|
83
|
+
algorithm: 'similar',
|
|
84
|
+
sourceProduct: {
|
|
85
|
+
key: 'unknown-product-id',
|
|
86
|
+
},
|
|
87
|
+
numberOfRecommendations: 10,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (!result.success) {
|
|
91
|
+
assert.fail(JSON.stringify(result.error));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
expect(result.value.length).toBe(0);
|
|
95
|
+
});
|
|
96
|
+
});
|
package/src/utils.ts
CHANGED
|
@@ -91,6 +91,7 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
91
91
|
order: true,
|
|
92
92
|
price: true,
|
|
93
93
|
productSearch: true,
|
|
94
|
+
productRecommendations: true,
|
|
94
95
|
orderSearch: true,
|
|
95
96
|
store: true,
|
|
96
97
|
profile: true
|
|
@@ -124,6 +125,7 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
124
125
|
builder = builder.withCapability(
|
|
125
126
|
withAlgoliaCapabilities(getAlgoliaTestConfiguration(), {
|
|
126
127
|
productSearch: true,
|
|
128
|
+
productRecommendations: true,
|
|
127
129
|
})
|
|
128
130
|
);
|
|
129
131
|
}
|
|
@@ -133,6 +135,7 @@ export function createClient(provider: PrimaryProvider) {
|
|
|
133
135
|
withMeilisearchCapabilities(getMeilisearchTestConfiguration(), {
|
|
134
136
|
productSearch: true,
|
|
135
137
|
orderSearch: true,
|
|
138
|
+
productRecommendations: true,
|
|
136
139
|
}),
|
|
137
140
|
);
|
|
138
141
|
builder = builder.withCapability(
|