@reactionary/examples-node 0.1.13 → 0.2.2
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 +5 -5
- package/src/basic/basic-node-setup.spec.ts +6 -2
- package/src/capabilities/cart.spec.ts +109 -65
- package/src/capabilities/category.spec.ts +80 -45
- package/src/capabilities/checkout.spec.ts +237 -168
- package/src/capabilities/identity.spec.ts +36 -10
- package/src/capabilities/inventory.spec.ts +20 -20
- package/src/capabilities/price.spec.ts +45 -35
- package/src/capabilities/product-search.spec.ts +82 -29
- package/src/capabilities/product.spec.ts +90 -76
- package/src/capabilities/profile.spec.ts +307 -16
- package/src/capabilities/store.spec.ts +6 -2
- package/src/utils.ts +40 -25
|
@@ -1,25 +1,316 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
3
3
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
|
+
import { IdentityIdentifierSchema, type Address, type Identity, type IdentityIdentifier, type Profile } from '@reactionary/core';
|
|
4
5
|
|
|
5
|
-
describe.each([PrimaryProvider.COMMERCETOOLS])(
|
|
6
|
-
|
|
6
|
+
describe.each([PrimaryProvider.MEDUSA, PrimaryProvider.COMMERCETOOLS])(
|
|
7
|
+
'Profile Capability - %s',
|
|
8
|
+
(provider) => {
|
|
9
|
+
let client: ReturnType<typeof createClient>;
|
|
10
|
+
let identity: Identity | null = null;
|
|
11
|
+
let identityIdentifier: IdentityIdentifier | null = null;
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
client = createClient(provider);
|
|
15
|
+
const time = new Date().getTime();
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
const identityResponse = await client.identity.register({
|
|
18
|
+
username: `martin.rogne+test-${time}@solteq.com`,
|
|
19
|
+
password: 'love2test',
|
|
20
|
+
});
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
if (!identityResponse.success) {
|
|
23
|
+
assert.fail();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
identity = identityResponse.value;
|
|
27
|
+
if (identity.type !== 'Registered') {
|
|
28
|
+
assert.fail();
|
|
29
|
+
}
|
|
30
|
+
identityIdentifier = identity.id;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should be able to fetch the profile for the current user', async () => {
|
|
34
|
+
const time = new Date().getTime();
|
|
35
|
+
if (!identity) {
|
|
36
|
+
assert.fail();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (identity.type !== 'Registered') {
|
|
40
|
+
assert.fail();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const profile = await client.profile.getById({
|
|
44
|
+
identifier: identity.id,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!profile.success) {
|
|
48
|
+
console.log(profile.error);
|
|
49
|
+
assert.fail();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
expect(profile.value.email).toContain('martin.rogne');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should be able to update the profile for the current user', async () => {
|
|
56
|
+
|
|
57
|
+
const time = new Date().getTime();
|
|
58
|
+
const updatedProfile = await client.profile.update({
|
|
59
|
+
identifier: identityIdentifier!,
|
|
60
|
+
phone: '+4712345678',
|
|
61
|
+
email: `martin.rogne+test-${time}-a@solteq.com`,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!updatedProfile.success) {
|
|
65
|
+
console.log(updatedProfile.error);
|
|
66
|
+
assert.fail();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
expect(updatedProfile.value.email).toBe(
|
|
70
|
+
`martin.rogne+test-${time}-a@solteq.com`
|
|
71
|
+
);
|
|
72
|
+
expect(updatedProfile.value.phone).toBe('+4712345678');
|
|
73
|
+
expect(updatedProfile.value.billingAddress).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should be able to set the billing address on the profile', async () => {
|
|
77
|
+
if (!identity) {
|
|
78
|
+
assert.fail();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (identity.type !== 'Registered') {
|
|
82
|
+
assert.fail();
|
|
83
|
+
}
|
|
84
|
+
const newAddress: Address = {
|
|
85
|
+
identifier: {
|
|
86
|
+
nickName: 'Billing',
|
|
87
|
+
},
|
|
88
|
+
firstName: 'Jane',
|
|
89
|
+
lastName: 'Doe',
|
|
90
|
+
streetAddress: 'Second Street',
|
|
91
|
+
streetNumber: '456',
|
|
92
|
+
city: 'Gotham',
|
|
93
|
+
region: 'State',
|
|
94
|
+
postalCode: '67890',
|
|
95
|
+
countryCode: 'US',
|
|
96
|
+
};
|
|
97
|
+
const updatedProfile = await client.profile.setBillingAddress({
|
|
98
|
+
identifier: identity.id,
|
|
99
|
+
address: newAddress,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (!updatedProfile.success) {
|
|
103
|
+
console.log(updatedProfile.error);
|
|
104
|
+
assert.fail();
|
|
105
|
+
}
|
|
106
|
+
expect(updatedProfile.value.billingAddress).toMatchObject(newAddress);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('cannot use same nickname for billing and shipping addresses', async () => {
|
|
110
|
+
if (!identity) {
|
|
111
|
+
assert.fail();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (identity.type !== 'Registered') {
|
|
115
|
+
assert.fail();
|
|
116
|
+
}
|
|
117
|
+
const newAddress: Address = {
|
|
118
|
+
identifier: {
|
|
119
|
+
nickName: 'SameNick',
|
|
120
|
+
},
|
|
121
|
+
firstName: 'Jane',
|
|
122
|
+
lastName: 'Doe',
|
|
123
|
+
streetAddress: 'Second Street',
|
|
124
|
+
streetNumber: '456',
|
|
125
|
+
city: 'Gotham',
|
|
126
|
+
region: 'State',
|
|
127
|
+
postalCode: '67890',
|
|
128
|
+
countryCode: 'US',
|
|
129
|
+
};
|
|
130
|
+
const billingAddressResponse = await client.profile.setBillingAddress({
|
|
131
|
+
identifier: identity.id,
|
|
132
|
+
address: newAddress,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (!billingAddressResponse.success) {
|
|
136
|
+
console.log(billingAddressResponse.error);
|
|
137
|
+
assert.fail();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const shippingAddressResponse = await client.profile.addShippingAddress({
|
|
141
|
+
identifier: identity.id,
|
|
142
|
+
address: newAddress,
|
|
143
|
+
});
|
|
144
|
+
expect(shippingAddressResponse.success).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('cannot set the billing address to an existing shipping address', async () => {
|
|
148
|
+
if (!identity) {
|
|
149
|
+
assert.fail();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (identity.type !== 'Registered') {
|
|
153
|
+
assert.fail();
|
|
154
|
+
}
|
|
155
|
+
const newAddress: Address = {
|
|
156
|
+
identifier: {
|
|
157
|
+
nickName: 'SameNick',
|
|
158
|
+
},
|
|
159
|
+
firstName: 'Jane',
|
|
160
|
+
lastName: 'Doe',
|
|
161
|
+
streetAddress: 'Second Street',
|
|
162
|
+
streetNumber: '456',
|
|
163
|
+
city: 'Gotham',
|
|
164
|
+
region: 'State',
|
|
165
|
+
postalCode: '67890',
|
|
166
|
+
countryCode: 'US',
|
|
167
|
+
};
|
|
168
|
+
const shippingAddressResponse = await client.profile.addShippingAddress({
|
|
169
|
+
identifier: identity.id,
|
|
170
|
+
address: newAddress,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!shippingAddressResponse.success) {
|
|
174
|
+
console.log(shippingAddressResponse.error);
|
|
175
|
+
assert.fail();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const billingAddress = await client.profile.setBillingAddress({
|
|
179
|
+
identifier: identity.id,
|
|
180
|
+
address: shippingAddressResponse.value.alternateShippingAddresses[0]
|
|
181
|
+
});
|
|
182
|
+
expect(billingAddress.success).toBe(false);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
it('should be able to add a shipping address to the profile', async () => {
|
|
187
|
+
if (!identity) {
|
|
188
|
+
assert.fail();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (identity.type !== 'Registered') {
|
|
192
|
+
assert.fail();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const newAddress: Address = {
|
|
196
|
+
identifier: {
|
|
197
|
+
nickName: 'Home',
|
|
198
|
+
},
|
|
199
|
+
firstName: 'John',
|
|
200
|
+
lastName: 'Doe',
|
|
201
|
+
streetAddress: 'Main Street',
|
|
202
|
+
streetNumber: '123',
|
|
203
|
+
city: 'Metropolis',
|
|
204
|
+
region: 'State',
|
|
205
|
+
postalCode: '12345',
|
|
206
|
+
countryCode: 'US',
|
|
207
|
+
};
|
|
208
|
+
const updatedProfile = await client.profile.addShippingAddress({
|
|
209
|
+
identifier: identity.id,
|
|
210
|
+
address: newAddress,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (!updatedProfile.success) {
|
|
214
|
+
console.log(updatedProfile.error);
|
|
215
|
+
assert.fail();
|
|
216
|
+
}
|
|
217
|
+
expect(updatedProfile.value.shippingAddress).toBeUndefined();
|
|
218
|
+
|
|
219
|
+
expect(updatedProfile.value.alternateShippingAddresses.length).toBe(1);
|
|
220
|
+
expect(updatedProfile.value.alternateShippingAddresses[0]).toMatchObject(
|
|
221
|
+
newAddress
|
|
222
|
+
);
|
|
18
223
|
});
|
|
19
224
|
|
|
20
|
-
|
|
225
|
+
describe('Shipping Addresses', () => {
|
|
226
|
+
const newAddress: Address = {
|
|
227
|
+
identifier: {
|
|
228
|
+
nickName: 'Home',
|
|
229
|
+
},
|
|
230
|
+
firstName: 'John',
|
|
231
|
+
lastName: 'Doe',
|
|
232
|
+
streetAddress: 'Main Street',
|
|
233
|
+
streetNumber: '123',
|
|
234
|
+
city: 'Metropolis',
|
|
235
|
+
region: 'State',
|
|
236
|
+
postalCode: '12345',
|
|
237
|
+
countryCode: 'US',
|
|
238
|
+
};
|
|
239
|
+
let profile: Profile | null;
|
|
240
|
+
|
|
241
|
+
beforeEach(async () => {
|
|
242
|
+
const updatedProfile = await client.profile.addShippingAddress({
|
|
243
|
+
identifier: identityIdentifier!,
|
|
244
|
+
address: newAddress,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (!updatedProfile.success) {
|
|
248
|
+
console.log(updatedProfile.error);
|
|
249
|
+
assert.fail();
|
|
250
|
+
}
|
|
21
251
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
252
|
+
profile = updatedProfile.value;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('can make a shipping address the default address', async () => {
|
|
256
|
+
const addressToMakeDefault =
|
|
257
|
+
profile!.alternateShippingAddresses[0];
|
|
258
|
+
|
|
259
|
+
const updatedProfile = await client.profile.makeShippingAddressDefault({
|
|
260
|
+
identifier: identityIdentifier!,
|
|
261
|
+
addressIdentifier: addressToMakeDefault.identifier,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
if (!updatedProfile.success) {
|
|
265
|
+
console.log(updatedProfile.error);
|
|
266
|
+
assert.fail();
|
|
267
|
+
}
|
|
268
|
+
expect(updatedProfile.value.shippingAddress).toBeDefined();
|
|
269
|
+
expect(updatedProfile.value.shippingAddress).toMatchObject(newAddress);
|
|
270
|
+
expect(updatedProfile.value.alternateShippingAddresses.length).toBe(0);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('can remove a shipping address from the profile', async () => {
|
|
274
|
+
const addressToRemove =
|
|
275
|
+
profile!.alternateShippingAddresses[0];
|
|
276
|
+
|
|
277
|
+
const updatedProfile = await client.profile.removeShippingAddress({
|
|
278
|
+
identifier: identityIdentifier!,
|
|
279
|
+
addressIdentifier: addressToRemove.identifier,
|
|
280
|
+
});
|
|
281
|
+
if (!updatedProfile.success) {
|
|
282
|
+
console.log(updatedProfile.error);
|
|
283
|
+
assert.fail();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
expect(updatedProfile.value.alternateShippingAddresses.length).toBe(0);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('can remove a shipping address from the profile even if it is the default shipping address', async () => {
|
|
290
|
+
const makeDefaultResponse = await client.profile.makeShippingAddressDefault({
|
|
291
|
+
identifier: identityIdentifier!,
|
|
292
|
+
addressIdentifier: profile!.alternateShippingAddresses[0].identifier,
|
|
293
|
+
});
|
|
294
|
+
if (!makeDefaultResponse.success) {
|
|
295
|
+
console.log(makeDefaultResponse.error);
|
|
296
|
+
assert.fail();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const profileWithDefault = makeDefaultResponse.value;
|
|
300
|
+
const addressToRemove = profileWithDefault.shippingAddress!;
|
|
301
|
+
|
|
302
|
+
const updatedProfile = await client.profile.removeShippingAddress({
|
|
303
|
+
identifier: identityIdentifier!,
|
|
304
|
+
addressIdentifier: addressToRemove.identifier,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (!updatedProfile.success) {
|
|
308
|
+
console.log(updatedProfile.error);
|
|
309
|
+
assert.fail();
|
|
310
|
+
}
|
|
311
|
+
expect(updatedProfile.value.shippingAddress).toBeUndefined();
|
|
312
|
+
expect(updatedProfile.value.alternateShippingAddresses.length).toBe(0);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
+
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
3
3
|
import { createClient, PrimaryProvider } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
describe.each([PrimaryProvider.COMMERCETOOLS])('Store Capability - %s', (provider) => {
|
|
@@ -17,6 +17,10 @@ describe.each([PrimaryProvider.COMMERCETOOLS])('Store Capability - %s', (provide
|
|
|
17
17
|
limit: 10,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
if (!stores.success) {
|
|
21
|
+
assert.fail();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
expect(stores.value.length).toBe(2);
|
|
21
25
|
});
|
|
22
26
|
});
|
package/src/utils.ts
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
createInitialRequestContext,
|
|
3
3
|
ClientBuilder,
|
|
4
4
|
NoOpCache,
|
|
5
|
-
type PaymentMethod,
|
|
6
|
-
type PaymentMethodIdentifier,
|
|
7
5
|
} from '@reactionary/core';
|
|
8
6
|
import type { CommercetoolsConfiguration } from '@reactionary/provider-commercetools';
|
|
9
7
|
import { withCommercetoolsCapabilities } from '@reactionary/provider-commercetools';
|
|
@@ -49,13 +47,6 @@ export function getCommercetoolsTestConfiguration() {
|
|
|
49
47
|
paymentProcessor: 'stripe'
|
|
50
48
|
},
|
|
51
49
|
isPunchOut: false,
|
|
52
|
-
meta: {
|
|
53
|
-
cache: {
|
|
54
|
-
hit: false,
|
|
55
|
-
key: ''
|
|
56
|
-
},
|
|
57
|
-
placeholder: false
|
|
58
|
-
},
|
|
59
50
|
description: 'Stripe payment gateway',
|
|
60
51
|
|
|
61
52
|
},
|
|
@@ -73,22 +64,46 @@ export enum PrimaryProvider {
|
|
|
73
64
|
export function createClient(provider: PrimaryProvider) {
|
|
74
65
|
const context = createInitialRequestContext();
|
|
75
66
|
let builder = new ClientBuilder(context)
|
|
76
|
-
.withCache(new NoOpCache())
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
67
|
+
.withCache(new NoOpCache());
|
|
68
|
+
|
|
69
|
+
if (provider === PrimaryProvider.MEDUSA) {
|
|
70
|
+
builder = builder.withCapability(
|
|
71
|
+
withMedusaCapabilities( getMedusaTestConfiguration(), {
|
|
72
|
+
cart: true,
|
|
73
|
+
product: true,
|
|
74
|
+
category: true,
|
|
75
|
+
checkout: true,
|
|
76
|
+
identity: true,
|
|
77
|
+
inventory: true,
|
|
78
|
+
order: true,
|
|
79
|
+
price: true,
|
|
80
|
+
productSearch: true,
|
|
81
|
+
store: true,
|
|
82
|
+
profile: true
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if (provider === PrimaryProvider.COMMERCETOOLS) {
|
|
90
|
+
builder = builder.withCapability(
|
|
91
|
+
withCommercetoolsCapabilities(getCommercetoolsTestConfiguration(), {
|
|
92
|
+
cart: true,
|
|
93
|
+
product: true,
|
|
94
|
+
category: true,
|
|
95
|
+
checkout: true,
|
|
96
|
+
identity: true,
|
|
97
|
+
inventory: true,
|
|
98
|
+
order: true,
|
|
99
|
+
price: true,
|
|
100
|
+
productSearch: true,
|
|
101
|
+
store: true,
|
|
102
|
+
profile: true,
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
92
107
|
|
|
93
108
|
if (provider === PrimaryProvider.ALGOLIA) {
|
|
94
109
|
builder = builder.withCapability(
|