@labdigital/commercetools-mock 2.61.0 → 2.61.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,18 +1,18 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
- "version": "2.61.0",
3
+ "version": "2.61.2",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
7
7
  "exports": {
8
- ".": "./dist/index.js"
8
+ ".": "./dist/index.mjs"
9
9
  },
10
10
  "imports": {
11
11
  "#src/*": "./src/*",
12
12
  "#vendor/*": "./vendor/*"
13
13
  },
14
- "main": "dist/index.js",
15
- "module": "dist/index.js",
14
+ "main": "dist/index.mjs",
15
+ "module": "dist/index.mjs",
16
16
  "typings": "dist/index.d.ts",
17
17
  "files": [
18
18
  "dist",
@@ -211,15 +211,12 @@ class BusinessUnitUpdateHandler
211
211
  }
212
212
 
213
213
  const newAddress = createAddress(
214
- address,
214
+ { ...address, id: addressId },
215
215
  context.projectKey,
216
216
  this._storage,
217
217
  );
218
218
  if (newAddress) {
219
- resource.addresses[existingAddressIndex] = {
220
- ...newAddress,
221
- id: addressId,
222
- };
219
+ resource.addresses[existingAddressIndex] = newAddress;
223
220
  }
224
221
  }
225
222
 
@@ -118,16 +118,13 @@ export class CustomerUpdateHandler
118
118
  );
119
119
 
120
120
  const newAddress = createAddress(
121
- address,
121
+ { ...address, id: current.id },
122
122
  context.projectKey,
123
123
  this._storage,
124
124
  );
125
125
 
126
126
  if (newAddress) {
127
- resource.addresses[oldAddressIndex] = {
128
- id: addressId,
129
- ...newAddress,
130
- };
127
+ resource.addresses[oldAddressIndex] = newAddress;
131
128
  }
132
129
  }
133
130
 
@@ -0,0 +1,25 @@
1
+ import type { BaseAddress } from "@commercetools/platform-sdk";
2
+ import { describe, expect, test } from "vitest";
3
+ import { InMemoryStorage } from "#src/storage/index.ts";
4
+ import { createAddress } from "./helpers.ts";
5
+
6
+ describe("Helpers", () => {
7
+ const storage = new InMemoryStorage();
8
+ const projectKey = "test-project";
9
+
10
+ describe("createAddress", () => {
11
+ test("should generate random id when id is not provided", () => {
12
+ const baseAddress: BaseAddress = {
13
+ country: "US",
14
+ streetName: "Test Street",
15
+ city: "Test City",
16
+ };
17
+
18
+ const result = createAddress(baseAddress, projectKey, storage);
19
+ expect(result).toBeDefined();
20
+ expect(result?.id).toBeDefined();
21
+ expect(typeof result?.id).toBe("string");
22
+ expect(result?.id).toMatch(/^[a-z0-9]{8}$/);
23
+ });
24
+ });
25
+ });
@@ -48,8 +48,13 @@ export const createAddress = (
48
48
  throw new Error("Country is required");
49
49
  }
50
50
 
51
+ // Generate a random 8-character alphanumeric string
52
+ // which is what addresses use instead of uuid
53
+ const generateRandomId = (): string =>
54
+ Math.random().toString(36).substring(2, 10).padEnd(8, "0");
51
55
  return {
52
56
  ...base,
57
+ id: base.id ?? generateRandomId(),
53
58
  };
54
59
  };
55
60
 
@@ -644,7 +644,10 @@ describe("Cart Update Actions", () => {
644
644
  });
645
645
  expect(response.status).toBe(200);
646
646
  expect(response.body.version).toBe(2);
647
- expect(response.body.billingAddress).toEqual(address);
647
+ expect(response.body.billingAddress).toEqual({
648
+ ...address,
649
+ id: expect.any(String),
650
+ });
648
651
  });
649
652
 
650
653
  test("setCountry", async () => {
@@ -1187,6 +1190,7 @@ describe("Cart Update Actions", () => {
1187
1190
  expect(response.body.version).toBe(3);
1188
1191
  expect(response.body.billingAddress).toEqual({
1189
1192
  ...address,
1193
+ id: expect.any(String),
1190
1194
  custom: {
1191
1195
  type: { typeId: "type", id: type.id },
1192
1196
  fields: { foo: "bar" },