@labdigital/commercetools-mock 2.20.2 → 2.21.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.20.2",
3
+ "version": "2.21.1",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
package/src/helpers.ts CHANGED
@@ -77,3 +77,14 @@ export const mapHeaderType = (
77
77
  }
78
78
  return headersInit;
79
79
  };
80
+
81
+ export const generateRandomString = (length: number) => {
82
+ const characters =
83
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
84
+ let result = "";
85
+ for (let i = 0; i < length; i++) {
86
+ const randomIndex = Math.floor(Math.random() * characters.length);
87
+ result += characters[randomIndex];
88
+ }
89
+ return result;
90
+ };
@@ -164,7 +164,9 @@ export abstract class AbstractResourceRepository<
164
164
  });
165
165
 
166
166
  const data = result.results.map((r) =>
167
- this.postProcessResource(context, r as ResourceMap[T]),
167
+ this.postProcessResource(context, r as ResourceMap[T], {
168
+ expand: params.expand,
169
+ }),
168
170
  );
169
171
  return {
170
172
  ...result,
@@ -88,5 +88,19 @@ describe("Order repository", () => {
88
88
  { id: level1.id, typeId: "category", obj: level1 },
89
89
  { id: root.id, typeId: "category", obj: root },
90
90
  ]);
91
+
92
+ const queryResult = repository.query(
93
+ { projectKey: "dummy" },
94
+ {
95
+ where: [`id="${level3.id}"`],
96
+ expand: ["ancestors[*]"],
97
+ },
98
+ );
99
+ expect(queryResult.results[0].ancestors).toHaveLength(3);
100
+ expect(queryResult.results[0].ancestors).toEqual([
101
+ { id: level2.id, typeId: "category", obj: level2 },
102
+ { id: level1.id, typeId: "category", obj: level1 },
103
+ { id: root.id, typeId: "category", obj: root },
104
+ ]);
91
105
  });
92
106
  });
@@ -28,6 +28,9 @@ export class CategoryRepository extends AbstractResourceRepository<"category"> {
28
28
  key: draft.key,
29
29
  name: draft.name,
30
30
  slug: draft.slug,
31
+ description: draft.description,
32
+ metaDescription: draft.metaDescription,
33
+ metaKeywords: draft.metaKeywords,
31
34
  orderHint: draft.orderHint || "",
32
35
  externalId: draft.externalId || "",
33
36
  parent: draft.parent
@@ -6,13 +6,14 @@ import type {
6
6
  ResourceNotFoundError,
7
7
  } from "@commercetools/platform-sdk";
8
8
  import { CommercetoolsError } from "~src/exceptions";
9
- import { getBaseResourceProperties } from "~src/helpers";
9
+ import { generateRandomString, getBaseResourceProperties } from "~src/helpers";
10
10
  import { createPasswordResetToken, hashPassword } from "~src/lib/password";
11
11
  import { AbstractStorage } from "~src/storage/abstract";
12
12
  import {
13
13
  AbstractResourceRepository,
14
14
  type RepositoryContext,
15
15
  } from "../abstract";
16
+ import { createCustomFields } from "../helpers";
16
17
  import { CustomerUpdateHandler } from "./actions";
17
18
 
18
19
  export class CustomerRepository extends AbstractResourceRepository<"customer"> {
@@ -43,14 +44,44 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {
43
44
  });
44
45
  }
45
46
 
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
+
46
62
  const resource: Customer = {
47
63
  ...getBaseResourceProperties(),
64
+ key: draft.key,
48
65
  authenticationMode: draft.authenticationMode || "Password",
66
+ firstName: draft.firstName,
67
+ lastName: draft.lastName,
68
+ middleName: draft.middleName,
69
+ title: draft.title,
70
+ dateOfBirth: draft.dateOfBirth,
71
+ companyName: draft.companyName,
49
72
  email: draft.email.toLowerCase(),
50
73
  password: draft.password ? hashPassword(draft.password) : undefined,
51
74
  isEmailVerified: draft.isEmailVerified || false,
52
- addresses: [],
75
+ addresses: addresses,
53
76
  customerNumber: draft.customerNumber,
77
+ externalId: draft.externalId,
78
+ defaultBillingAddressId: defaultBillingAddressId,
79
+ defaultShippingAddressId: defaultShippingAddressId,
80
+ custom: createCustomFields(
81
+ draft.custom,
82
+ context.projectKey,
83
+ this._storage,
84
+ ),
54
85
  };
55
86
  return this.saveNew(context, resource);
56
87
  }