@labdigital/commercetools-mock 2.50.1 → 2.51.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/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/repositories/cart/index.test.ts +60 -0
- package/src/repositories/cart/index.ts +29 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.51.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"build": "tsdown",
|
|
61
61
|
"build:server": "esbuild src/server.ts --bundle --outfile=dist/server.js --platform=node",
|
|
62
62
|
"check": "biome check && tsc",
|
|
63
|
-
"format": "biome
|
|
63
|
+
"format": "biome check --fix",
|
|
64
64
|
"lint": "biome check",
|
|
65
65
|
"publish:ci": "pnpm build && pnpm changeset publish",
|
|
66
66
|
"publish:version": "pnpm changeset version && pnpm format",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CartDraft, LineItem } from "@commercetools/platform-sdk";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
3
|
import type { Config } from "~src/config";
|
|
4
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
4
5
|
import { InMemoryStorage } from "~src/storage";
|
|
5
6
|
import { CartRepository } from "./index";
|
|
6
7
|
|
|
@@ -9,6 +10,15 @@ describe("Cart repository", () => {
|
|
|
9
10
|
const config: Config = { storage, strict: false };
|
|
10
11
|
const repository = new CartRepository(config);
|
|
11
12
|
|
|
13
|
+
storage.add("dummy", "type", {
|
|
14
|
+
...getBaseResourceProperties(),
|
|
15
|
+
id: "1234567890",
|
|
16
|
+
key: "custom-type-key",
|
|
17
|
+
name: { "nl-NL": "custom-type-name" },
|
|
18
|
+
resourceTypeIds: [],
|
|
19
|
+
fieldDefinitions: [],
|
|
20
|
+
});
|
|
21
|
+
|
|
12
22
|
test("create cart in store", async () => {
|
|
13
23
|
storage.add("dummy", "product", {
|
|
14
24
|
createdAt: "",
|
|
@@ -108,6 +118,15 @@ describe("Cart repository", () => {
|
|
|
108
118
|
},
|
|
109
119
|
],
|
|
110
120
|
},
|
|
121
|
+
custom: {
|
|
122
|
+
type: {
|
|
123
|
+
typeId: "type",
|
|
124
|
+
id: "1234567890",
|
|
125
|
+
},
|
|
126
|
+
fields: {
|
|
127
|
+
description: "example description",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
111
130
|
} as unknown as LineItem,
|
|
112
131
|
],
|
|
113
132
|
origin: "Customer",
|
|
@@ -149,5 +168,46 @@ describe("Cart repository", () => {
|
|
|
149
168
|
expect(result.taxMode).toEqual(cart.taxMode);
|
|
150
169
|
expect(result.taxRoundingMode).toEqual(cart.taxRoundingMode);
|
|
151
170
|
expect(result.store?.key).toEqual(ctx.storeKey);
|
|
171
|
+
expect(result.lineItems[0].custom?.fields.description as string).toEqual(
|
|
172
|
+
cart.lineItems![0].custom?.fields?.description,
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("create cart with business unit", async () => {
|
|
177
|
+
storage.add("dummy", "business-unit", {
|
|
178
|
+
...getBaseResourceProperties(),
|
|
179
|
+
unitType: "Company",
|
|
180
|
+
key: "business-unit-key",
|
|
181
|
+
status: "Active",
|
|
182
|
+
storeMode: "Explicit",
|
|
183
|
+
name: "Test",
|
|
184
|
+
addresses: [],
|
|
185
|
+
associateMode: "Explicit",
|
|
186
|
+
associates: [],
|
|
187
|
+
topLevelUnit: {
|
|
188
|
+
typeId: "business-unit",
|
|
189
|
+
key: "business-unit-key",
|
|
190
|
+
},
|
|
191
|
+
approvalRuleMode: "Explicit",
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const cart: CartDraft = {
|
|
195
|
+
country: "NL",
|
|
196
|
+
currency: "EUR",
|
|
197
|
+
businessUnit: {
|
|
198
|
+
typeId: "business-unit",
|
|
199
|
+
key: "business-unit-key",
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const ctx = { projectKey: "dummy", storeKey: "dummyStore" };
|
|
204
|
+
|
|
205
|
+
const result = repository.create(ctx, cart);
|
|
206
|
+
expect(result.id).toBeDefined();
|
|
207
|
+
|
|
208
|
+
expect(result.businessUnit).toEqual({
|
|
209
|
+
key: "business-unit-key",
|
|
210
|
+
typeId: "business-unit",
|
|
211
|
+
});
|
|
152
212
|
});
|
|
153
213
|
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BusinessUnit,
|
|
3
|
+
InvalidOperationError,
|
|
4
|
+
} from "@commercetools/platform-sdk";
|
|
2
5
|
import type {
|
|
3
6
|
Cart,
|
|
4
7
|
CartDraft,
|
|
@@ -43,6 +46,19 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
|
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
let storedBusinessUnit: BusinessUnit | undefined = undefined;
|
|
50
|
+
if (draft.businessUnit?.id || draft.businessUnit?.key) {
|
|
51
|
+
storedBusinessUnit =
|
|
52
|
+
this._storage.getByResourceIdentifier<"business-unit">(
|
|
53
|
+
context.projectKey,
|
|
54
|
+
{
|
|
55
|
+
typeId: "business-unit",
|
|
56
|
+
id: draft.businessUnit.id,
|
|
57
|
+
key: draft.businessUnit.key,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
const lineItems =
|
|
47
63
|
draft.lineItems?.map((draftLineItem) =>
|
|
48
64
|
this.draftLineItemtoLineItem(
|
|
@@ -56,6 +72,13 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
|
|
|
56
72
|
const resource: Writable<Cart> = {
|
|
57
73
|
...getBaseResourceProperties(),
|
|
58
74
|
anonymousId: draft.anonymousId,
|
|
75
|
+
businessUnit:
|
|
76
|
+
storedBusinessUnit && draft.businessUnit
|
|
77
|
+
? {
|
|
78
|
+
typeId: draft.businessUnit.typeId,
|
|
79
|
+
key: storedBusinessUnit.key,
|
|
80
|
+
}
|
|
81
|
+
: undefined,
|
|
59
82
|
billingAddress: draft.billingAddress
|
|
60
83
|
? createAddress(draft.billingAddress, context.projectKey, this._storage)
|
|
61
84
|
: undefined,
|
|
@@ -202,6 +225,11 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
|
|
|
202
225
|
lineItemMode: "Standard",
|
|
203
226
|
priceMode: "Platform",
|
|
204
227
|
state: [],
|
|
228
|
+
custom: createCustomFields(
|
|
229
|
+
draftLineItem.custom,
|
|
230
|
+
projectKey,
|
|
231
|
+
this._storage,
|
|
232
|
+
),
|
|
205
233
|
};
|
|
206
234
|
};
|
|
207
235
|
}
|