@reactionary/examples-node 0.3.2 → 0.3.4

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.2",
3
+ "version": "0.3.4",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.2",
8
- "@reactionary/provider-commercetools": "0.3.2",
9
- "@reactionary/provider-algolia": "0.3.2",
10
- "@reactionary/provider-medusa": "0.3.2",
11
- "@reactionary/provider-meilisearch": "0.3.2"
7
+ "@reactionary/core": "0.3.4",
8
+ "@reactionary/provider-commercetools": "0.3.4",
9
+ "@reactionary/provider-algolia": "0.3.4",
10
+ "@reactionary/provider-medusa": "0.3.4",
11
+ "@reactionary/provider-meilisearch": "0.3.4"
12
12
  },
13
13
  "type": "module"
14
14
  }
@@ -0,0 +1,140 @@
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
+ });
97
+
98
+
99
+
100
+ describe.each([PrimaryProvider.ALGOLIA])(
101
+ 'Product Recommendations - Related - %s',
102
+ (provider) => {
103
+ let client: ReturnType<typeof createClient>;
104
+
105
+ beforeEach(() => {
106
+ client = createClient(provider);
107
+ });
108
+
109
+ it('should be able to return a list of products for recommendation - Related ', async () => {
110
+ const result = await client.productRecommendations.getRecommendations({
111
+ algorithm: 'related',
112
+ sourceProduct: {
113
+ key: testData.product.id,
114
+ },
115
+ numberOfRecommendations: 10,
116
+ });
117
+
118
+ if (!result.success) {
119
+ assert.fail(JSON.stringify(result.error));
120
+ }
121
+
122
+ expect(result.value.length).toBeGreaterThan(0);
123
+ });
124
+
125
+ it('should return an empty result for an unknown sku', async () => {
126
+ const result = await client.productRecommendations.getRecommendations({
127
+ algorithm: 'related',
128
+ sourceProduct: {
129
+ key: 'unknown-product-id',
130
+ },
131
+ numberOfRecommendations: 10,
132
+ });
133
+
134
+ if (!result.success) {
135
+ assert.fail(JSON.stringify(result.error));
136
+ }
137
+
138
+ expect(result.value.length).toBe(0);
139
+ });
140
+ });
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(