@labdigital/commercetools-mock 2.50.1 → 2.52.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.
Files changed (41) hide show
  1. package/dist/index.d.ts +34 -23
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +121 -8
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/lib/product-review-statistics.test.ts +349 -0
  7. package/src/lib/review-statistics.ts +58 -0
  8. package/src/product-projection-search.ts +17 -2
  9. package/src/repositories/as-associate.test.ts +126 -0
  10. package/src/repositories/attribute-group.test.ts +221 -0
  11. package/src/repositories/business-unit.test.ts +282 -0
  12. package/src/repositories/business-unit.ts +5 -1
  13. package/src/repositories/cart/index.test.ts +60 -0
  14. package/src/repositories/cart/index.ts +29 -1
  15. package/src/repositories/channel.test.ts +374 -0
  16. package/src/repositories/customer-group.test.ts +262 -0
  17. package/src/repositories/extension.test.ts +306 -0
  18. package/src/repositories/index.test.ts +17 -0
  19. package/src/repositories/product/index.ts +22 -1
  20. package/src/repositories/product-projection.ts +8 -2
  21. package/src/repositories/review.test.ts +636 -0
  22. package/src/repositories/review.ts +145 -4
  23. package/src/repositories/subscription.test.ts +207 -0
  24. package/src/repositories/zone.test.ts +278 -0
  25. package/src/services/as-associate-cart.test.ts +58 -0
  26. package/src/services/as-associate.test.ts +34 -0
  27. package/src/services/attribute-group.test.ts +114 -0
  28. package/src/services/channel.test.ts +90 -0
  29. package/src/services/customer-group.test.ts +85 -0
  30. package/src/services/discount-code.test.ts +120 -0
  31. package/src/services/extension.test.ts +130 -0
  32. package/src/services/my-business-unit.test.ts +113 -0
  33. package/src/services/my-business-unit.ts +6 -0
  34. package/src/services/my-customer.test.ts +24 -0
  35. package/src/services/order.test.ts +18 -0
  36. package/src/services/product-discount.test.ts +146 -0
  37. package/src/services/project.test.ts +17 -0
  38. package/src/services/reviews.test.ts +230 -0
  39. package/src/services/subscription.test.ts +151 -0
  40. package/src/services/type.test.ts +127 -0
  41. package/src/services/zone.test.ts +117 -0
@@ -0,0 +1,221 @@
1
+ import type {
2
+ AttributeGroupChangeNameAction,
3
+ AttributeGroupDraft,
4
+ AttributeGroupSetAttributesAction,
5
+ AttributeGroupSetDescriptionAction,
6
+ AttributeGroupSetKeyAction,
7
+ } from "@commercetools/platform-sdk";
8
+ import { describe, expect, test } from "vitest";
9
+ import type { Config } from "~src/config";
10
+ import { InMemoryStorage } from "~src/storage";
11
+ import { AttributeGroupRepository } from "./attribute-group";
12
+
13
+ describe("AttributeGroup Repository", () => {
14
+ const storage = new InMemoryStorage();
15
+ const config: Config = { storage, strict: false };
16
+ const repository = new AttributeGroupRepository(config);
17
+
18
+ test("create attribute group", () => {
19
+ const draft: AttributeGroupDraft = {
20
+ name: { "en-US": "Size Attributes", "de-DE": "Größenattribute" },
21
+ description: { "en-US": "Attributes related to product size" },
22
+ key: "size-attributes",
23
+ attributes: [
24
+ {
25
+ key: "size",
26
+ },
27
+ {
28
+ key: "weight",
29
+ },
30
+ ],
31
+ };
32
+
33
+ const ctx = { projectKey: "dummy" };
34
+ const result = repository.create(ctx, draft);
35
+
36
+ expect(result.id).toBeDefined();
37
+ expect(result.version).toBe(1);
38
+ expect(result.name).toEqual(draft.name);
39
+ expect(result.description).toEqual(draft.description);
40
+ expect(result.key).toBe(draft.key);
41
+ expect(result.attributes).toEqual(draft.attributes);
42
+
43
+ // Test that the attribute group is stored
44
+ const items = repository.query(ctx);
45
+ expect(items.count).toBe(1);
46
+ expect(items.results[0].id).toBe(result.id);
47
+ });
48
+
49
+ test("create attribute group with minimal data", () => {
50
+ const draft: AttributeGroupDraft = {
51
+ name: { "en-US": "Minimal Attributes" },
52
+ attributes: [],
53
+ };
54
+
55
+ const ctx = { projectKey: "dummy" };
56
+ const result = repository.create(ctx, draft);
57
+
58
+ expect(result.id).toBeDefined();
59
+ expect(result.name).toEqual(draft.name);
60
+ expect(result.description).toBeUndefined();
61
+ expect(result.key).toBeUndefined();
62
+ expect(result.attributes).toEqual([]);
63
+ });
64
+
65
+ test("update attribute group - changeName", () => {
66
+ const draft: AttributeGroupDraft = {
67
+ name: { "en-US": "Original Name" },
68
+ key: "test-attributes",
69
+ attributes: [],
70
+ };
71
+
72
+ const ctx = { projectKey: "dummy" };
73
+ const attributeGroup = repository.create(ctx, draft);
74
+
75
+ const result = repository.processUpdateActions(
76
+ ctx,
77
+ attributeGroup,
78
+ attributeGroup.version,
79
+ [
80
+ {
81
+ action: "changeName",
82
+ name: { "en-US": "Updated Name", "de-DE": "Aktualisierter Name" },
83
+ } as AttributeGroupChangeNameAction,
84
+ ],
85
+ );
86
+
87
+ expect(result.name).toEqual({
88
+ "en-US": "Updated Name",
89
+ "de-DE": "Aktualisierter Name",
90
+ });
91
+ expect(result.version).toBe(attributeGroup.version + 1);
92
+ });
93
+
94
+ test("update attribute group - setDescription", () => {
95
+ const draft: AttributeGroupDraft = {
96
+ name: { "en-US": "Test Attributes" },
97
+ key: "test-attributes-2",
98
+ attributes: [],
99
+ };
100
+
101
+ const ctx = { projectKey: "dummy" };
102
+ const attributeGroup = repository.create(ctx, draft);
103
+
104
+ const result = repository.processUpdateActions(
105
+ ctx,
106
+ attributeGroup,
107
+ attributeGroup.version,
108
+ [
109
+ {
110
+ action: "setDescription",
111
+ description: {
112
+ "en-US": "New description",
113
+ "de-DE": "Neue Beschreibung",
114
+ },
115
+ } as AttributeGroupSetDescriptionAction,
116
+ ],
117
+ );
118
+
119
+ expect(result.description).toEqual({
120
+ "en-US": "New description",
121
+ "de-DE": "Neue Beschreibung",
122
+ });
123
+ expect(result.version).toBe(attributeGroup.version + 1);
124
+ });
125
+
126
+ test("update attribute group - setKey", () => {
127
+ const draft: AttributeGroupDraft = {
128
+ name: { "en-US": "Key Test Attributes" },
129
+ key: "original-key",
130
+ attributes: [],
131
+ };
132
+
133
+ const ctx = { projectKey: "dummy" };
134
+ const attributeGroup = repository.create(ctx, draft);
135
+
136
+ const result = repository.processUpdateActions(
137
+ ctx,
138
+ attributeGroup,
139
+ attributeGroup.version,
140
+ [
141
+ {
142
+ action: "setKey",
143
+ key: "updated-key",
144
+ } as AttributeGroupSetKeyAction,
145
+ ],
146
+ );
147
+
148
+ expect(result.key).toBe("updated-key");
149
+ expect(result.version).toBe(attributeGroup.version + 1);
150
+ });
151
+
152
+ test("update attribute group - setAttributes", () => {
153
+ const draft: AttributeGroupDraft = {
154
+ name: { "en-US": "Attributes Test" },
155
+ key: "attributes-test",
156
+ attributes: [
157
+ {
158
+ key: "original-attribute",
159
+ },
160
+ ],
161
+ };
162
+
163
+ const ctx = { projectKey: "dummy" };
164
+ const attributeGroup = repository.create(ctx, draft);
165
+
166
+ const result = repository.processUpdateActions(
167
+ ctx,
168
+ attributeGroup,
169
+ attributeGroup.version,
170
+ [
171
+ {
172
+ action: "setAttributes",
173
+ attributes: [
174
+ {
175
+ key: "new-attribute-1",
176
+ },
177
+ {
178
+ key: "new-attribute-2",
179
+ },
180
+ ],
181
+ } as AttributeGroupSetAttributesAction,
182
+ ],
183
+ );
184
+
185
+ expect(result.attributes).toEqual([
186
+ { key: "new-attribute-1" },
187
+ { key: "new-attribute-2" },
188
+ ]);
189
+ expect(result.version).toBe(attributeGroup.version + 1);
190
+ });
191
+
192
+ test("get and delete attribute group", () => {
193
+ const draft: AttributeGroupDraft = {
194
+ name: { "en-US": "Delete Test Attributes" },
195
+ key: "delete-test",
196
+ attributes: [],
197
+ };
198
+
199
+ const ctx = { projectKey: "dummy" };
200
+ const attributeGroup = repository.create(ctx, draft);
201
+
202
+ // Test get
203
+ const retrieved = repository.get(ctx, attributeGroup.id);
204
+ expect(retrieved).toBeDefined();
205
+ expect(retrieved?.id).toBe(attributeGroup.id);
206
+
207
+ // Test getByKey
208
+ const retrievedByKey = repository.getByKey(ctx, attributeGroup.key!);
209
+ expect(retrievedByKey).toBeDefined();
210
+ expect(retrievedByKey?.key).toBe(attributeGroup.key);
211
+
212
+ // Test delete
213
+ const deleted = repository.delete(ctx, attributeGroup.id);
214
+ expect(deleted).toBeDefined();
215
+ expect(deleted?.id).toBe(attributeGroup.id);
216
+
217
+ // Verify it's deleted
218
+ const notFound = repository.get(ctx, attributeGroup.id);
219
+ expect(notFound).toBeNull();
220
+ });
221
+ });
@@ -0,0 +1,282 @@
1
+ import type {
2
+ BusinessUnitChangeNameAction,
3
+ BusinessUnitChangeStatusAction,
4
+ BusinessUnitSetContactEmailAction,
5
+ CompanyDraft,
6
+ DivisionDraft,
7
+ } from "@commercetools/platform-sdk";
8
+ import { describe, expect, test } from "vitest";
9
+ import type { Config } from "~src/config";
10
+ import { getBaseResourceProperties } from "~src/helpers";
11
+ import { InMemoryStorage } from "~src/storage";
12
+ import { BusinessUnitRepository } from "./business-unit";
13
+ import { CustomerRepository } from "./customer";
14
+
15
+ describe("BusinessUnit Repository", () => {
16
+ const storage = new InMemoryStorage();
17
+ const config: Config = { storage, strict: false };
18
+ const repository = new BusinessUnitRepository(config);
19
+
20
+ // Add required dependencies for testing
21
+ storage.add("dummy", "store", {
22
+ ...getBaseResourceProperties(),
23
+ id: "store-123",
24
+ key: "test-store",
25
+ name: { "en-US": "Test Store" },
26
+ languages: ["en-US"],
27
+ countries: [{ code: "US" }],
28
+ distributionChannels: [],
29
+ supplyChannels: [],
30
+ productSelections: [],
31
+ });
32
+
33
+ // Create a proper customer using the customer repository
34
+ const customerRepository = new CustomerRepository(config);
35
+ const customer = customerRepository.create(
36
+ { projectKey: "dummy" },
37
+ {
38
+ email: "associate@example.com",
39
+ password: "password123",
40
+ firstName: "John",
41
+ lastName: "Associate",
42
+ },
43
+ );
44
+
45
+ test("create company business unit", () => {
46
+ const draft: CompanyDraft = {
47
+ key: "test-company",
48
+ unitType: "Company",
49
+ status: "Active",
50
+ name: "Test Company Inc.",
51
+ contactEmail: "contact@testcompany.com",
52
+ storeMode: "Explicit",
53
+ associateMode: "Explicit",
54
+ approvalRuleMode: "ExplicitApproval",
55
+ stores: [
56
+ {
57
+ typeId: "store",
58
+ key: "test-store",
59
+ },
60
+ ],
61
+ addresses: [
62
+ {
63
+ country: "US",
64
+ city: "New York",
65
+ streetName: "5th Avenue",
66
+ streetNumber: "123",
67
+ postalCode: "10001",
68
+ },
69
+ ],
70
+ defaultBillingAddress: 0,
71
+ defaultShippingAddress: 0,
72
+ billingAddresses: [0],
73
+ shippingAddresses: [0],
74
+ associates: [
75
+ {
76
+ customer: {
77
+ typeId: "customer",
78
+ id: customer.id,
79
+ },
80
+ associateRoleAssignments: [
81
+ {
82
+ associateRole: {
83
+ typeId: "associate-role",
84
+ key: "admin",
85
+ },
86
+ inheritance: "Enabled",
87
+ },
88
+ ],
89
+ },
90
+ ],
91
+ };
92
+
93
+ const ctx = { projectKey: "dummy" };
94
+ const result = repository.create(ctx, draft);
95
+
96
+ expect(result.id).toBeDefined();
97
+ expect(result.version).toBe(1);
98
+ expect(result.key).toBe(draft.key);
99
+ expect(result.unitType).toBe("Company");
100
+ expect(result.name).toBe(draft.name);
101
+ expect(result.contactEmail).toBe(draft.contactEmail);
102
+ expect(result.status).toBe(draft.status);
103
+ expect(result.storeMode).toBe(draft.storeMode);
104
+ expect(result.associateMode).toBe(draft.associateMode);
105
+ expect(result.approvalRuleMode).toBe(draft.approvalRuleMode);
106
+ expect(result.addresses).toHaveLength(1);
107
+ expect(result.addresses[0].country).toBe("US");
108
+ expect(result.stores).toHaveLength(1);
109
+ expect(result.associates).toHaveLength(1);
110
+
111
+ // Test that the business unit is stored
112
+ const items = repository.query(ctx);
113
+ expect(items.count).toBe(1);
114
+ expect(items.results[0].id).toBe(result.id);
115
+ });
116
+
117
+ test("create division business unit", () => {
118
+ // First create a company to be the parent
119
+ const companyDraft: CompanyDraft = {
120
+ key: "parent-company",
121
+ unitType: "Company",
122
+ status: "Active",
123
+ name: "Parent Company",
124
+ };
125
+
126
+ const company = repository.create({ projectKey: "dummy" }, companyDraft);
127
+
128
+ const draft: DivisionDraft = {
129
+ key: "test-division",
130
+ unitType: "Division",
131
+ status: "Active",
132
+ name: "Test Division",
133
+ contactEmail: "division@testcompany.com",
134
+ parentUnit: {
135
+ typeId: "business-unit",
136
+ key: "parent-company",
137
+ },
138
+ };
139
+
140
+ const ctx = { projectKey: "dummy" };
141
+ const result = repository.create(ctx, draft);
142
+
143
+ expect(result.id).toBeDefined();
144
+ expect(result.key).toBe(draft.key);
145
+ expect(result.unitType).toBe("Division");
146
+ expect(result.name).toBe(draft.name);
147
+ expect(result.contactEmail).toBe(draft.contactEmail);
148
+
149
+ // Check division-specific properties
150
+ if (result.unitType === "Division") {
151
+ expect(result.parentUnit?.key).toBe("parent-company");
152
+ }
153
+ });
154
+
155
+ test("create business unit with minimal data", () => {
156
+ const draft: CompanyDraft = {
157
+ key: "minimal-company",
158
+ unitType: "Company",
159
+ name: "Minimal Company",
160
+ };
161
+
162
+ const ctx = { projectKey: "dummy" };
163
+ const result = repository.create(ctx, draft);
164
+
165
+ expect(result.id).toBeDefined();
166
+ expect(result.key).toBe(draft.key);
167
+ expect(result.name).toBe(draft.name);
168
+ expect(result.unitType).toBe("Company");
169
+ expect(result.addresses).toEqual([]);
170
+ expect(result.associates).toEqual([]);
171
+ expect(result.stores).toBeUndefined();
172
+ });
173
+
174
+ test("update business unit - changeName", () => {
175
+ const draft: CompanyDraft = {
176
+ key: "update-test-company",
177
+ unitType: "Company",
178
+ name: "Original Company Name",
179
+ };
180
+
181
+ const ctx = { projectKey: "dummy" };
182
+ const businessUnit = repository.create(ctx, draft);
183
+
184
+ const result = repository.processUpdateActions(
185
+ ctx,
186
+ businessUnit,
187
+ businessUnit.version,
188
+ [
189
+ {
190
+ action: "changeName",
191
+ name: "Updated Company Name",
192
+ } as BusinessUnitChangeNameAction,
193
+ ],
194
+ );
195
+
196
+ expect(result.name).toBe("Updated Company Name");
197
+ expect(result.version).toBe(businessUnit.version + 1);
198
+ });
199
+
200
+ test("update business unit - setContactEmail", () => {
201
+ const draft: CompanyDraft = {
202
+ key: "email-test-company",
203
+ unitType: "Company",
204
+ name: "Email Test Company",
205
+ };
206
+
207
+ const ctx = { projectKey: "dummy" };
208
+ const businessUnit = repository.create(ctx, draft);
209
+
210
+ const result = repository.processUpdateActions(
211
+ ctx,
212
+ businessUnit,
213
+ businessUnit.version,
214
+ [
215
+ {
216
+ action: "setContactEmail",
217
+ contactEmail: "newemail@company.com",
218
+ } as BusinessUnitSetContactEmailAction,
219
+ ],
220
+ );
221
+
222
+ expect(result.contactEmail).toBe("newemail@company.com");
223
+ expect(result.version).toBe(businessUnit.version + 1);
224
+ });
225
+
226
+ test("update business unit - changeStatus", () => {
227
+ const draft: CompanyDraft = {
228
+ key: "status-test-company",
229
+ unitType: "Company",
230
+ name: "Status Test Company",
231
+ status: "Active",
232
+ };
233
+
234
+ const ctx = { projectKey: "dummy" };
235
+ const businessUnit = repository.create(ctx, draft);
236
+
237
+ const result = repository.processUpdateActions(
238
+ ctx,
239
+ businessUnit,
240
+ businessUnit.version,
241
+ [
242
+ {
243
+ action: "changeStatus",
244
+ status: "Inactive",
245
+ } as BusinessUnitChangeStatusAction,
246
+ ],
247
+ );
248
+
249
+ expect(result.status).toBe("Inactive");
250
+ expect(result.version).toBe(businessUnit.version + 1);
251
+ });
252
+
253
+ test("get and delete business unit", () => {
254
+ const draft: CompanyDraft = {
255
+ key: "delete-test",
256
+ unitType: "Company",
257
+ name: "Delete Test Company",
258
+ };
259
+
260
+ const ctx = { projectKey: "dummy" };
261
+ const businessUnit = repository.create(ctx, draft);
262
+
263
+ // Test get
264
+ const retrieved = repository.get(ctx, businessUnit.id);
265
+ expect(retrieved).toBeDefined();
266
+ expect(retrieved?.id).toBe(businessUnit.id);
267
+
268
+ // Test getByKey
269
+ const retrievedByKey = repository.getByKey(ctx, businessUnit.key!);
270
+ expect(retrievedByKey).toBeDefined();
271
+ expect(retrievedByKey?.key).toBe(businessUnit.key);
272
+
273
+ // Test delete
274
+ const deleted = repository.delete(ctx, businessUnit.id);
275
+ expect(deleted).toBeDefined();
276
+ expect(deleted?.id).toBe(businessUnit.id);
277
+
278
+ // Verify it's deleted
279
+ const notFound = repository.get(ctx, businessUnit.id);
280
+ expect(notFound).toBeNull();
281
+ });
282
+ });
@@ -101,6 +101,7 @@ export class BusinessUnitRepository extends AbstractResourceRepository<"business
101
101
  if (this._isDivisionDraft(draft)) {
102
102
  const division = {
103
103
  ...resource,
104
+ unitType: "Division" as const,
104
105
  parentUnit: getBusinessUnitKeyReference(
105
106
  draft.parentUnit,
106
107
  context.projectKey,
@@ -112,7 +113,10 @@ export class BusinessUnitRepository extends AbstractResourceRepository<"business
112
113
  return division;
113
114
  }
114
115
  if (this._isCompanyDraft(draft)) {
115
- const company = resource as Company;
116
+ const company = {
117
+ ...resource,
118
+ unitType: "Company" as const,
119
+ } as Company;
116
120
 
117
121
  this.saveNew(context, company);
118
122
  return company;
@@ -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 { InvalidOperationError } from "@commercetools/platform-sdk";
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
  }