@reactionary/examples-node 0.2.14 → 0.2.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,14 +1,14 @@
1
1
  {
2
2
  "name": "@reactionary/examples-node",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.2.14",
8
- "@reactionary/provider-commercetools": "0.2.14",
9
- "@reactionary/provider-algolia": "0.2.14",
10
- "@reactionary/provider-medusa": "0.2.14",
11
- "@reactionary/provider-meilisearch": "0.2.14"
7
+ "@reactionary/core": "0.2.16",
8
+ "@reactionary/provider-commercetools": "0.2.16",
9
+ "@reactionary/provider-algolia": "0.2.16",
10
+ "@reactionary/provider-medusa": "0.2.16",
11
+ "@reactionary/provider-meilisearch": "0.2.16"
12
12
  },
13
13
  "type": "module"
14
14
  }
@@ -5,10 +5,12 @@ import type { ProductSearchQueryCreateNavigationFilter } from '@reactionary/core
5
5
 
6
6
  const testData = {
7
7
  searchTerm: '',
8
- sku: '0766623301831'
8
+ sku: '0766623301831',
9
+ customerName: 'Eileen Harvey',
10
+ email: 'eileen.harvey@example.com',
9
11
  };
10
12
 
11
- describe.each([PrimaryProvider.COMMERCETOOLS])(
13
+ describe.each([PrimaryProvider.MEILISEARCH])(
12
14
  'Order Search Capability - %s',
13
15
  (provider) => {
14
16
  let client: ReturnType<typeof createClient>;
@@ -36,14 +38,12 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
36
38
  });
37
39
 
38
40
  it('can be called by guest users', async () => {
39
- const updatedCart = await client.cart.add(
40
- {
41
- quantity: 1,
42
- variant: {
43
- sku: testData.sku
44
- },
45
- }
46
- );
41
+ const updatedCart = await client.cart.add({
42
+ quantity: 1,
43
+ variant: {
44
+ sku: testData.sku,
45
+ },
46
+ });
47
47
  const identity = await client.identity.getSelf({});
48
48
 
49
49
  if (!identity.success) {
@@ -70,14 +70,13 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
70
70
 
71
71
  it('can be called by an authenticated user', async () => {
72
72
  const time = new Date().getTime();
73
- const identity = await client.identity.register(
74
- {
75
- username: `test-user+${time}@example.com`,
76
- password: 'love2test',
77
- }
78
- );
73
+ const identity = await client.identity.register({
74
+ username: `test-user+${time}@example.com`,
75
+ password: 'love2test',
76
+ });
79
77
 
80
78
  if (!identity.success) {
79
+
81
80
  assert.fail();
82
81
  }
83
82
 
@@ -96,64 +95,171 @@ describe.each([PrimaryProvider.COMMERCETOOLS])(
96
95
  if (!result.success) {
97
96
  assert.fail(JSON.stringify(result.error));
98
97
  }
99
-
100
- });
101
- it.skip('can filter by startDate', async () => {
102
- /** TODO */
103
98
  });
104
99
 
105
- it.skip('can filter by endDate', async () => {
106
- /** TODO */
107
- });
100
+ describe('filters', () => {
108
101
 
109
- it.skip('can filter by orderStatus', async () => {
110
- /** TODO */
111
- });
112
102
 
113
- it.skip('can filter by multiple orderStatuses', async () => {
114
- /** TODO */
115
- });
103
+ beforeEach(async () => {
104
+ const time = new Date().getTime();
105
+ const identity = await client.identity.login({ username: testData.email,
106
+ password: 'Test1234!'
107
+ });
116
108
 
117
- it.skip('can filter by partNumber', async () => {
118
- /** TODO */
119
- });
109
+ if (!identity.success) {
110
+ assert.fail();
111
+ }
112
+ expect(identity.value.type).toBe('Registered');
113
+ });
120
114
 
115
+ it('has some test orders', async () => {
116
+ const result = await client.orderSearch.queryByTerm({
117
+ search: {
118
+ term: '',
119
+ paginationOptions: {
120
+ pageNumber: 1,
121
+ pageSize: 10,
122
+ },
123
+ filters: [],
124
+ },
125
+ });
121
126
 
122
- it.skip('can page the resultset', async () => {
123
- const result = await client.orderSearch.queryByTerm({
124
- search: {
125
- term: testData.searchTerm,
126
- paginationOptions: {
127
- pageNumber: 1,
128
- pageSize: 2,
127
+ if (!result.success) {
128
+ assert.fail(JSON.stringify(result.error));
129
+ }
130
+
131
+ expect(result.value.items.length).toBeGreaterThan(0);
132
+ });
133
+
134
+ it('can filter by part number', async () => {
135
+
136
+ const result = await client.orderSearch.queryByTerm({
137
+ search: {
138
+ term: '',
139
+ paginationOptions: {
140
+ pageNumber: 1,
141
+ pageSize: 10,
142
+ },
143
+ filters: [],
129
144
  },
130
- filters: [],
131
- },
145
+ });
146
+
147
+ if (!result.success) {
148
+ assert.fail(JSON.stringify(result.error));
149
+ }
150
+
151
+
152
+ const result2 = await client.orderSearch.queryByTerm({
153
+ search: {
154
+ term: '',
155
+ partNumber: [testData.sku],
156
+ paginationOptions: {
157
+ pageNumber: 1,
158
+ pageSize: 10,
159
+ },
160
+ filters: [],
161
+ },
162
+ });
163
+
164
+ if (!result2.success) {
165
+ assert.fail(JSON.stringify(result2.error));
166
+ }
167
+ expect(result2.value.items.length).toBeGreaterThan(0);
168
+ expect(result2.value.totalCount).toBeLessThanOrEqual(result.value.totalCount);
132
169
  });
133
170
 
134
- if (!result.success) {
135
- assert.fail(JSON.stringify(result.error));
136
- }
171
+ it('can filter by search term', async () => {
172
+ const result = await client.orderSearch.queryByTerm({
173
+ search: {
174
+ term: 'cable',
175
+ paginationOptions: {
176
+ pageNumber: 1,
177
+ pageSize: 10,
178
+ },
179
+ filters: [],
180
+ },
181
+ });
137
182
 
138
- const result2 = await client.orderSearch.queryByTerm({
139
- search: {
140
- term: testData.searchTerm,
141
- paginationOptions: {
142
- pageNumber: 2,
143
- pageSize: 2,
183
+ if (!result.success) {
184
+ assert.fail(JSON.stringify(result.error));
185
+ }
186
+ expect(result.value.items.length).toBeGreaterThan(0);
187
+ });
188
+
189
+
190
+
191
+ it('can paginate results', async () => {
192
+ const result = await client.orderSearch.queryByTerm({
193
+ search: {
194
+ term: '',
195
+ paginationOptions: {
196
+ pageNumber: 1,
197
+ pageSize: 1,
198
+ },
199
+ filters: [],
144
200
  },
145
- filters: [],
146
- },
201
+ });
202
+
203
+ if (!result.success) {
204
+ assert.fail(JSON.stringify(result.error));
205
+ }
206
+ expect(result.value.items.length).toBe(1);
207
+
208
+ const result2 = await client.orderSearch.queryByTerm({
209
+ search: {
210
+ term: '',
211
+ paginationOptions: {
212
+ pageNumber: 2,
213
+ pageSize: 1,
214
+ },
215
+ filters: [],
216
+ },
217
+ });
218
+
219
+ if (!result2.success) {
220
+ assert.fail(JSON.stringify(result2.error));
221
+ }
222
+ expect(result2.value.items.length).toBe(1);
223
+ expect(result2.value.items[0].identifier.key).not.toBe(
224
+ result.value.items[0].identifier.key
225
+ );
147
226
  });
148
227
 
149
- if (!result2.success) {
150
- assert.fail(JSON.stringify(result2.error));
151
- }
228
+ it('can filter by order status', async () => {
229
+ const result = await client.orderSearch.queryByTerm({
230
+ search: {
231
+ term: '',
232
+ orderStatus: ['Shipped'],
233
+ paginationOptions: {
234
+ pageNumber: 1,
235
+ pageSize: 10,
236
+ },
237
+ filters: [],
238
+ },
239
+ });
152
240
 
153
- expect(result.value.items[0].identifier).not.toBe(
154
- result2.value.items[0].identifier
155
- );
241
+ if (!result.success) {
242
+ assert.fail(JSON.stringify(result.error));
243
+ }
244
+ expect(result.value.items.length).toBeGreaterThan(0);
245
+
246
+ const result2 = await client.orderSearch.queryByTerm({
247
+ search: {
248
+ term: '',
249
+ orderStatus: ['Cancelled'],
250
+ paginationOptions: {
251
+ pageNumber: 1,
252
+ pageSize: 10,
253
+ },
254
+ filters: [],
255
+ },
256
+ });
257
+
258
+ if (!result2.success) {
259
+ assert.fail(JSON.stringify(result2.error));
260
+ }
261
+ expect(result2.value.items.length).toBe(0);
262
+ });
156
263
  });
157
264
  }
158
-
159
265
  );
package/src/utils.ts CHANGED
@@ -23,6 +23,7 @@ export function getMeilisearchTestConfiguration() {
23
23
  apiUrl: process.env['MEILISEARCH_API_URL'] || '',
24
24
  indexName: process.env['MEILISEARCH_INDEX'] || '',
25
25
  useAIEmbedding: process.env['MEILISEARCH_USE_AI_EMBEDDING'] || undefined,
26
+ orderIndexName: process.env['MEILISEARCH_ORDER_INDEX'] || 'order',
26
27
  };
27
28
  }
28
29
 
@@ -90,6 +91,7 @@ export function createClient(provider: PrimaryProvider) {
90
91
  order: true,
91
92
  price: true,
92
93
  productSearch: true,
94
+ orderSearch: true,
93
95
  store: true,
94
96
  profile: true
95
97
  })
@@ -110,6 +112,7 @@ export function createClient(provider: PrimaryProvider) {
110
112
  order: true,
111
113
  price: true,
112
114
  productSearch: true,
115
+ orderSearch: true,
113
116
  store: true,
114
117
  profile: true,
115
118
  })
@@ -129,6 +132,13 @@ export function createClient(provider: PrimaryProvider) {
129
132
  builder = builder.withCapability(
130
133
  withMeilisearchCapabilities(getMeilisearchTestConfiguration(), {
131
134
  productSearch: true,
135
+ orderSearch: true,
136
+ }),
137
+ );
138
+ builder = builder.withCapability(
139
+ withMedusaCapabilities(getMedusaTestConfiguration(), {
140
+ cart: true,
141
+ identity: true,
132
142
  })
133
143
  );
134
144
  }