@reactionary/examples-node 0.2.2 → 0.2.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,13 +1,13 @@
1
1
  {
2
2
  "name": "@reactionary/examples-node",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.2.2",
8
- "@reactionary/provider-commercetools": "0.2.2",
9
- "@reactionary/provider-algolia": "0.2.2",
10
- "@reactionary/provider-medusa": "0.2.2"
7
+ "@reactionary/core": "0.2.3",
8
+ "@reactionary/provider-commercetools": "0.2.3",
9
+ "@reactionary/provider-algolia": "0.2.3",
10
+ "@reactionary/provider-medusa": "0.2.3"
11
11
  },
12
12
  "type": "module"
13
13
  }
@@ -0,0 +1,159 @@
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
+ searchTerm: '',
8
+ sku: '0766623301831'
9
+ };
10
+
11
+ describe.each([PrimaryProvider.COMMERCETOOLS])(
12
+ 'Order Search Capability - %s',
13
+ (provider) => {
14
+ let client: ReturnType<typeof createClient>;
15
+
16
+ beforeEach(() => {
17
+ client = createClient(provider);
18
+ });
19
+
20
+ // Technically, i should create a bunch of orders first, but a) that would make the test way longer, and b) they would all be on the same day with same statuses.
21
+ it('can be called by anonymous users', async () => {
22
+ const result = await client.orderSearch.queryByTerm({
23
+ search: {
24
+ term: testData.searchTerm,
25
+ paginationOptions: {
26
+ pageNumber: 1,
27
+ pageSize: 10,
28
+ },
29
+ filters: [],
30
+ },
31
+ });
32
+
33
+ if (!result.success) {
34
+ assert.fail(JSON.stringify(result.error));
35
+ }
36
+ });
37
+
38
+ 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
+ );
47
+ const identity = await client.identity.getSelf({});
48
+
49
+ if (!identity.success) {
50
+ assert.fail();
51
+ }
52
+
53
+ expect(identity.value.type).toBe('Guest');
54
+
55
+ const result = await client.orderSearch.queryByTerm({
56
+ search: {
57
+ term: testData.searchTerm,
58
+ paginationOptions: {
59
+ pageNumber: 1,
60
+ pageSize: 10,
61
+ },
62
+ filters: [],
63
+ },
64
+ });
65
+
66
+ if (!result.success) {
67
+ assert.fail(JSON.stringify(result.error));
68
+ }
69
+ });
70
+
71
+ it('can be called by an authenticated user', async () => {
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
+ );
79
+
80
+ if (!identity.success) {
81
+ assert.fail();
82
+ }
83
+
84
+ expect(identity.value.type).toBe('Registered');
85
+ const result = await client.orderSearch.queryByTerm({
86
+ search: {
87
+ term: testData.searchTerm,
88
+ paginationOptions: {
89
+ pageNumber: 1,
90
+ pageSize: 10,
91
+ },
92
+ filters: [],
93
+ },
94
+ });
95
+
96
+ if (!result.success) {
97
+ assert.fail(JSON.stringify(result.error));
98
+ }
99
+
100
+ });
101
+ it.skip('can filter by startDate', async () => {
102
+ /** TODO */
103
+ });
104
+
105
+ it.skip('can filter by endDate', async () => {
106
+ /** TODO */
107
+ });
108
+
109
+ it.skip('can filter by orderStatus', async () => {
110
+ /** TODO */
111
+ });
112
+
113
+ it.skip('can filter by multiple orderStatuses', async () => {
114
+ /** TODO */
115
+ });
116
+
117
+ it.skip('can filter by partNumber', async () => {
118
+ /** TODO */
119
+ });
120
+
121
+
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,
129
+ },
130
+ filters: [],
131
+ },
132
+ });
133
+
134
+ if (!result.success) {
135
+ assert.fail(JSON.stringify(result.error));
136
+ }
137
+
138
+ const result2 = await client.orderSearch.queryByTerm({
139
+ search: {
140
+ term: testData.searchTerm,
141
+ paginationOptions: {
142
+ pageNumber: 2,
143
+ pageSize: 2,
144
+ },
145
+ filters: [],
146
+ },
147
+ });
148
+
149
+ if (!result2.success) {
150
+ assert.fail(JSON.stringify(result2.error));
151
+ }
152
+
153
+ expect(result.value.items[0].identifier).not.toBe(
154
+ result2.value.items[0].identifier
155
+ );
156
+ });
157
+ }
158
+
159
+ );
@@ -0,0 +1,91 @@
1
+ import 'dotenv/config';
2
+ import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { createClient, PrimaryProvider } from '../utils.js';
4
+ import type { OrderIdentifier, ProductSearchQueryCreateNavigationFilter } from '@reactionary/core';
5
+
6
+ const testData = {
7
+ searchTerm: '',
8
+ sku: '0766623301831',
9
+ };
10
+
11
+ describe.each([PrimaryProvider.COMMERCETOOLS])(
12
+ 'Order Search Capability - %s',
13
+ (provider) => {
14
+ let client: ReturnType<typeof createClient>;
15
+
16
+ beforeEach(() => {
17
+ client = createClient(provider);
18
+ });
19
+
20
+ it.skip('can be called by guest users', async () => {
21
+ const updatedCart = await client.cart.add(
22
+ {
23
+ quantity: 1,
24
+ variant: {
25
+ sku: testData.sku
26
+ },
27
+ }
28
+ );
29
+ // create order....somehow.....
30
+
31
+ const orderId: OrderIdentifier = { key: '123456'};
32
+ const identity = await client.identity.getSelf({});
33
+ if (!identity.success) {
34
+ assert.fail();
35
+ }
36
+
37
+ expect(identity.value.type).toBe('Guest');
38
+ const result = await client.order.getById({ order: orderId });
39
+ if (!result.success) {
40
+ assert.fail(JSON.stringify(result.error));
41
+ }
42
+
43
+ const order = result.value;
44
+ expect(order.identifier.key).toBe(orderId.key);
45
+ expect(order.items.length).toBeGreaterThan(0);
46
+ expect(order.price.grandTotal.value).toBeGreaterThan(0);
47
+
48
+ });
49
+
50
+ it.skip('can be called by registered users', async () => {
51
+ const time = new Date().getTime();
52
+ const identity = await client.identity.register(
53
+ {
54
+ username: `test-user+${time}@example.com`,
55
+ password: 'love2test',
56
+ }
57
+ );
58
+
59
+ if (!identity.success) {
60
+ assert.fail();
61
+ }
62
+
63
+ expect(identity.value.type).toBe('Registered');
64
+
65
+ const updatedCart = await client.cart.add(
66
+ {
67
+ quantity: 1,
68
+ variant: {
69
+ sku: testData.sku
70
+ },
71
+ }
72
+ );
73
+ // create order....somehow.....
74
+
75
+ const orderId: OrderIdentifier = { key: '456789'};
76
+
77
+
78
+ expect(identity.value.type).toBe('Guest');
79
+ const result = await client.order.getById({ order: orderId });
80
+ if (!result.success) {
81
+ assert.fail(JSON.stringify(result.error));
82
+ }
83
+
84
+ const order = result.value;
85
+ expect(order.identifier.key).toBe(orderId.key);
86
+ expect(order.items.length).toBeGreaterThan(0);
87
+ expect(order.price.grandTotal.value).toBeGreaterThan(0);
88
+ });
89
+
90
+
91
+ });