@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
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
NoOpCache,
|
|
4
|
+
ProductSchema,
|
|
5
|
+
createInitialRequestContext
|
|
6
|
+
} from "@reactionary/core";
|
|
3
7
|
import { MedusaProductProvider } from "../providers/product.provider.js";
|
|
4
8
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
5
|
-
import { describe, expect, it, beforeAll, beforeEach } from "vitest";
|
|
9
|
+
import { describe, expect, it, beforeAll, beforeEach, assert } from "vitest";
|
|
6
10
|
import { MedusaClient } from "../index.js";
|
|
7
11
|
const testData = {
|
|
8
12
|
product: {
|
|
@@ -21,57 +25,77 @@ describe("Medusa Product Provider", () => {
|
|
|
21
25
|
beforeEach(() => {
|
|
22
26
|
reqCtx = createInitialRequestContext();
|
|
23
27
|
const client = new MedusaClient(getMedusaTestConfiguration(), reqCtx);
|
|
24
|
-
provider = new MedusaProductProvider(
|
|
28
|
+
provider = new MedusaProductProvider(
|
|
29
|
+
getMedusaTestConfiguration(),
|
|
30
|
+
new NoOpCache(),
|
|
31
|
+
reqCtx,
|
|
32
|
+
client
|
|
33
|
+
);
|
|
25
34
|
});
|
|
26
35
|
it("should be able to get a product by id", async () => {
|
|
27
|
-
const slugResult = await provider.getBySlug({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
expect(result.
|
|
36
|
+
const slugResult = await provider.getBySlug({
|
|
37
|
+
slug: testData.product.slug
|
|
38
|
+
});
|
|
39
|
+
if (!slugResult.success) {
|
|
40
|
+
assert.fail();
|
|
41
|
+
}
|
|
42
|
+
const result = await provider.getById({
|
|
43
|
+
identifier: slugResult.value.identifier
|
|
44
|
+
});
|
|
45
|
+
if (!result.success) {
|
|
46
|
+
assert.fail();
|
|
47
|
+
}
|
|
48
|
+
expect(result.value.identifier.key).toBe(slugResult.value.identifier.key);
|
|
49
|
+
expect(result.value.name).toBe(testData.product.name);
|
|
50
|
+
expect(result.value.mainVariant).toBeDefined();
|
|
51
|
+
expect(result.value.mainVariant.identifier.sku).toBe(testData.product.sku);
|
|
52
|
+
expect(result.value.mainVariant.images[0].sourceUrl).toBe(
|
|
53
|
+
testData.product.image
|
|
54
|
+
);
|
|
55
|
+
expect(result.value.sharedAttributes.length).toBeGreaterThan(1);
|
|
56
|
+
expect(result.value.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
57
|
+
expect(result.value.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
40
58
|
});
|
|
41
59
|
it("should be able to get a product with multiple variants by slug", async () => {
|
|
42
|
-
const result = await provider.getBySlug({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(result.slug).toBe(testData.productWithMultiVariants.slug);
|
|
48
|
-
expect(result.mainVariant).toBeDefined();
|
|
49
|
-
expect(result.variants.length).toBeGreaterThan(0);
|
|
50
|
-
expect(result.variants[0].identifier.sku).toBeTruthy();
|
|
51
|
-
expect(result.variants[0].identifier.sku).not.toBe(result.mainVariant.identifier.sku);
|
|
52
|
-
expect(result.sharedAttributes.length).toBeGreaterThan(1);
|
|
53
|
-
expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
54
|
-
expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
60
|
+
const result = await provider.getBySlug({
|
|
61
|
+
slug: testData.productWithMultiVariants.slug
|
|
62
|
+
});
|
|
63
|
+
if (!result.success) {
|
|
64
|
+
assert.fail();
|
|
55
65
|
}
|
|
66
|
+
expect(result.value.identifier.key).toBeTruthy();
|
|
67
|
+
expect(result.value.slug).toBe(testData.productWithMultiVariants.slug);
|
|
68
|
+
expect(result.value.mainVariant).toBeDefined();
|
|
69
|
+
expect(result.value.variants.length).toBeGreaterThan(0);
|
|
70
|
+
expect(result.value.variants[0].identifier.sku).toBeTruthy();
|
|
71
|
+
expect(result.value.variants[0].identifier.sku).not.toBe(
|
|
72
|
+
result.value.mainVariant.identifier.sku
|
|
73
|
+
);
|
|
74
|
+
expect(result.value.sharedAttributes.length).toBeGreaterThan(1);
|
|
75
|
+
expect(result.value.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
76
|
+
expect(result.value.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
56
77
|
});
|
|
57
78
|
it("should be able to get a product by sku", async () => {
|
|
58
|
-
const slugResult = await provider.getBySlug({
|
|
59
|
-
|
|
79
|
+
const slugResult = await provider.getBySlug({
|
|
80
|
+
slug: testData.product.slug
|
|
81
|
+
});
|
|
82
|
+
if (!slugResult.success) {
|
|
83
|
+
assert.fail();
|
|
84
|
+
}
|
|
60
85
|
const result = await provider.getBySKU({
|
|
61
86
|
variant: { sku: testData.product.sku }
|
|
62
87
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
expect(result.meta.placeholder).toBe(false);
|
|
66
|
-
expect(result.identifier.key).toBe(slugResult?.identifier.key);
|
|
67
|
-
expect(result.name).toBe(testData.product.name);
|
|
68
|
-
expect(result.mainVariant).toBeDefined();
|
|
69
|
-
expect(result.mainVariant.identifier.sku).toBe(testData.product.sku);
|
|
70
|
-
expect(result.mainVariant.images[0].sourceUrl).toBe(testData.product.image);
|
|
71
|
-
expect(result.sharedAttributes.length).toBeGreaterThan(1);
|
|
72
|
-
expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
73
|
-
expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
88
|
+
if (!result.success) {
|
|
89
|
+
assert.fail();
|
|
74
90
|
}
|
|
91
|
+
expect(result.value.identifier.key).toBe(slugResult.value.identifier.key);
|
|
92
|
+
expect(result.value.name).toBe(testData.product.name);
|
|
93
|
+
expect(result.value.mainVariant).toBeDefined();
|
|
94
|
+
expect(result.value.mainVariant.identifier.sku).toBe(testData.product.sku);
|
|
95
|
+
expect(result.value.mainVariant.images[0].sourceUrl).toBe(testData.product.image);
|
|
96
|
+
expect(result.value.sharedAttributes.length).toBeGreaterThan(1);
|
|
97
|
+
expect(result.value.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
98
|
+
expect(result.value.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
75
99
|
});
|
|
76
100
|
it("should return null for unknown slug", async () => {
|
|
77
101
|
const result = await provider.getBySlug({ slug: "unknown-slug" });
|
|
@@ -79,14 +103,19 @@ describe("Medusa Product Provider", () => {
|
|
|
79
103
|
});
|
|
80
104
|
it("should contain both product level and variant level attributes", async () => {
|
|
81
105
|
const result = await provider.getBySlug({ slug: testData.product.slug });
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(result.sharedAttributes
|
|
106
|
+
if (!result.success) {
|
|
107
|
+
assert.fail();
|
|
108
|
+
}
|
|
109
|
+
expect(result.value.sharedAttributes.length).toBeGreaterThan(1);
|
|
110
|
+
expect(result.value.sharedAttributes[1].values.length).toBeGreaterThan(0);
|
|
111
|
+
expect(result.value.sharedAttributes[1].values[0].value).toBeTruthy();
|
|
86
112
|
});
|
|
87
113
|
it("should return a placeholder product for unknown id", async () => {
|
|
88
|
-
const result = await provider.getById({
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
const result = await provider.getById({
|
|
115
|
+
identifier: { key: "unknown-id" }
|
|
116
|
+
});
|
|
117
|
+
if (!result.success) {
|
|
118
|
+
assert.fail();
|
|
119
|
+
}
|
|
91
120
|
});
|
|
92
121
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { createInitialRequestContext, NoOpCache, ProductSearchQueryByTermSchema, ProductSearchResultItemSchema } from "@reactionary/core";
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { assert, describe, expect, it } from "vitest";
|
|
4
4
|
import { MedusaSearchProvider } from "../providers/product-search.provider.js";
|
|
5
5
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
6
6
|
import { MedusaClient } from "../index.js";
|
|
@@ -33,8 +33,11 @@ describe("Medusa Search Provider", () => {
|
|
|
33
33
|
facets: [],
|
|
34
34
|
filters: []
|
|
35
35
|
} }));
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (!result.success) {
|
|
37
|
+
assert.fail();
|
|
38
|
+
}
|
|
39
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
40
|
+
expect(result.value.facets.length).toBe(0);
|
|
38
41
|
});
|
|
39
42
|
it("should be able to paginate", async () => {
|
|
40
43
|
const firstPage = await provider.queryByTerm(ProductSearchQueryByTermSchema.parse({ search: {
|
|
@@ -55,10 +58,13 @@ describe("Medusa Search Provider", () => {
|
|
|
55
58
|
facets: [],
|
|
56
59
|
filters: []
|
|
57
60
|
} }));
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
if (!firstPage.success || !secondPage.success) {
|
|
62
|
+
assert.fail();
|
|
63
|
+
}
|
|
64
|
+
expect(firstPage.value.pageNumber).toBe(1);
|
|
65
|
+
expect(secondPage.value.pageNumber).toBe(2);
|
|
66
|
+
expect(firstPage.value.items[0].identifier.key).not.toEqual(
|
|
67
|
+
secondPage.value.items[0].identifier.key
|
|
62
68
|
);
|
|
63
69
|
});
|
|
64
70
|
it("should be able to apply a top level category filter", async () => {
|
|
@@ -68,7 +74,10 @@ describe("Medusa Search Provider", () => {
|
|
|
68
74
|
pageSize: 2
|
|
69
75
|
}
|
|
70
76
|
});
|
|
71
|
-
|
|
77
|
+
if (!categories.success) {
|
|
78
|
+
assert.fail();
|
|
79
|
+
}
|
|
80
|
+
let candidate = categories.value.items[0];
|
|
72
81
|
while (candidate) {
|
|
73
82
|
const children = await categoryProvider.findChildCategories({
|
|
74
83
|
parentId: candidate.identifier,
|
|
@@ -77,8 +86,11 @@ describe("Medusa Search Provider", () => {
|
|
|
77
86
|
pageSize: 10
|
|
78
87
|
}
|
|
79
88
|
});
|
|
80
|
-
if (children.
|
|
81
|
-
|
|
89
|
+
if (!children.success) {
|
|
90
|
+
assert.fail();
|
|
91
|
+
}
|
|
92
|
+
if (children.value.items.length > 0) {
|
|
93
|
+
candidate = children.value.items[0];
|
|
82
94
|
} else {
|
|
83
95
|
break;
|
|
84
96
|
}
|
|
@@ -94,18 +106,27 @@ describe("Medusa Search Provider", () => {
|
|
|
94
106
|
filters: []
|
|
95
107
|
}
|
|
96
108
|
});
|
|
97
|
-
|
|
109
|
+
if (!unfilteredSearch.success) {
|
|
110
|
+
assert.fail();
|
|
111
|
+
}
|
|
112
|
+
expect(unfilteredSearch.value.totalCount).toBeGreaterThan(0);
|
|
98
113
|
const breadCrumb = await categoryProvider.getBreadcrumbPathToCategory({
|
|
99
114
|
id: candidate.identifier
|
|
100
115
|
});
|
|
101
|
-
|
|
116
|
+
if (!breadCrumb.success) {
|
|
117
|
+
assert.fail();
|
|
118
|
+
}
|
|
119
|
+
expect(breadCrumb.value.length).toBeGreaterThan(0);
|
|
102
120
|
const categoryFilter = await provider.createCategoryNavigationFilter({
|
|
103
|
-
categoryPath: breadCrumb
|
|
121
|
+
categoryPath: breadCrumb.value
|
|
104
122
|
});
|
|
123
|
+
if (!categoryFilter.success) {
|
|
124
|
+
assert.fail();
|
|
125
|
+
}
|
|
105
126
|
const filteredSearch = await provider.queryByTerm({
|
|
106
127
|
search: {
|
|
107
128
|
term: "",
|
|
108
|
-
categoryFilter,
|
|
129
|
+
categoryFilter: categoryFilter.value,
|
|
109
130
|
paginationOptions: {
|
|
110
131
|
pageNumber: 1,
|
|
111
132
|
pageSize: 1
|
|
@@ -114,8 +135,11 @@ describe("Medusa Search Provider", () => {
|
|
|
114
135
|
filters: []
|
|
115
136
|
}
|
|
116
137
|
});
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
if (!filteredSearch.success) {
|
|
139
|
+
assert.fail();
|
|
140
|
+
}
|
|
141
|
+
expect(filteredSearch.value.totalCount).toBeLessThan(unfilteredSearch.value.totalCount);
|
|
142
|
+
expect(filteredSearch.value.totalCount).toBeGreaterThan(0);
|
|
119
143
|
});
|
|
120
144
|
it("should be able to change page size", async () => {
|
|
121
145
|
const smallPage = await provider.queryByTerm(ProductSearchQueryByTermSchema.parse({ search: {
|
|
@@ -136,9 +160,12 @@ describe("Medusa Search Provider", () => {
|
|
|
136
160
|
facets: [],
|
|
137
161
|
filters: []
|
|
138
162
|
} }));
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
expect(
|
|
163
|
+
if (!smallPage.success || !largePage.success) {
|
|
164
|
+
assert.fail();
|
|
165
|
+
}
|
|
166
|
+
expect(smallPage.value.items.length).toBe(2);
|
|
167
|
+
expect(smallPage.value.pageSize).toBe(2);
|
|
168
|
+
expect(largePage.value.items.length).toBe(30);
|
|
169
|
+
expect(largePage.value.pageSize).toBe(30);
|
|
143
170
|
});
|
|
144
171
|
});
|