@reactionary/provider-medusa 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/core/client.js +2 -23
- package/core/initialize.js +4 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +68 -58
- package/providers/category.provider.js +19 -53
- package/providers/checkout.provider.js +18 -40
- package/providers/identity.provider.js +9 -25
- package/providers/inventory.provider.js +7 -22
- package/providers/price.provider.js +8 -13
- package/providers/product-search.provider.js +31 -35
- package/providers/product.provider.js +13 -13
- package/providers/profile.provider.js +323 -0
- package/schema/capabilities.schema.js +2 -1
- package/src/core/client.d.ts +0 -35
- package/src/index.d.ts +1 -0
- package/src/providers/cart.provider.d.ts +10 -10
- package/src/providers/category.provider.d.ts +8 -50
- package/src/providers/checkout.provider.d.ts +10 -10
- package/src/providers/identity.provider.d.ts +5 -5
- package/src/providers/inventory.provider.d.ts +2 -2
- package/src/providers/price.provider.d.ts +3 -3
- package/src/providers/product-search.provider.d.ts +3 -17
- package/src/providers/product.provider.d.ts +4 -4
- package/src/providers/profile.provider.d.ts +30 -0
- package/src/schema/capabilities.schema.d.ts +3 -2
- package/test/cart.provider.spec.js +69 -49
- package/test/category.provider.spec.js +125 -63
- package/test/checkout.spec.js +80 -49
- package/test/identity.provider.spec.js +22 -7
- package/test/inventory.provider.spec.js +35 -24
- package/test/large-cart.provider.spec.js +57 -31
- package/test/price.provider.spec.js +57 -36
- package/test/product.provider.spec.js +78 -49
- package/test/search.provider.spec.js +47 -20
package/test/checkout.spec.js
CHANGED
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
createInitialRequestContext,
|
|
4
4
|
NoOpCache,
|
|
5
5
|
PaymentInstructionSchema,
|
|
6
|
-
ShippingInstructionSchema
|
|
6
|
+
ShippingInstructionSchema,
|
|
7
|
+
unwrapValue
|
|
7
8
|
} from "@reactionary/core";
|
|
8
9
|
import "dotenv/config";
|
|
9
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
10
|
+
import { assert, beforeEach, describe, expect, it } from "vitest";
|
|
10
11
|
import { withMedusaCapabilities } from "../core/initialize.js";
|
|
11
12
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
12
13
|
const testData = {
|
|
@@ -39,15 +40,14 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
39
40
|
describe("anonymous sessions", () => {
|
|
40
41
|
let cart;
|
|
41
42
|
beforeEach(async () => {
|
|
42
|
-
cart = await client.cart.add(
|
|
43
|
+
cart = unwrapValue(await client.cart.add(
|
|
43
44
|
{
|
|
44
|
-
cart: { key: "" },
|
|
45
45
|
variant: {
|
|
46
46
|
sku: testData.skuWithoutTiers
|
|
47
47
|
},
|
|
48
48
|
quantity: 1
|
|
49
49
|
}
|
|
50
|
-
);
|
|
50
|
+
));
|
|
51
51
|
});
|
|
52
52
|
it("can create a checkout session from a cart", async () => {
|
|
53
53
|
const checkout = await client.checkout.initiateCheckoutForCart(
|
|
@@ -67,16 +67,19 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
67
67
|
notificationPhone: "+4512345678"
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
expect(checkout.
|
|
74
|
-
expect(checkout.
|
|
70
|
+
if (!checkout.success) {
|
|
71
|
+
assert.fail();
|
|
72
|
+
}
|
|
73
|
+
expect(checkout.value.identifier.key).toBeDefined();
|
|
74
|
+
expect(checkout.value.originalCartReference.key).toBe(cart.identifier.key);
|
|
75
|
+
expect(checkout.value.billingAddress?.firstName).toBe("John");
|
|
76
|
+
expect(checkout.value.items.length).toBe(1);
|
|
77
|
+
expect(checkout.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
75
78
|
});
|
|
76
79
|
describe("checkout actions", () => {
|
|
77
80
|
let checkout;
|
|
78
81
|
beforeEach(async () => {
|
|
79
|
-
checkout = await client.checkout.initiateCheckoutForCart(
|
|
82
|
+
checkout = unwrapValue(await client.checkout.initiateCheckoutForCart(
|
|
80
83
|
{
|
|
81
84
|
cart,
|
|
82
85
|
billingAddress: {
|
|
@@ -92,7 +95,7 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
92
95
|
notificationEmail: "sample@example.com",
|
|
93
96
|
notificationPhone: "+4512345678"
|
|
94
97
|
}
|
|
95
|
-
);
|
|
98
|
+
));
|
|
96
99
|
});
|
|
97
100
|
it("can list payment methods", async () => {
|
|
98
101
|
const paymentMethods = await client.checkout.getAvailablePaymentMethods(
|
|
@@ -100,9 +103,12 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
100
103
|
checkout: checkout.identifier
|
|
101
104
|
}
|
|
102
105
|
);
|
|
103
|
-
|
|
106
|
+
if (!paymentMethods.success) {
|
|
107
|
+
assert.fail();
|
|
108
|
+
}
|
|
109
|
+
expect(paymentMethods.value.length).toBeGreaterThan(0);
|
|
104
110
|
expect(
|
|
105
|
-
paymentMethods.find((x) => x.identifier.method === "pp_stripe_stripe")
|
|
111
|
+
paymentMethods.value.find((x) => x.identifier.method === "pp_stripe_stripe")
|
|
106
112
|
).toBeDefined();
|
|
107
113
|
});
|
|
108
114
|
it("can list shipping methods", async () => {
|
|
@@ -111,9 +117,12 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
111
117
|
checkout: checkout.identifier
|
|
112
118
|
}
|
|
113
119
|
);
|
|
114
|
-
|
|
120
|
+
if (!shippingMethods.success) {
|
|
121
|
+
assert.fail();
|
|
122
|
+
}
|
|
123
|
+
expect(shippingMethods.value.length).toBeGreaterThan(0);
|
|
115
124
|
expect(
|
|
116
|
-
shippingMethods.find((x) => x.name === "Standard Shipping")
|
|
125
|
+
shippingMethods.value.find((x) => x.name === "Standard Shipping")
|
|
117
126
|
).toBeDefined();
|
|
118
127
|
});
|
|
119
128
|
it("can add a payment instruction", async () => {
|
|
@@ -122,7 +131,10 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
122
131
|
checkout: checkout.identifier
|
|
123
132
|
}
|
|
124
133
|
);
|
|
125
|
-
|
|
134
|
+
if (!paymentMethods.success) {
|
|
135
|
+
assert.fail();
|
|
136
|
+
}
|
|
137
|
+
const pm = paymentMethods.value.find((x) => x.identifier.method === "pp_stripe_stripe");
|
|
126
138
|
expect(pm).toBeDefined();
|
|
127
139
|
const checkoutWithPi = await client.checkout.addPaymentInstruction(
|
|
128
140
|
{
|
|
@@ -134,11 +146,14 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
148
|
);
|
|
137
|
-
|
|
138
|
-
|
|
149
|
+
if (!checkoutWithPi.success) {
|
|
150
|
+
assert.fail();
|
|
151
|
+
}
|
|
152
|
+
expect(checkoutWithPi.value.paymentInstructions.length).toBe(1);
|
|
153
|
+
expect(checkoutWithPi.value.paymentInstructions[0].paymentMethod.method).toBe(
|
|
139
154
|
"pp_stripe_stripe"
|
|
140
155
|
);
|
|
141
|
-
expect(checkoutWithPi.paymentInstructions[0].protocolData.find((x) => x.key === "client_secret")?.value).toBeDefined();
|
|
156
|
+
expect(checkoutWithPi.value.paymentInstructions[0].protocolData.find((x) => x.key === "client_secret")?.value).toBeDefined();
|
|
142
157
|
});
|
|
143
158
|
it.skip("can cancel an in-progress payment", async () => {
|
|
144
159
|
const paymentMethods = await client.checkout.getAvailablePaymentMethods(
|
|
@@ -146,7 +161,10 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
146
161
|
checkout: checkout.identifier
|
|
147
162
|
}
|
|
148
163
|
);
|
|
149
|
-
|
|
164
|
+
if (!paymentMethods.success) {
|
|
165
|
+
assert.fail();
|
|
166
|
+
}
|
|
167
|
+
const pm = paymentMethods.value.find((x) => x.identifier.method === "pp_stripe_stripe");
|
|
150
168
|
expect(pm).toBeDefined();
|
|
151
169
|
const checkoutWithPi = await client.checkout.addPaymentInstruction(
|
|
152
170
|
{
|
|
@@ -158,14 +176,20 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
158
176
|
}
|
|
159
177
|
}
|
|
160
178
|
);
|
|
161
|
-
|
|
179
|
+
if (!checkoutWithPi.success) {
|
|
180
|
+
assert.fail();
|
|
181
|
+
}
|
|
182
|
+
expect(checkoutWithPi.value.paymentInstructions.length).toBe(1);
|
|
162
183
|
const checkoutAfterCancel = await client.checkout.removePaymentInstruction(
|
|
163
184
|
{
|
|
164
185
|
checkout: checkout.identifier,
|
|
165
|
-
paymentInstruction: checkoutWithPi.paymentInstructions[0].identifier
|
|
186
|
+
paymentInstruction: checkoutWithPi.value.paymentInstructions[0].identifier
|
|
166
187
|
}
|
|
167
188
|
);
|
|
168
|
-
|
|
189
|
+
if (!checkoutAfterCancel.success) {
|
|
190
|
+
assert.fail();
|
|
191
|
+
}
|
|
192
|
+
expect(checkoutAfterCancel.value.paymentInstructions.length).toBe(0);
|
|
169
193
|
});
|
|
170
194
|
it("can set shipping address", async () => {
|
|
171
195
|
const checkoutWithShipping = await client.checkout.setShippingAddress(
|
|
@@ -183,8 +207,11 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
183
207
|
}
|
|
184
208
|
}
|
|
185
209
|
);
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
if (!checkoutWithShipping.success) {
|
|
211
|
+
assert.fail();
|
|
212
|
+
}
|
|
213
|
+
expect(checkoutWithShipping.value.shippingAddress).toBeDefined();
|
|
214
|
+
expect(checkoutWithShipping.value.shippingAddress?.firstName).toBe("Jane");
|
|
188
215
|
});
|
|
189
216
|
it("can set shipping instructions", async () => {
|
|
190
217
|
const shippingMethods = await client.checkout.getAvailableShippingMethods(
|
|
@@ -192,20 +219,16 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
192
219
|
checkout: checkout.identifier
|
|
193
220
|
}
|
|
194
221
|
);
|
|
195
|
-
|
|
222
|
+
if (!shippingMethods.success) {
|
|
223
|
+
assert.fail();
|
|
224
|
+
}
|
|
225
|
+
const sm = shippingMethods.value.find((x) => x.name === "Standard Shipping");
|
|
196
226
|
expect(sm).toBeDefined();
|
|
197
227
|
const shippingInstruction = {
|
|
198
228
|
shippingMethod: sm?.identifier || { key: "" },
|
|
199
229
|
instructions: "Leave at front door if not home",
|
|
200
230
|
consentForUnattendedDelivery: true,
|
|
201
|
-
pickupPoint: "4190asx141"
|
|
202
|
-
meta: {
|
|
203
|
-
cache: {
|
|
204
|
-
hit: false,
|
|
205
|
-
key: ""
|
|
206
|
-
},
|
|
207
|
-
placeholder: false
|
|
208
|
-
}
|
|
231
|
+
pickupPoint: "4190asx141"
|
|
209
232
|
};
|
|
210
233
|
const checkoutWithShipping = await client.checkout.setShippingInstruction(
|
|
211
234
|
{
|
|
@@ -213,29 +236,34 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
213
236
|
shippingInstruction
|
|
214
237
|
}
|
|
215
238
|
);
|
|
239
|
+
if (!checkoutWithShipping.success) {
|
|
240
|
+
assert.fail();
|
|
241
|
+
}
|
|
216
242
|
expect(checkout.price.totalShipping.value).toBe(0);
|
|
217
|
-
expect(checkoutWithShipping.price.totalShipping.value).toBeGreaterThan(0);
|
|
218
|
-
expect(checkoutWithShipping.shippingInstruction).toBeDefined();
|
|
243
|
+
expect(checkoutWithShipping.value.price.totalShipping.value).toBeGreaterThan(0);
|
|
244
|
+
expect(checkoutWithShipping.value.shippingInstruction).toBeDefined();
|
|
219
245
|
expect(
|
|
220
|
-
checkoutWithShipping.shippingInstruction?.shippingMethod.key
|
|
246
|
+
checkoutWithShipping.value.shippingInstruction?.shippingMethod.key
|
|
221
247
|
).toBe(sm?.identifier.key);
|
|
222
|
-
expect(checkoutWithShipping.shippingInstruction?.instructions).toBe(
|
|
248
|
+
expect(checkoutWithShipping.value.shippingInstruction?.instructions).toBe(
|
|
223
249
|
"Leave at front door if not home"
|
|
224
250
|
);
|
|
225
|
-
expect(checkoutWithShipping.shippingInstruction?.pickupPoint).toBe(
|
|
251
|
+
expect(checkoutWithShipping.value.shippingInstruction?.pickupPoint).toBe(
|
|
226
252
|
"4190asx141"
|
|
227
253
|
);
|
|
228
254
|
expect(
|
|
229
|
-
checkoutWithShipping.shippingInstruction?.consentForUnattendedDelivery
|
|
255
|
+
checkoutWithShipping.value.shippingInstruction?.consentForUnattendedDelivery
|
|
230
256
|
).toBe(true);
|
|
231
257
|
});
|
|
232
258
|
it.skip("wont report it finalizable until everything is paid/authorized", async () => {
|
|
233
259
|
expect(checkout.readyForFinalization).toBe(false);
|
|
234
|
-
const pm = (
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
260
|
+
const pm = unwrapValue(
|
|
261
|
+
await client.checkout.getAvailablePaymentMethods(
|
|
262
|
+
{
|
|
263
|
+
checkout: checkout.identifier
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
).find((x) => x.identifier.method === "stripe");
|
|
239
267
|
expect(pm).toBeDefined();
|
|
240
268
|
const checkoutWithPi = await client.checkout.addPaymentInstruction(
|
|
241
269
|
{
|
|
@@ -247,13 +275,16 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
|
|
|
247
275
|
}
|
|
248
276
|
}
|
|
249
277
|
);
|
|
278
|
+
if (!checkoutWithPi.success) {
|
|
279
|
+
assert.fail();
|
|
280
|
+
}
|
|
250
281
|
const checkoutReady = await client.checkout.getById(
|
|
251
|
-
{ identifier: checkoutWithPi.identifier }
|
|
282
|
+
{ identifier: checkoutWithPi.value.identifier }
|
|
252
283
|
);
|
|
253
|
-
if (!checkoutReady) {
|
|
284
|
+
if (!checkoutReady.success || !checkoutReady) {
|
|
254
285
|
expect.fail("checkout not found");
|
|
255
286
|
}
|
|
256
|
-
expect(checkoutReady.readyForFinalization).toBe(true);
|
|
287
|
+
expect(checkoutReady.value.readyForFinalization).toBe(true);
|
|
257
288
|
});
|
|
258
289
|
});
|
|
259
290
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
1
|
+
import { describe, it, expect, beforeEach, assert } from "vitest";
|
|
2
2
|
import { MedusaIdentityProvider } from "../providers/identity.provider.js";
|
|
3
3
|
import { IdentitySchema, NoOpCache, createInitialRequestContext } from "@reactionary/core";
|
|
4
4
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
@@ -20,8 +20,11 @@ describe("Medusa Identity Provider", () => {
|
|
|
20
20
|
});
|
|
21
21
|
it("should return anonymous identity when not authenticated", async () => {
|
|
22
22
|
const result = await provider.getSelf({});
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (!result.success) {
|
|
24
|
+
assert.fail();
|
|
25
|
+
}
|
|
26
|
+
expect(result.value).toBeTruthy();
|
|
27
|
+
expect(result.value.type).toBe("Anonymous");
|
|
25
28
|
});
|
|
26
29
|
it("should be able to register a new user", async () => {
|
|
27
30
|
const testEmail = `test-user+${(/* @__PURE__ */ new Date()).getTime()}@example.com`;
|
|
@@ -29,8 +32,11 @@ describe("Medusa Identity Provider", () => {
|
|
|
29
32
|
username: testEmail,
|
|
30
33
|
password: testData.testPassword
|
|
31
34
|
});
|
|
35
|
+
if (!result.success) {
|
|
36
|
+
assert.fail();
|
|
37
|
+
}
|
|
32
38
|
expect(result).toBeTruthy();
|
|
33
|
-
expect(["Registered", "Anonymous"]).toContain(result.type);
|
|
39
|
+
expect(["Registered", "Anonymous"]).toContain(result.value.type);
|
|
34
40
|
});
|
|
35
41
|
it("should be able to login with valid credentials", async () => {
|
|
36
42
|
try {
|
|
@@ -45,8 +51,11 @@ describe("Medusa Identity Provider", () => {
|
|
|
45
51
|
username: testData.testEmail,
|
|
46
52
|
password: testData.testPassword
|
|
47
53
|
});
|
|
54
|
+
if (!result.success) {
|
|
55
|
+
assert.fail();
|
|
56
|
+
}
|
|
48
57
|
expect(result).toBeTruthy();
|
|
49
|
-
expect(["Registered", "Anonymous"]).toContain(result.type);
|
|
58
|
+
expect(["Registered", "Anonymous"]).toContain(result.value.type);
|
|
50
59
|
});
|
|
51
60
|
it("should be able to logout", async () => {
|
|
52
61
|
await provider.login({
|
|
@@ -54,8 +63,11 @@ describe("Medusa Identity Provider", () => {
|
|
|
54
63
|
password: testData.testPassword
|
|
55
64
|
});
|
|
56
65
|
const result = await provider.logout({});
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
assert.fail();
|
|
68
|
+
}
|
|
57
69
|
expect(result).toBeTruthy();
|
|
58
|
-
expect(result.type).toBe("Anonymous");
|
|
70
|
+
expect(result.value.type).toBe("Anonymous");
|
|
59
71
|
});
|
|
60
72
|
it("should return registered identity when authenticated", async () => {
|
|
61
73
|
await provider.login({
|
|
@@ -63,8 +75,11 @@ describe("Medusa Identity Provider", () => {
|
|
|
63
75
|
password: testData.testPassword
|
|
64
76
|
});
|
|
65
77
|
const result = await provider.getSelf({});
|
|
78
|
+
if (!result.success) {
|
|
79
|
+
assert.fail();
|
|
80
|
+
}
|
|
66
81
|
expect(result).toBeTruthy();
|
|
67
|
-
expect(["Registered", "Anonymous"]).toContain(result.type);
|
|
82
|
+
expect(["Registered", "Anonymous"]).toContain(result.value.type);
|
|
68
83
|
});
|
|
69
84
|
it("should handle login errors gracefully", async () => {
|
|
70
85
|
await expect(async () => {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
1
|
+
import { describe, it, expect, beforeEach, assert } from "vitest";
|
|
2
2
|
import { MedusaInventoryProvider } from "../providers/inventory.provider.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
InventorySchema,
|
|
5
|
+
NoOpCache,
|
|
6
|
+
createInitialRequestContext
|
|
7
|
+
} from "@reactionary/core";
|
|
4
8
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
5
9
|
import { MedusaClient } from "../core/client.js";
|
|
6
10
|
const testData = {
|
|
@@ -15,22 +19,28 @@ describe("Medusa Inventory Provider", () => {
|
|
|
15
19
|
reqCtx = createInitialRequestContext();
|
|
16
20
|
const config = getMedusaTestConfiguration();
|
|
17
21
|
const client = new MedusaClient(config, reqCtx);
|
|
18
|
-
provider = new MedusaInventoryProvider(
|
|
22
|
+
provider = new MedusaInventoryProvider(
|
|
23
|
+
config,
|
|
24
|
+
new NoOpCache(),
|
|
25
|
+
reqCtx,
|
|
26
|
+
client
|
|
27
|
+
);
|
|
19
28
|
});
|
|
20
29
|
it("should be able to get inventory for a SKU with stock", async () => {
|
|
21
30
|
const result = await provider.getBySKU({
|
|
22
31
|
variant: { sku: testData.skuInStock },
|
|
23
32
|
fulfilmentCenter: { key: testData.fulfillmentCenter }
|
|
24
33
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
if (!result.success) {
|
|
35
|
+
assert.fail();
|
|
36
|
+
}
|
|
37
|
+
expect(result.value.identifier.variant.sku).toBe(testData.skuInStock);
|
|
38
|
+
expect(result.value.identifier.fulfillmentCenter.key).toBe(
|
|
39
|
+
testData.fulfillmentCenter
|
|
40
|
+
);
|
|
41
|
+
expect(result.value.quantity).toBeGreaterThanOrEqual(0);
|
|
42
|
+
if (result.value.quantity > 0) {
|
|
43
|
+
expect(result.value.status).toBe("inStock");
|
|
34
44
|
}
|
|
35
45
|
});
|
|
36
46
|
it("should return out of stock for a SKU without inventory", async () => {
|
|
@@ -38,25 +48,26 @@ describe("Medusa Inventory Provider", () => {
|
|
|
38
48
|
variant: { sku: testData.skuOutOfStock },
|
|
39
49
|
fulfilmentCenter: { key: testData.fulfillmentCenter }
|
|
40
50
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
expect(result.identifier.variant.sku).toBe(testData.skuOutOfStock);
|
|
44
|
-
expect(result.identifier.fulfillmentCenter.key).toBe(testData.fulfillmentCenter);
|
|
45
|
-
expect(result.quantity).toBe(0);
|
|
46
|
-
expect(result.status).toBe("outOfStock");
|
|
51
|
+
if (!result.success) {
|
|
52
|
+
assert.fail();
|
|
47
53
|
}
|
|
54
|
+
expect(result.value.identifier.variant.sku).toBe(testData.skuOutOfStock);
|
|
55
|
+
expect(result.value.identifier.fulfillmentCenter.key).toBe(
|
|
56
|
+
testData.fulfillmentCenter
|
|
57
|
+
);
|
|
58
|
+
expect(result.value.quantity).toBe(0);
|
|
59
|
+
expect(result.value.status).toBe("outOfStock");
|
|
48
60
|
});
|
|
49
61
|
it("should return placeholder inventory for an unknown SKU", async () => {
|
|
50
62
|
const result = await provider.getBySKU({
|
|
51
63
|
variant: { sku: "unknown-sku" },
|
|
52
64
|
fulfilmentCenter: { key: testData.fulfillmentCenter }
|
|
53
65
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(result.identifier.variant.sku).toBe("unknown-sku");
|
|
57
|
-
expect(result.quantity).toBe(0);
|
|
58
|
-
expect(result.status).toBe("outOfStock");
|
|
59
|
-
expect(result.meta?.placeholder).toBe(true);
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
assert.fail();
|
|
60
68
|
}
|
|
69
|
+
expect(result.value.identifier.variant.sku).toBe("unknown-sku");
|
|
70
|
+
expect(result.value.quantity).toBe(0);
|
|
71
|
+
expect(result.value.status).toBe("outOfStock");
|
|
61
72
|
});
|
|
62
73
|
});
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CartSchema,
|
|
3
|
+
NoOpCache,
|
|
4
|
+
ProductSearchQueryByTermSchema,
|
|
5
|
+
ProductSearchResultItemSchema,
|
|
6
|
+
createInitialRequestContext
|
|
7
|
+
} from "@reactionary/core";
|
|
8
|
+
import { assert, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
3
9
|
import { MedusaCartProvider } from "../providers/cart.provider.js";
|
|
4
10
|
import { MedusaSearchProvider } from "../providers/product-search.provider.js";
|
|
5
11
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
@@ -11,46 +17,66 @@ describe("Medusa Cart Provider - Large Scenarios", () => {
|
|
|
11
17
|
beforeEach(() => {
|
|
12
18
|
reqCtx = createInitialRequestContext();
|
|
13
19
|
const client = new MedusaClient(getMedusaTestConfiguration(), reqCtx);
|
|
14
|
-
provider = new MedusaCartProvider(
|
|
15
|
-
|
|
20
|
+
provider = new MedusaCartProvider(
|
|
21
|
+
getMedusaTestConfiguration(),
|
|
22
|
+
new NoOpCache(),
|
|
23
|
+
reqCtx,
|
|
24
|
+
client
|
|
25
|
+
);
|
|
26
|
+
searchProvider = new MedusaSearchProvider(
|
|
27
|
+
getMedusaTestConfiguration(),
|
|
28
|
+
new NoOpCache(),
|
|
29
|
+
reqCtx,
|
|
30
|
+
client
|
|
31
|
+
);
|
|
16
32
|
});
|
|
17
33
|
describe("large carts", () => {
|
|
18
34
|
it("should be able to add an 50 items to a cart in less than 30 seconds", async () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const searchResult = await searchProvider.queryByTerm(
|
|
36
|
+
ProductSearchQueryByTermSchema.parse({
|
|
37
|
+
search: {
|
|
38
|
+
term: "phil",
|
|
39
|
+
paginationOptions: {
|
|
40
|
+
pageNumber: 1,
|
|
41
|
+
pageSize: 50
|
|
42
|
+
},
|
|
43
|
+
filters: [],
|
|
44
|
+
facets: []
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
if (!searchResult.success) {
|
|
49
|
+
assert.fail();
|
|
50
|
+
}
|
|
51
|
+
expect(searchResult.value.items.length).toBeGreaterThanOrEqual(50);
|
|
52
|
+
let cartIdentifier = void 0;
|
|
53
|
+
let cart;
|
|
54
|
+
for (const product of searchResult.value.items) {
|
|
35
55
|
cart = await provider.add({
|
|
36
|
-
cart:
|
|
56
|
+
cart: cartIdentifier,
|
|
37
57
|
variant: {
|
|
38
58
|
sku: product.variants[0].variant.sku
|
|
39
59
|
},
|
|
40
60
|
quantity: 1
|
|
41
61
|
});
|
|
62
|
+
if (!cart.success) {
|
|
63
|
+
assert.fail();
|
|
64
|
+
}
|
|
65
|
+
cartIdentifier = cart.value.identifier;
|
|
42
66
|
}
|
|
43
|
-
if (cart) {
|
|
44
|
-
|
|
45
|
-
expect(cart.items.length).toBe(50);
|
|
46
|
-
expect(cart.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
47
|
-
expect(cart.items[0].price.totalPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
48
|
-
expect(cart.price.grandTotal.value).toBeGreaterThan(0);
|
|
49
|
-
expect(cart.price.grandTotal.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
50
|
-
expect(cart.meta?.placeholder).toBeFalsy();
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error("Cart is undefined");
|
|
67
|
+
if (!cart) {
|
|
68
|
+
assert.fail();
|
|
53
69
|
}
|
|
70
|
+
expect(cart.value.identifier.key).toBeDefined();
|
|
71
|
+
expect(cart.value.items.length).toBe(50);
|
|
72
|
+
expect(cart.value.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
73
|
+
expect(cart.value.items[0].price.totalPrice.currency).toBe(
|
|
74
|
+
reqCtx.languageContext.currencyCode
|
|
75
|
+
);
|
|
76
|
+
expect(cart.value.price.grandTotal.value).toBeGreaterThan(0);
|
|
77
|
+
expect(cart.value.price.grandTotal.currency).toBe(
|
|
78
|
+
reqCtx.languageContext.currencyCode
|
|
79
|
+
);
|
|
54
80
|
}, 3e4);
|
|
55
81
|
});
|
|
56
82
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
1
|
+
import { describe, it, expect, beforeEach, vi, assert } from "vitest";
|
|
2
2
|
import { MedusaPriceProvider } from "../providers/price.provider.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
PriceSchema,
|
|
5
|
+
NoOpCache,
|
|
6
|
+
createInitialRequestContext
|
|
7
|
+
} from "@reactionary/core";
|
|
4
8
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
5
9
|
import { MedusaClient } from "../core/client.js";
|
|
6
10
|
const testData = {
|
|
@@ -17,47 +21,64 @@ describe("Medusa Price Provider", () => {
|
|
|
17
21
|
provider = new MedusaPriceProvider(config, new NoOpCache(), reqCtx, client);
|
|
18
22
|
});
|
|
19
23
|
it("should be able to get prices for a product without tiers", async () => {
|
|
20
|
-
const result = await provider.getCustomerPrice({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
expect(result.unitPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
26
|
-
expect(result.tieredPrices.length).toBe(0);
|
|
24
|
+
const result = await provider.getCustomerPrice({
|
|
25
|
+
variant: { sku: testData.skuWithoutTiers }
|
|
26
|
+
});
|
|
27
|
+
if (!result.success) {
|
|
28
|
+
assert.fail();
|
|
27
29
|
}
|
|
30
|
+
expect(result.value.identifier.variant.sku).toBe(testData.skuWithoutTiers);
|
|
31
|
+
expect(result.value.unitPrice.value).toBeGreaterThan(0);
|
|
32
|
+
expect(result.value.unitPrice.currency).toBe(
|
|
33
|
+
reqCtx.languageContext.currencyCode
|
|
34
|
+
);
|
|
35
|
+
expect(result.value.tieredPrices.length).toBe(0);
|
|
28
36
|
});
|
|
29
37
|
it.skip("should be able to get prices for a product with tiers", async () => {
|
|
30
|
-
const result = await provider.getCustomerPrice({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(result.unitPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
36
|
-
expect(result.tieredPrices.length).toBeGreaterThan(0);
|
|
37
|
-
expect(result.tieredPrices[0].minimumQuantity).toBeGreaterThan(0);
|
|
38
|
-
expect(result.tieredPrices[0].price.value).toBeLessThanOrEqual(result.unitPrice.value);
|
|
39
|
-
expect(result.tieredPrices[0].price.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
38
|
+
const result = await provider.getCustomerPrice({
|
|
39
|
+
variant: { sku: testData.skuWithTiers }
|
|
40
|
+
});
|
|
41
|
+
if (!result.success) {
|
|
42
|
+
assert.fail();
|
|
40
43
|
}
|
|
44
|
+
expect(result.value.identifier.variant.sku).toBe(testData.skuWithTiers);
|
|
45
|
+
expect(result.value.unitPrice.value).toBeGreaterThan(0);
|
|
46
|
+
expect(result.value.unitPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
47
|
+
expect(result.value.tieredPrices.length).toBeGreaterThan(0);
|
|
48
|
+
expect(result.value.tieredPrices[0].minimumQuantity).toBeGreaterThan(0);
|
|
49
|
+
expect(result.value.tieredPrices[0].price.value).toBeLessThanOrEqual(
|
|
50
|
+
result.value.unitPrice.value
|
|
51
|
+
);
|
|
52
|
+
expect(result.value.tieredPrices[0].price.currency).toBe(
|
|
53
|
+
reqCtx.languageContext.currencyCode
|
|
54
|
+
);
|
|
41
55
|
});
|
|
42
|
-
it("should return
|
|
43
|
-
const result = await provider.getCustomerPrice({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(result.unitPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
49
|
-
expect(result.tieredPrices.length).toBe(0);
|
|
50
|
-
expect(result.meta?.placeholder).toBe(true);
|
|
56
|
+
it("should return NotFound for an unknown SKU", async () => {
|
|
57
|
+
const result = await provider.getCustomerPrice({
|
|
58
|
+
variant: { sku: "unknown-sku" }
|
|
59
|
+
});
|
|
60
|
+
if (result.success) {
|
|
61
|
+
assert.fail();
|
|
51
62
|
}
|
|
52
63
|
});
|
|
53
64
|
it("can look up multiple prices at once", async () => {
|
|
54
|
-
const skus = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
const skus = [
|
|
66
|
+
testData.skuWithTiers,
|
|
67
|
+
testData.skuWithoutTiers,
|
|
68
|
+
"unknown-sku"
|
|
69
|
+
];
|
|
70
|
+
const results = await Promise.all(
|
|
71
|
+
skus.map((sku) => provider.getCustomerPrice({ variant: { sku } }))
|
|
72
|
+
);
|
|
73
|
+
const success = results.filter((x) => x.success);
|
|
74
|
+
if (results.length !== success.length) {
|
|
75
|
+
assert.fail();
|
|
76
|
+
}
|
|
77
|
+
expect(success).toHaveLength(skus.length);
|
|
78
|
+
expect(success[0].value.identifier.variant.sku).toBe(testData.skuWithTiers);
|
|
79
|
+
expect(success[0].value.unitPrice.value).toBeGreaterThan(0);
|
|
80
|
+
expect(success[1].value.identifier.variant.sku).toBe(testData.skuWithoutTiers);
|
|
81
|
+
expect(success[1].value.unitPrice.value).toBeGreaterThan(0);
|
|
82
|
+
expect(success[2].value.identifier.variant.sku).toBe("unknown-sku");
|
|
62
83
|
});
|
|
63
84
|
});
|