@reactionary/provider-medusa 0.3.0 → 0.3.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 CHANGED
@@ -1,22 +1,15 @@
1
1
  {
2
2
  "name": "@reactionary/provider-medusa",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "src/index.d.ts",
7
7
  "dependencies": {
8
- "zod": "4.1.9",
9
- "@reactionary/core": "0.3.0",
10
- "@medusajs/js-sdk": "^2.0.0",
11
- "debug": "^4.3.4",
8
+ "@medusajs/js-sdk": "^2.13.0",
9
+ "@reactionary/core": "0.3.2",
10
+ "debug": "^4.4.3",
12
11
  "@medusajs/types": "^2.11.0",
13
- "dotenv": "^17.2.2"
14
- },
15
- "devDependencies": {
16
- "vitest": "*",
17
- "@vitest/ui": "*",
18
- "@vitest/coverage-v8": "*",
19
- "vite-tsconfig-paths": "*"
12
+ "zod": "4.1.9"
20
13
  },
21
14
  "sideEffects": false
22
15
  }
@@ -38,22 +38,30 @@ class MedusaIdentityProvider extends IdentityProvider {
38
38
  const token = await medusaClient.client.getToken();
39
39
  if (!token) {
40
40
  debug("No active session token found, returning anonymous identity");
41
- return success(this.createAnonymousIdentity());
41
+ const identity2 = this.createAnonymousIdentity();
42
+ this.updateIdentityContext(identity2);
43
+ return success(identity2);
42
44
  }
43
45
  const customerResponse = await medusaClient.store.customer.retrieve();
44
46
  if (customerResponse.customer) {
45
47
  debug("Customer authenticated:", customerResponse.customer.email);
46
- return success({
48
+ const identity2 = {
47
49
  id: {
48
50
  userId: customerResponse.customer.id
49
51
  },
50
52
  type: "Registered"
51
- });
53
+ };
54
+ this.updateIdentityContext(identity2);
55
+ return success(identity2);
52
56
  }
53
- return success(this.createAnonymousIdentity());
57
+ const identity = this.createAnonymousIdentity();
58
+ this.updateIdentityContext(identity);
59
+ return success(identity);
54
60
  } catch (error) {
55
61
  debug("getSelf failed, returning anonymous identity:", error);
56
- return success(this.createAnonymousIdentity());
62
+ const identity = this.createAnonymousIdentity();
63
+ this.updateIdentityContext(identity);
64
+ return success(identity);
57
65
  }
58
66
  }
59
67
  async login(payload) {
@@ -63,11 +71,13 @@ class MedusaIdentityProvider extends IdentityProvider {
63
71
  payload.password,
64
72
  this.context
65
73
  );
74
+ this.updateIdentityContext(identity);
66
75
  return success(identity);
67
76
  }
68
77
  async logout(_payload) {
69
78
  debug("Logging out user");
70
79
  const identity = await this.medusaApi.logout(this.context);
80
+ this.updateIdentityContext(identity);
71
81
  return success(identity);
72
82
  }
73
83
  async register(payload) {
@@ -83,6 +93,7 @@ class MedusaIdentityProvider extends IdentityProvider {
83
93
  lastName,
84
94
  this.context
85
95
  );
96
+ this.updateIdentityContext(identity);
86
97
  return success(identity);
87
98
  }
88
99
  }
@@ -77,18 +77,14 @@ class MedusaProfileProvider extends ProfileProvider {
77
77
  if (existingAddress) {
78
78
  return error({
79
79
  type: "InvalidInput",
80
- error: {
81
- message: "Address with the same nickname already exists"
82
- }
80
+ error: "Address with the same nickname already exists"
83
81
  });
84
82
  }
85
83
  const response = await client.store.customer.createAddress(medusaAddress, { fields: this.includedFields.join(",") });
86
84
  if (!response.customer) {
87
85
  return error({
88
86
  type: "InvalidInput",
89
- error: {
90
- message: "Failed to add shipping address"
91
- }
87
+ error: "Failed to add shipping address"
92
88
  });
93
89
  }
94
90
  const model = this.parseSingle(response.customer);
@@ -116,9 +112,7 @@ class MedusaProfileProvider extends ProfileProvider {
116
112
  if (!response.customer) {
117
113
  return error({
118
114
  type: "InvalidInput",
119
- error: {
120
- message: "Failed to add shipping address"
121
- }
115
+ error: "Failed to add shipping address"
122
116
  });
123
117
  }
124
118
  const model = this.parseSingle(response.customer);
@@ -145,9 +139,7 @@ class MedusaProfileProvider extends ProfileProvider {
145
139
  if (!response.deleted) {
146
140
  return error({
147
141
  type: "InvalidInput",
148
- error: {
149
- message: "Failed to delete shipping address"
150
- }
142
+ error: "Failed to delete shipping address"
151
143
  });
152
144
  }
153
145
  const customerAfterDelete = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
@@ -196,9 +188,7 @@ class MedusaProfileProvider extends ProfileProvider {
196
188
  if (existingAddressWithNickname && !existingAddressWithNickname.is_default_billing) {
197
189
  return error({
198
190
  type: "InvalidInput",
199
- error: {
200
- message: "Another address with the same nickname already exists"
201
- }
191
+ error: "Another address with the same nickname already exists"
202
192
  });
203
193
  }
204
194
  const newAddr = this.createMedusaAddress(payload.address);
@@ -15,46 +15,14 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
15
15
  pageSize: number;
16
16
  totalCount: number;
17
17
  totalPages: number;
18
- items: {
19
- identifier: {
20
- key: string;
21
- };
22
- name: string;
23
- slug: string;
24
- text: string;
25
- images: {
26
- sourceUrl: string;
27
- altText: string;
28
- width: number;
29
- height: number;
30
- }[];
31
- parentCategory?: {
32
- key: string;
33
- } | undefined;
34
- }[];
18
+ items: Category[];
35
19
  }>>;
36
20
  findTopCategories(payload: CategoryQueryForTopCategories): Promise<import("@reactionary/core").Ok<{
37
21
  pageNumber: number;
38
22
  pageSize: number;
39
23
  totalCount: number;
40
24
  totalPages: number;
41
- items: {
42
- identifier: {
43
- key: string;
44
- };
45
- name: string;
46
- slug: string;
47
- text: string;
48
- images: {
49
- sourceUrl: string;
50
- altText: string;
51
- width: number;
52
- height: number;
53
- }[];
54
- parentCategory?: {
55
- key: string;
56
- } | undefined;
57
- }[];
25
+ items: Category[];
58
26
  }>>;
59
27
  protected parseSingle(_body: StoreProductCategory): Category;
60
28
  protected parsePaginatedResult(body: StoreProductCategoryListResponse): {
@@ -62,22 +30,6 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
62
30
  pageSize: number;
63
31
  totalCount: number;
64
32
  totalPages: number;
65
- items: {
66
- identifier: {
67
- key: string;
68
- };
69
- name: string;
70
- slug: string;
71
- text: string;
72
- images: {
73
- sourceUrl: string;
74
- altText: string;
75
- width: number;
76
- height: number;
77
- }[];
78
- parentCategory?: {
79
- key: string;
80
- } | undefined;
81
- }[];
33
+ items: Category[];
82
34
  };
83
35
  }
@@ -1,4 +1,4 @@
1
- import type { RequestContext, Cache, OrderSearchQueryByTerm, OrderSearchResult, Result, OrderStatus, Address } from '@reactionary/core';
1
+ import type { RequestContext, Cache, OrderSearchQueryByTerm, OrderSearchResult, Result, Address, IdentityIdentifier, MonetaryAmount, OrderSearchResultItem } from '@reactionary/core';
2
2
  import { OrderSearchProvider } from '@reactionary/core';
3
3
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
4
4
  import type { MedusaAPI } from '../core/client.js';
@@ -13,30 +13,17 @@ export declare class MedusaOrderSearchProvider extends OrderSearchProvider {
13
13
  identifier: {
14
14
  key: string;
15
15
  };
16
- userId: {
17
- userId: string;
18
- };
16
+ userId: IdentityIdentifier;
19
17
  customerName: string;
20
- shippingAddress: {
21
- identifier: {
22
- nickName: string;
23
- };
24
- firstName: string;
25
- lastName: string;
26
- streetAddress: string;
27
- streetNumber: string;
28
- city: string;
29
- region: string;
30
- postalCode: string;
31
- countryCode: string;
32
- };
18
+ shippingAddress: Address;
33
19
  orderDate: string;
34
- orderStatus: OrderStatus;
35
- inventoryStatus: "NotAllocated" | "Allocated";
36
- totalAmount: {
37
- value: number;
38
- currency: "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLE" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TVD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VED" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL";
39
- };
20
+ orderStatus: "AwaitingPayment" | "ReleasedToFulfillment" | "Shipped" | "Cancelled";
21
+ inventoryStatus: ("NotAllocated" & {
22
+ _?: never;
23
+ }) | ("Allocated" & {
24
+ _?: never;
25
+ });
26
+ totalAmount: MonetaryAmount;
40
27
  };
41
28
  protected parsePaginatedResult(body: StoreOrderListResponse, query: OrderSearchQueryByTerm): {
42
29
  identifier: {
@@ -58,34 +45,6 @@ export declare class MedusaOrderSearchProvider extends OrderSearchProvider {
58
45
  pageSize: number;
59
46
  totalCount: number;
60
47
  totalPages: number;
61
- items: {
62
- identifier: {
63
- key: string;
64
- };
65
- userId: {
66
- userId: string;
67
- };
68
- customerName: string;
69
- orderDate: string;
70
- orderStatus: "AwaitingPayment" | "ReleasedToFulfillment" | "Shipped" | "Cancelled";
71
- inventoryStatus: "NotAllocated" | "Allocated" | "Backordered" | "Preordered";
72
- totalAmount: {
73
- value: number;
74
- currency: "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLE" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TVD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VED" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL";
75
- };
76
- shippingAddress?: {
77
- identifier: {
78
- nickName: string;
79
- };
80
- firstName: string;
81
- lastName: string;
82
- streetAddress: string;
83
- streetNumber: string;
84
- city: string;
85
- region: string;
86
- postalCode: string;
87
- countryCode: string;
88
- } | undefined;
89
- }[];
48
+ items: OrderSearchResultItem[];
90
49
  };
91
50
  }
@@ -1,4 +1,4 @@
1
- import type { Cache, Order, OrderQueryById, RequestContext, Result, NotFoundError, CostBreakDown, Currency, OrderItem, ItemCostBreakdown } from '@reactionary/core';
1
+ import type { Cache, Order, OrderQueryById, RequestContext, Result, NotFoundError, CostBreakDown, Currency, OrderItem, ItemCostBreakdown, PaymentMethodIdentifier } from '@reactionary/core';
2
2
  import { OrderProvider } from '@reactionary/core';
3
3
  import type { MedusaAPI } from '../core/client.js';
4
4
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
@@ -36,11 +36,7 @@ export declare class MedusaOrderProvider extends OrderProvider {
36
36
  value: number;
37
37
  currency: Currency;
38
38
  };
39
- paymentMethod: {
40
- method: string;
41
- name: string;
42
- paymentProcessor: string;
43
- };
39
+ paymentMethod: PaymentMethodIdentifier;
44
40
  protocolData: {
45
41
  key: string;
46
42
  value: string;
@@ -22,39 +22,7 @@ export declare class MedusaSearchProvider extends ProductSearchProvider {
22
22
  pageSize: number;
23
23
  totalCount: number;
24
24
  totalPages: number;
25
- items: {
26
- identifier: {
27
- key: string;
28
- };
29
- name: string;
30
- slug: string;
31
- variants: {
32
- variant: {
33
- sku: string;
34
- };
35
- image: {
36
- sourceUrl: string;
37
- altText: string;
38
- width?: number | undefined;
39
- height?: number | undefined;
40
- };
41
- options?: {
42
- identifier: {
43
- key: string;
44
- };
45
- name: string;
46
- value: {
47
- identifier: {
48
- option: {
49
- key: string;
50
- };
51
- key: string;
52
- };
53
- label: string;
54
- };
55
- } | undefined;
56
- }[];
57
- }[];
25
+ items: ProductSearchResultItem[];
58
26
  facets: never[];
59
27
  };
60
28
  protected parseSingle(_body: StoreProduct): ProductSearchResultItem;
@@ -1,4 +1,4 @@
1
- import type { Cache, NotFoundError, Product, ProductAttribute, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, Result } from '@reactionary/core';
1
+ import type { Cache, NotFoundError, Product, ProductAttribute, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, ProductVariant, RequestContext, Result } from '@reactionary/core';
2
2
  import { ProductProvider } from '@reactionary/core';
3
3
  import type { MedusaAPI } from '../core/client.js';
4
4
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
@@ -11,37 +11,7 @@ export declare class MedusaProductProvider extends ProductProvider {
11
11
  getBySlug(payload: ProductQueryBySlug): Promise<Result<Product, NotFoundError>>;
12
12
  getBySKU(payload: ProductQueryBySKU): Promise<Result<Product>>;
13
13
  protected parseSingle(_body: StoreProduct): Product;
14
- protected parseVariant(variant: StoreProductVariant, product: StoreProduct): {
15
- identifier: {
16
- sku: string;
17
- };
18
- name: string;
19
- images: {
20
- sourceUrl: string;
21
- altText: string;
22
- width?: number | undefined;
23
- height?: number | undefined;
24
- }[];
25
- ean: string;
26
- gtin: string;
27
- upc: string;
28
- barcode: string;
29
- options: {
30
- identifier: {
31
- key: string;
32
- };
33
- name: string;
34
- value: {
35
- identifier: {
36
- option: {
37
- key: string;
38
- };
39
- key: string;
40
- };
41
- label: string;
42
- };
43
- }[];
44
- };
14
+ protected parseVariant(variant: StoreProductVariant, product: StoreProduct): ProductVariant;
45
15
  protected createSynthAttribute(key: string, name: string, value: string): ProductAttribute;
46
16
  protected parseAttributes(_body: StoreProduct): Array<ProductAttribute>;
47
17
  }
@@ -2,9 +2,9 @@ import type { z } from 'zod';
2
2
  export declare const MedusaCapabilitiesSchema: z.ZodObject<{
3
3
  price: z.ZodOptional<z.ZodBoolean>;
4
4
  product: z.ZodOptional<z.ZodBoolean>;
5
+ order: z.ZodOptional<z.ZodBoolean>;
5
6
  cart: z.ZodOptional<z.ZodBoolean>;
6
7
  checkout: z.ZodOptional<z.ZodBoolean>;
7
- order: z.ZodOptional<z.ZodBoolean>;
8
8
  identity: z.ZodOptional<z.ZodBoolean>;
9
9
  inventory: z.ZodOptional<z.ZodBoolean>;
10
10
  category: z.ZodOptional<z.ZodBoolean>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- import 'dotenv/config';
@@ -1 +0,0 @@
1
- import 'dotenv/config';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- import 'dotenv/config';
@@ -1 +0,0 @@
1
- import 'dotenv/config';
@@ -1,3 +0,0 @@
1
- import 'dotenv/config';
2
- import { type MedusaConfiguration } from '../schema/configuration.schema.js';
3
- export declare function getMedusaTestConfiguration(): MedusaConfiguration;
@@ -1,163 +0,0 @@
1
- import { NoOpCache, createInitialRequestContext, unwrapValue } from "@reactionary/core";
2
- import { assert, beforeEach, describe, expect, it } from "vitest";
3
- import { MedusaAPI } from "../core/client.js";
4
- import { MedusaCartProvider } from "../providers/cart.provider.js";
5
- import { getMedusaTestConfiguration } from "./test-utils.js";
6
- const testData = {
7
- skuWithoutTiers: "4047443491480",
8
- skuWithTiers: "0819927012825"
9
- };
10
- describe("Medusa Cart Provider", () => {
11
- let provider;
12
- let reqCtx;
13
- beforeEach(() => {
14
- reqCtx = createInitialRequestContext();
15
- const client = new MedusaAPI(getMedusaTestConfiguration(), reqCtx);
16
- provider = new MedusaCartProvider(getMedusaTestConfiguration(), new NoOpCache(), reqCtx, client);
17
- });
18
- describe("anonymous sessions", () => {
19
- it("should get a NotFound for an unknown identifier", async () => {
20
- const cart = await provider.getById({
21
- cart: { key: "" }
22
- });
23
- if (cart.success) {
24
- assert.fail();
25
- }
26
- expect(cart.error.type).toBe("NotFound");
27
- });
28
- it("should be able to add an item to a cart", async () => {
29
- const cart = await provider.add({
30
- variant: {
31
- sku: testData.skuWithoutTiers
32
- },
33
- quantity: 1
34
- });
35
- if (!cart.success) {
36
- assert.fail();
37
- }
38
- expect(cart.value.identifier.key).toBeDefined();
39
- expect(cart.value.items.length).toBe(1);
40
- expect(cart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
41
- expect(cart.value.items[0].quantity).toBe(1);
42
- expect(cart.value.items[0].price.totalPrice.value).toBeGreaterThan(0);
43
- expect(cart.value.items[0].price.totalPrice.currency).toBe(reqCtx.languageContext.currencyCode);
44
- expect(cart.value.price.grandTotal.value).toBeGreaterThan(0);
45
- expect(cart.value.price.grandTotal.currency).toBe(reqCtx.languageContext.currencyCode);
46
- expect(cart.value.price.grandTotal.value).toBe(cart.value.items[0].price.totalPrice.value);
47
- });
48
- it("can add multiple different items to a cart", async () => {
49
- const cart = await provider.add({
50
- variant: {
51
- sku: testData.skuWithoutTiers
52
- },
53
- quantity: 1
54
- });
55
- if (!cart.success) {
56
- assert.fail();
57
- }
58
- const updatedCart = await provider.add({
59
- cart: cart.value.identifier,
60
- variant: {
61
- sku: testData.skuWithTiers
62
- },
63
- quantity: 2
64
- });
65
- if (!updatedCart.success) {
66
- assert.fail();
67
- }
68
- expect(updatedCart.value.items.length).toBe(2);
69
- expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
70
- expect(updatedCart.value.items[0].quantity).toBe(1);
71
- expect(updatedCart.value.items[1].variant.sku).toBe(testData.skuWithTiers);
72
- expect(updatedCart.value.items[1].quantity).toBe(2);
73
- });
74
- it("should be able to change quantity of an item in a cart", async () => {
75
- const cart = await provider.add({
76
- variant: {
77
- sku: testData.skuWithoutTiers
78
- },
79
- quantity: 1
80
- });
81
- if (!cart.success) {
82
- assert.fail();
83
- }
84
- const updatedCart = await provider.changeQuantity({
85
- cart: cart.value.identifier,
86
- item: cart.value.items[0].identifier,
87
- quantity: 3
88
- });
89
- if (!updatedCart.success) {
90
- assert.fail();
91
- }
92
- expect(updatedCart.value.items.length).toBe(1);
93
- expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
94
- expect(updatedCart.value.items[0].quantity).toBe(3);
95
- expect(updatedCart.value.items[0].price.totalPrice.value).toBe(cart.value.items[0].price.totalPrice.value * 3);
96
- expect(updatedCart.value.items[0].price.unitPrice.value).toBe(cart.value.items[0].price.unitPrice.value);
97
- });
98
- it("cannot set quantity below 1", async () => {
99
- const cart = unwrapValue(await provider.add({
100
- variant: {
101
- sku: testData.skuWithoutTiers
102
- },
103
- quantity: 1
104
- }));
105
- let updatedCart;
106
- try {
107
- updatedCart = unwrapValue(await provider.changeQuantity({
108
- cart: cart.identifier,
109
- item: cart.items[0].identifier,
110
- quantity: 0
111
- }));
112
- expect(updatedCart).toBeDefined();
113
- } catch (error) {
114
- expect(error).toBeDefined();
115
- return;
116
- }
117
- throw new Error("Should have thrown an error");
118
- });
119
- it("should be able to remove an item from a cart", async () => {
120
- const cart = await provider.add({
121
- variant: {
122
- sku: testData.skuWithoutTiers
123
- },
124
- quantity: 1
125
- });
126
- if (!cart.success) {
127
- assert.fail();
128
- }
129
- const updatedCart = await provider.remove({
130
- cart: cart.value.identifier,
131
- item: cart.value.items[0].identifier
132
- });
133
- if (!updatedCart.success) {
134
- assert.fail();
135
- }
136
- expect(updatedCart.value.items.length).toBe(0);
137
- });
138
- it("should be able to delete a cart", async () => {
139
- const cart = await provider.add({
140
- variant: {
141
- sku: testData.skuWithoutTiers
142
- },
143
- quantity: 1
144
- });
145
- if (!cart.success) {
146
- assert.fail();
147
- }
148
- expect(cart.value.items.length).toBe(1);
149
- expect(cart.value.identifier.key).toBeTruthy();
150
- const deletedCart = await provider.deleteCart({
151
- cart: cart.value.identifier
152
- });
153
- expect(deletedCart.success).toBe(true);
154
- const originalCart = await provider.getById({
155
- cart: cart.value.identifier
156
- });
157
- if (originalCart.success) {
158
- assert.fail();
159
- }
160
- expect(originalCart.error.type).toBe("NotFound");
161
- });
162
- });
163
- });