@labdigital/commercetools-mock 2.48.1 → 2.49.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
- "version": "2.48.1",
3
+ "version": "2.49.1",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
@@ -17,6 +17,7 @@ import type {
17
17
  CartChangeTaxRoundingModeAction,
18
18
  CartRemoveDiscountCodeAction,
19
19
  CartRemoveLineItemAction,
20
+ CartRemoveShippingMethodAction,
20
21
  CartSetBillingAddressAction,
21
22
  CartSetBillingAddressCustomTypeAction,
22
23
  CartSetCountryAction,
@@ -28,6 +29,7 @@ import type {
28
29
  CartSetLineItemShippingDetailsAction,
29
30
  CartSetLocaleAction,
30
31
  CartSetShippingAddressAction,
32
+ CartSetShippingAddressCustomFieldAction,
31
33
  CartSetShippingAddressCustomTypeAction,
32
34
  CartSetShippingMethodAction,
33
35
  CustomFields,
@@ -43,6 +45,7 @@ import type {
43
45
  TaxPortion,
44
46
  TaxedItemPrice,
45
47
  } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/cart";
48
+ import type { ShippingMethodResourceIdentifier } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/shipping-method";
46
49
  import { Decimal } from "decimal.js/decimal";
47
50
  import { v4 as uuidv4 } from "uuid";
48
51
  import { CommercetoolsError } from "~src/exceptions";
@@ -402,6 +405,7 @@ export class CartUpdateHandler
402
405
  if (!resource.custom) {
403
406
  throw new Error("Resource has no custom field");
404
407
  }
408
+
405
409
  resource.custom.fields[name] = value;
406
410
  }
407
411
 
@@ -751,4 +755,42 @@ export class CartUpdateHandler
751
755
  resource.shippingInfo = undefined;
752
756
  }
753
757
  }
758
+
759
+ setShippingAddressCustomField(
760
+ context: RepositoryContext,
761
+ resource: Writable<Cart>,
762
+ { name, value }: CartSetShippingAddressCustomFieldAction,
763
+ ) {
764
+ if (!resource.shippingAddress) {
765
+ throw new Error("Resource has no shipping address");
766
+ }
767
+ if (!resource.shippingAddress.custom) {
768
+ throw new Error("Resource has no custom field");
769
+ }
770
+ resource.shippingAddress.custom.fields[name] = value;
771
+ }
772
+
773
+ removeShippingMethod(
774
+ context: RepositoryContext,
775
+ resource: Writable<Cart>,
776
+ { shippingKey }: CartRemoveShippingMethodAction,
777
+ ) {
778
+ if (!resource.shippingInfo) {
779
+ return;
780
+ }
781
+ const shippingMethod =
782
+ this._storage.getByResourceIdentifier<"shipping-method">(
783
+ context.projectKey,
784
+ {
785
+ typeId: "shipping-method",
786
+ key: shippingKey,
787
+ } as ShippingMethodResourceIdentifier,
788
+ );
789
+
790
+ if (resource.shippingInfo?.shippingMethod?.id !== shippingMethod.id) {
791
+ throw new Error("Shipping method with key not found");
792
+ }
793
+
794
+ resource.shippingInfo = undefined;
795
+ }
754
796
  }
@@ -1101,6 +1101,37 @@ describe("Cart Update Actions", () => {
1101
1101
  );
1102
1102
  });
1103
1103
 
1104
+ test("correctly removes a shipping method", async () => {
1105
+ assert(cart, "cart not created");
1106
+
1107
+ const shippingMethod: ShippingMethodResourceIdentifier = {
1108
+ typeId: "shipping-method",
1109
+ id: standardShippingMethod.id,
1110
+ };
1111
+
1112
+ const response = await supertest(ctMock.app)
1113
+ .post(`/dummy/carts/${cart.id}`)
1114
+ .send({
1115
+ version: 2,
1116
+ actions: [{ action: "setShippingMethod", shippingMethod }],
1117
+ });
1118
+ expect(response.status).toBe(200);
1119
+
1120
+ const removeResponse = await supertest(ctMock.app)
1121
+ .post(`/dummy/carts/${cart.id}`)
1122
+ .send({
1123
+ version: 3,
1124
+ actions: [
1125
+ {
1126
+ action: "removeShippingMethod",
1127
+ shippingKey: standardShippingMethod.key,
1128
+ },
1129
+ ],
1130
+ });
1131
+ expect(removeResponse.status).toBe(200);
1132
+ expect(removeResponse.body.shippingInfo).toBeUndefined();
1133
+ });
1134
+
1104
1135
  test("correctly sets shippingInfo rates + tax when includedInPrice: true", async () => {
1105
1136
  assert(cart, "cart not created");
1106
1137
  assert(standardShippingMethod, "shipping method not created");