@reactionary/provider-medusa 0.1.4 → 0.1.5

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,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/provider-medusa",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "src/index.d.ts",
7
7
  "dependencies": {
8
8
  "zod": "4.1.9",
9
- "@reactionary/core": "0.1.4",
9
+ "@reactionary/core": "0.1.5",
10
10
  "@medusajs/js-sdk": "^2.0.0",
11
11
  "debug": "^4.3.4",
12
12
  "@medusajs/types": "^2.11.0",
@@ -93,6 +93,12 @@ class MedusaProductProvider extends ProductProvider {
93
93
  throw new Error("Product has no variants " + _body.id);
94
94
  }
95
95
  const mainVariant = this.parseVariant(_body.variants[0], _body);
96
+ const otherVariants = [];
97
+ if (_body.variants.length > 1) {
98
+ otherVariants.push(
99
+ ..._body.variants.slice(1).map((variant) => this.parseVariant(variant, _body))
100
+ );
101
+ }
96
102
  const meta = {
97
103
  cache: { hit: false, key: this.generateCacheKeySingle(identifier) },
98
104
  placeholder: false
@@ -110,7 +116,8 @@ class MedusaProductProvider extends ProductProvider {
110
116
  parentCategories,
111
117
  published: true,
112
118
  sharedAttributes,
113
- slug
119
+ slug,
120
+ variants: otherVariants
114
121
  };
115
122
  return result;
116
123
  }
@@ -10,6 +10,9 @@ const testData = {
10
10
  slug: "lv-ca31-scart-cable-101080",
11
11
  image: "https://images.icecat.biz/img/norm/high/101080-3513.jpg",
12
12
  sku: "4960999194479"
13
+ },
14
+ productWithMultiVariants: {
15
+ slug: "hp-gk859aa-mouse-office-bluetooth-laser-1600-dpi-1377612"
13
16
  }
14
17
  };
15
18
  describe("Medusa Product Provider", () => {
@@ -35,16 +38,20 @@ describe("Medusa Product Provider", () => {
35
38
  expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
36
39
  expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
37
40
  });
38
- it("should be able to get a product by slug", async () => {
39
- const result = await provider.getBySlug({ slug: testData.product.slug });
41
+ it("should be able to get a product with multiple variants by slug", async () => {
42
+ const result = await provider.getBySlug({ slug: testData.productWithMultiVariants.slug });
40
43
  expect(result).toBeTruthy();
41
44
  if (result) {
42
45
  expect(result.meta.placeholder).toBe(false);
43
46
  expect(result.identifier.key).toBeTruthy();
44
- expect(result.name).toBe(testData.product.name);
47
+ expect(result.slug).toBe(testData.productWithMultiVariants.slug);
45
48
  expect(result.mainVariant).toBeDefined();
46
- expect(result.mainVariant.identifier.sku).toBe(testData.product.sku);
47
- expect(result.mainVariant.images[0].sourceUrl).toBe(testData.product.image);
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();
48
55
  }
49
56
  });
50
57
  it("should be able to get a product by sku", async () => {