@labdigital/commercetools-mock 2.27.0 → 2.28.0

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.27.0",
3
+ "version": "2.28.0",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@changesets/changelog-github": "^0.5.0",
36
36
  "@changesets/cli": "^2.27.1",
37
- "@commercetools/platform-sdk": "7.3.0",
37
+ "@commercetools/platform-sdk": "7.11.0",
38
38
  "@stylistic/eslint-plugin": "^1.6.2",
39
39
  "@types/basic-auth": "^1.1.8",
40
40
  "@types/body-parser": "^1.19.5",
@@ -106,6 +106,7 @@ describe("OAuth2Server", () => {
106
106
  addresses: [],
107
107
  authenticationMode: "password",
108
108
  isEmailVerified: true,
109
+ stores: [],
109
110
  });
110
111
 
111
112
  const response = await supertest(app)
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BusinessUnitChangeApprovalRuleModeAction,
2
3
  BusinessUnitChangeAssociateModeAction,
3
4
  BusinessUnitChangeStatusAction,
4
5
  BusinessUnitUpdateAction,
@@ -19,8 +20,8 @@ import {
19
20
  type Company,
20
21
  type Division,
21
22
  } from "@commercetools/platform-sdk";
22
- import { getBaseResourceProperties } from "../helpers";
23
- import { AbstractStorage } from "../storage/abstract";
23
+ import { AbstractStorage } from "~src/storage";
24
+ import { generateRandomString, getBaseResourceProperties } from "../helpers";
24
25
  import { Writable } from "../types";
25
26
  import {
26
27
  AbstractResourceRepository,
@@ -43,6 +44,28 @@ export class BusinessUnitRepository extends AbstractResourceRepository<"business
43
44
  }
44
45
 
45
46
  create(context: RepositoryContext, draft: BusinessUnitDraft): BusinessUnit {
47
+ const addresses =
48
+ draft.addresses?.map((address) => ({
49
+ ...address,
50
+ id: generateRandomString(5),
51
+ })) ?? [];
52
+
53
+ const defaultBillingAddressId =
54
+ addresses.length > 0 && draft.defaultBillingAddress !== undefined
55
+ ? addresses[draft.defaultBillingAddress].id
56
+ : undefined;
57
+ const defaultShippingAddressId =
58
+ addresses.length > 0 && draft.defaultShippingAddress !== undefined
59
+ ? addresses[draft.defaultShippingAddress].id
60
+ : undefined;
61
+
62
+ const shippingAddressIds = draft.shippingAddresses?.map(
63
+ (i) => addresses[i].id,
64
+ );
65
+ const billingAddressIds = draft.billingAddresses?.map(
66
+ (i) => addresses[i].id,
67
+ );
68
+
46
69
  const resource = {
47
70
  ...getBaseResourceProperties(),
48
71
  key: draft.key,
@@ -53,18 +76,19 @@ export class BusinessUnitRepository extends AbstractResourceRepository<"business
53
76
  storeMode: draft.storeMode,
54
77
  name: draft.name,
55
78
  contactEmail: draft.contactEmail,
56
- addresses: draft.addresses?.map((a) =>
57
- createAddress(a, context.projectKey, this._storage),
58
- ),
79
+ addresses: addresses,
59
80
  custom: createCustomFields(
60
81
  draft.custom,
61
82
  context.projectKey,
62
83
  this._storage,
63
84
  ),
64
- shippingAddressIds: draft.shippingAddresses,
65
- defaultShippingAddressId: draft.defaultShippingAddress,
66
- billingAddressIds: draft.billingAddresses,
85
+ shippingAddressIds: shippingAddressIds,
86
+ billingAddressIds: billingAddressIds,
87
+ defaultShippingAddressId: defaultShippingAddressId,
88
+ defaultBillingAddressId: defaultBillingAddressId,
67
89
  associateMode: draft.associateMode,
90
+ approvalRuleMode: draft.approvalRuleMode,
91
+
68
92
  associates: draft.associates?.map((a) =>
69
93
  createAssociate(a, context.projectKey, this._storage),
70
94
  ),
@@ -170,6 +194,14 @@ class BusinessUnitUpdateHandler
170
194
  }
171
195
  }
172
196
 
197
+ changeApprovalRuleMode(
198
+ context: RepositoryContext,
199
+ resource: Writable<BusinessUnit>,
200
+ { approvalRuleMode }: BusinessUnitChangeApprovalRuleModeAction,
201
+ ) {
202
+ resource.approvalRuleMode = approvalRuleMode;
203
+ }
204
+
173
205
  changeAssociateMode(
174
206
  context: RepositoryContext,
175
207
  resource: Writable<BusinessUnit>,
@@ -30,6 +30,7 @@ import {
30
30
  type ProductPagedQueryResponse,
31
31
  type ProductVariant,
32
32
  } from "@commercetools/platform-sdk";
33
+ import { DirectDiscount } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/cart";
33
34
  import { v4 as uuidv4 } from "uuid";
34
35
  import { CommercetoolsError } from "~src/exceptions";
35
36
  import type { Writable } from "~src/types";
@@ -419,10 +420,13 @@ export class CartUpdateHandler
419
420
  { discounts }: CartSetDirectDiscountsAction,
420
421
  ) {
421
422
  // Doesn't apply any discounts logic, just sets the directDiscounts field
422
- resource.directDiscounts = discounts.map((discount) => ({
423
- ...discount,
424
- id: uuidv4(),
425
- }));
423
+ resource.directDiscounts = discounts.map(
424
+ (discount) =>
425
+ ({
426
+ ...discount,
427
+ id: uuidv4(),
428
+ }) as DirectDiscount,
429
+ );
426
430
  }
427
431
 
428
432
  setLineItemShippingDetails(
@@ -91,6 +91,7 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {
91
91
  context.projectKey,
92
92
  this._storage,
93
93
  ),
94
+ stores: [],
94
95
  };
95
96
  return this.saveNew(context, resource);
96
97
  }
@@ -27,7 +27,6 @@ import {
27
27
  type StoreReference,
28
28
  type StoreResourceIdentifier,
29
29
  type Type,
30
- type TypedMoney,
31
30
  type _Money,
32
31
  } from "@commercetools/platform-sdk";
33
32
  import type { Request } from "express";
@@ -133,7 +132,7 @@ export const createCentPrecisionMoney = (value: _Money): CentPrecisionMoney => {
133
132
  };
134
133
  };
135
134
 
136
- export const createTypedMoney = (value: _Money): TypedMoney => {
135
+ export const createTypedMoney = (value: _Money): CentPrecisionMoney => {
137
136
  const result = createCentPrecisionMoney(value);
138
137
  return result;
139
138
  };
@@ -1,3 +1,4 @@
1
+ import { ProductTailoringRepository } from "~src/repositories/product-tailoring";
1
2
  import { AbstractStorage } from "../storage";
2
3
  import { AssociateRoleRepository } from "./associate-role";
3
4
  import { AttributeGroupRepository } from "./attribute-group";
@@ -66,6 +67,7 @@ export const createRepositories = (storage: AbstractStorage) => ({
66
67
  "product-discount": new ProductDiscountRepository(storage),
67
68
  "product-projection": new ProductProjectionRepository(storage),
68
69
  "product-selection": new ProductSelectionRepository(storage),
70
+ "product-tailoring": new ProductTailoringRepository(storage),
69
71
  "project": new ProjectRepository(storage),
70
72
  "review": new ReviewRepository(storage),
71
73
  "quote": new QuoteRepository(storage),
@@ -0,0 +1,34 @@
1
+ import type {
2
+ ProductTailoring,
3
+ ProductTailoringUpdateAction,
4
+ } from "@commercetools/platform-sdk";
5
+ import { AbstractStorage } from "~src/storage";
6
+ import {
7
+ AbstractResourceRepository,
8
+ AbstractUpdateHandler,
9
+ RepositoryContext,
10
+ UpdateHandlerInterface,
11
+ } from "./abstract";
12
+
13
+ export class ProductTailoringRepository extends AbstractResourceRepository<"product-tailoring"> {
14
+ constructor(storage: AbstractStorage) {
15
+ super("product-tailoring", storage);
16
+ this.actions = new ProductTailoringUpdateHandler(this._storage);
17
+ }
18
+
19
+ create(context: RepositoryContext, draft: any): ProductTailoring {
20
+ throw new Error("Create method for product-tailoring not implemented.");
21
+ }
22
+ }
23
+
24
+ class ProductTailoringUpdateHandler
25
+ extends AbstractUpdateHandler
26
+ implements
27
+ Partial<
28
+ UpdateHandlerInterface<ProductTailoring, ProductTailoringUpdateAction>
29
+ >
30
+ {
31
+ setSlug() {
32
+ throw new Error("SetSlug method for product-tailoring not implemented.");
33
+ }
34
+ }
@@ -4,6 +4,7 @@ import {
4
4
  type ShippingMethod,
5
5
  type ShippingMethodAddShippingRateAction,
6
6
  type ShippingMethodAddZoneAction,
7
+ type ShippingMethodChangeActiveAction,
7
8
  type ShippingMethodChangeIsDefaultAction,
8
9
  type ShippingMethodChangeNameAction,
9
10
  type ShippingMethodRemoveZoneAction,
@@ -18,7 +19,7 @@ import {
18
19
  type ZoneReference,
19
20
  } from "@commercetools/platform-sdk";
20
21
  import deepEqual from "deep-equal";
21
- import type { Writable } from "../../types";
22
+ import type { Writable } from "~src/types";
22
23
  import {
23
24
  AbstractUpdateHandler,
24
25
  RepositoryContext,
@@ -83,6 +84,14 @@ export class ShippingMethodUpdateHandler
83
84
  });
84
85
  }
85
86
 
87
+ changeActive(
88
+ _context: RepositoryContext,
89
+ resource: Writable<ShippingMethod>,
90
+ { active }: ShippingMethodChangeActiveAction,
91
+ ) {
92
+ resource.active = active;
93
+ }
94
+
86
95
  changeIsDefault(
87
96
  _context: RepositoryContext,
88
97
  resource: Writable<ShippingMethod>,
@@ -35,6 +35,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository<"shippi
35
35
  const resource: ShippingMethod = {
36
36
  ...getBaseResourceProperties(),
37
37
  ...draft,
38
+ active: draft.active ?? true,
38
39
  taxCategory: getReferenceFromResourceIdentifier(
39
40
  draft.taxCategory,
40
41
  context.projectKey,
@@ -20,6 +20,7 @@ describe("Customer Update Actions", () => {
20
20
  isEmailVerified: true,
21
21
  authenticationMode: "Password", //default in Commercetools
22
22
  version: 1,
23
+ stores: [],
23
24
  };
24
25
  ctMock.project("dummy").add("customer", customer);
25
26
  });
@@ -467,6 +468,7 @@ describe("Customer Password Reset", () => {
467
468
  isEmailVerified: true,
468
469
  authenticationMode: "password",
469
470
  custom: { type: { typeId: "type", id: "" }, fields: {} },
471
+ stores: [],
470
472
  });
471
473
  });
472
474
 
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ Customer,
2
3
  CustomerChangePassword,
3
4
  CustomerToken,
4
5
  MyCustomerDraft,
@@ -37,6 +38,7 @@ describe("Me", () => {
37
38
  id: expect.anything(),
38
39
  createdAt: expect.anything(),
39
40
  lastModifiedAt: expect.anything(),
41
+ stores: [],
40
42
  },
41
43
  });
42
44
  });
@@ -73,6 +75,7 @@ describe("/me", () => {
73
75
  isEmailVerified: true,
74
76
  authenticationMode: "password",
75
77
  custom: { type: { typeId: "type", id: "" }, fields: {} },
78
+ stores: [],
76
79
  });
77
80
  });
78
81
 
@@ -96,6 +99,7 @@ describe("/me", () => {
96
99
  typeId: "type",
97
100
  },
98
101
  },
102
+ stores: [],
99
103
  });
100
104
  });
101
105
 
@@ -119,6 +123,7 @@ describe("/me", () => {
119
123
  typeId: "type",
120
124
  },
121
125
  },
126
+ stores: [],
122
127
  });
123
128
 
124
129
  const newResponse = await supertest(ctMock.app).get("/dummy/me");
@@ -126,7 +131,7 @@ describe("/me", () => {
126
131
  });
127
132
 
128
133
  test("Change my password", async () => {
129
- const customer = {
134
+ const customer: Customer = {
130
135
  ...getBaseResourceProperties(),
131
136
  id: "customer-uuid",
132
137
  email: "user@example.com",
@@ -135,6 +140,7 @@ describe("/me", () => {
135
140
  isEmailVerified: true,
136
141
  authenticationMode: "Password", //default in Commercetools
137
142
  version: 1,
143
+ stores: [],
138
144
  };
139
145
  ctMock.project("dummy").add("customer", customer);
140
146
 
@@ -176,7 +182,7 @@ describe("/me", () => {
176
182
  });
177
183
 
178
184
  test("reset password flow", async () => {
179
- const customer = {
185
+ const customer: Customer = {
180
186
  ...getBaseResourceProperties(),
181
187
  id: "customer-uuid",
182
188
  email: "user@example.com",
@@ -185,6 +191,7 @@ describe("/me", () => {
185
191
  isEmailVerified: true,
186
192
  authenticationMode: "Password", //default in Commercetools
187
193
  version: 1,
194
+ stores: [],
188
195
  };
189
196
  ctMock.project("dummy").add("customer", customer);
190
197
 
@@ -225,7 +232,7 @@ describe("/me", () => {
225
232
  });
226
233
 
227
234
  test("verify email flow", async () => {
228
- const customer = {
235
+ const customer: Customer = {
229
236
  ...getBaseResourceProperties(),
230
237
  id: "customer-uuid",
231
238
  email: "user@example.com",
@@ -234,6 +241,7 @@ describe("/me", () => {
234
241
  isEmailVerified: false,
235
242
  authenticationMode: "Password", //default in Commercetools
236
243
  version: 1,
244
+ stores: [],
237
245
  };
238
246
  ctMock.project("dummy").add("customer", customer);
239
247
 
@@ -74,6 +74,7 @@ describe("Shipping method", () => {
74
74
  },
75
75
  version: 1,
76
76
  zoneRates: [],
77
+ active: true,
77
78
  });
78
79
  });
79
80
 
@@ -22,6 +22,7 @@ import {
22
22
  type Product,
23
23
  type ProductDiscount,
24
24
  type ProductProjection,
25
+ type ProductTailoring,
25
26
  type ProductType,
26
27
  type Project,
27
28
  type Quote,
@@ -189,6 +190,7 @@ export class InMemoryStorage extends AbstractStorage {
189
190
  "product-selection": new Map<string, any>(),
190
191
  "product-type": new Map<string, ProductType>(),
191
192
  "product-projection": new Map<string, ProductProjection>(),
193
+ "product-tailoring": new Map<string, ProductTailoring>(),
192
194
  "review": new Map<string, any>(),
193
195
  "shipping-method": new Map<string, ShippingMethod>(),
194
196
  "staged-quote": new Map<string, StagedQuote>(),
package/src/types.ts CHANGED
@@ -45,6 +45,7 @@ export type ResourceMap = {
45
45
  "product-price": ctp.StandalonePrice;
46
46
  "product-projection": ctp.ProductProjection;
47
47
  "product-selection": ctp.ProductSelection;
48
+ "product-tailoring": ctp.ProductTailoring;
48
49
  "product-type": ctp.ProductType;
49
50
  "product": ctp.Product;
50
51
  "quote-request": ctp.QuoteRequest;
@@ -85,6 +86,7 @@ export type PagedQueryResponseMap = {
85
86
  "product-price": ctp.StandalonePricePagedQueryResponse;
86
87
  "product-projection": ctp.ProductProjectionPagedQueryResponse;
87
88
  "product-selection": ctp.ProductSelectionPagedQueryResponse;
89
+ "product-tailoring": ctp.ProductTailoringPagedQueryResponse;
88
90
  "product-type": ctp.ProductTypePagedQueryResponse;
89
91
  "product": ctp.ProductPagedQueryResponse;
90
92
  "quote-request": ctp.QuoteRequestPagedQueryResponse;