@labdigital/commercetools-mock 2.51.0 → 2.53.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 (42) hide show
  1. package/dist/index.d.ts +34 -23
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +140 -13
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/lib/product-review-statistics.test.ts +349 -0
  7. package/src/lib/productSearchFilter.test.ts +77 -0
  8. package/src/lib/review-statistics.ts +58 -0
  9. package/src/product-projection-search.ts +17 -2
  10. package/src/product-search-availability.test.ts +242 -0
  11. package/src/product-search.ts +22 -4
  12. package/src/repositories/as-associate.test.ts +126 -0
  13. package/src/repositories/attribute-group.test.ts +221 -0
  14. package/src/repositories/business-unit.test.ts +425 -0
  15. package/src/repositories/business-unit.ts +57 -1
  16. package/src/repositories/channel.test.ts +374 -0
  17. package/src/repositories/customer-group.test.ts +262 -0
  18. package/src/repositories/extension.test.ts +306 -0
  19. package/src/repositories/index.test.ts +17 -0
  20. package/src/repositories/product/index.ts +22 -1
  21. package/src/repositories/product-projection.ts +8 -2
  22. package/src/repositories/review.test.ts +636 -0
  23. package/src/repositories/review.ts +145 -4
  24. package/src/repositories/subscription.test.ts +207 -0
  25. package/src/repositories/zone.test.ts +278 -0
  26. package/src/services/as-associate-cart.test.ts +58 -0
  27. package/src/services/as-associate.test.ts +34 -0
  28. package/src/services/attribute-group.test.ts +114 -0
  29. package/src/services/channel.test.ts +90 -0
  30. package/src/services/customer-group.test.ts +85 -0
  31. package/src/services/discount-code.test.ts +120 -0
  32. package/src/services/extension.test.ts +130 -0
  33. package/src/services/my-business-unit.test.ts +113 -0
  34. package/src/services/my-business-unit.ts +6 -0
  35. package/src/services/my-customer.test.ts +24 -0
  36. package/src/services/order.test.ts +18 -0
  37. package/src/services/product-discount.test.ts +146 -0
  38. package/src/services/project.test.ts +17 -0
  39. package/src/services/reviews.test.ts +230 -0
  40. package/src/services/subscription.test.ts +151 -0
  41. package/src/services/type.test.ts +127 -0
  42. package/src/services/zone.test.ts +117 -0
@@ -0,0 +1,374 @@
1
+ import type {
2
+ ChannelChangeDescriptionAction,
3
+ ChannelChangeKeyAction,
4
+ ChannelChangeNameAction,
5
+ ChannelDraft,
6
+ ChannelSetAddressAction,
7
+ ChannelSetCustomFieldAction,
8
+ ChannelSetCustomTypeAction,
9
+ ChannelSetGeoLocationAction,
10
+ } from "@commercetools/platform-sdk";
11
+ import { describe, expect, test } from "vitest";
12
+ import type { Config } from "~src/config";
13
+ import { getBaseResourceProperties } from "~src/helpers";
14
+ import { InMemoryStorage } from "~src/storage";
15
+ import { ChannelRepository } from "./channel";
16
+
17
+ describe("Channel Repository", () => {
18
+ const storage = new InMemoryStorage();
19
+ const config: Config = { storage, strict: false };
20
+ const repository = new ChannelRepository(config);
21
+
22
+ // Add a custom type for testing
23
+ storage.add("dummy", "type", {
24
+ ...getBaseResourceProperties(),
25
+ id: "custom-type-id",
26
+ key: "custom-type-key",
27
+ name: { "en-US": "Custom Type" },
28
+ resourceTypeIds: ["channel"],
29
+ fieldDefinitions: [
30
+ {
31
+ name: "description",
32
+ label: { "en-US": "Description" },
33
+ required: false,
34
+ type: { name: "String" },
35
+ inputHint: "SingleLine",
36
+ },
37
+ ],
38
+ });
39
+
40
+ test("create channel", () => {
41
+ const draft: ChannelDraft = {
42
+ key: "distribution-center-1",
43
+ name: { "en-US": "Distribution Center 1" },
44
+ description: { "en-US": "Main distribution center" },
45
+ roles: ["InventorySupply", "OrderExport"],
46
+ };
47
+
48
+ const ctx = { projectKey: "dummy" };
49
+ const result = repository.create(ctx, draft);
50
+
51
+ expect(result.id).toBeDefined();
52
+ expect(result.version).toBe(1);
53
+ expect(result.key).toBe(draft.key);
54
+ expect(result.name).toEqual(draft.name);
55
+ expect(result.description).toEqual(draft.description);
56
+ expect(result.roles).toEqual(draft.roles);
57
+ expect(result.geoLocation).toBeUndefined();
58
+ expect(result.address).toBeUndefined();
59
+ expect(result.custom).toBeUndefined();
60
+
61
+ // Test that the channel is stored
62
+ const items = repository.query(ctx);
63
+ expect(items.count).toBe(1);
64
+ expect(items.results[0].id).toBe(result.id);
65
+ });
66
+
67
+ test("create channel with all optional fields", () => {
68
+ const draft: ChannelDraft = {
69
+ key: "store-berlin",
70
+ name: { "en-US": "Berlin Store", "de-DE": "Berlin Geschäft" },
71
+ description: { "en-US": "Store in Berlin" },
72
+ roles: ["ProductDistribution"],
73
+ address: {
74
+ country: "DE",
75
+ city: "Berlin",
76
+ streetName: "Hauptstraße",
77
+ streetNumber: "123",
78
+ postalCode: "10115",
79
+ },
80
+ geoLocation: {
81
+ type: "Point",
82
+ coordinates: [13.405, 52.52],
83
+ },
84
+ custom: {
85
+ type: {
86
+ typeId: "type",
87
+ id: "custom-type-id",
88
+ },
89
+ fields: {
90
+ description: "Custom description",
91
+ },
92
+ },
93
+ };
94
+
95
+ const ctx = { projectKey: "dummy" };
96
+ const result = repository.create(ctx, draft);
97
+
98
+ expect(result.id).toBeDefined();
99
+ expect(result.key).toBe(draft.key);
100
+ expect(result.name).toEqual(draft.name);
101
+ expect(result.address?.country).toBe("DE");
102
+ expect(result.address?.city).toBe("Berlin");
103
+ expect(result.geoLocation).toEqual(draft.geoLocation);
104
+ expect(result.custom?.fields.description).toBe("Custom description");
105
+ });
106
+
107
+ test("update channel - changeName", () => {
108
+ const draft: ChannelDraft = {
109
+ key: "test-channel",
110
+ name: { "en-US": "Test Channel" },
111
+ };
112
+
113
+ const ctx = { projectKey: "dummy" };
114
+ const channel = repository.create(ctx, draft);
115
+
116
+ const result = repository.processUpdateActions(
117
+ ctx,
118
+ channel,
119
+ channel.version,
120
+ [
121
+ {
122
+ action: "changeName",
123
+ name: { "en-US": "Updated Test Channel" },
124
+ } as ChannelChangeNameAction,
125
+ ],
126
+ );
127
+
128
+ expect(result.name).toEqual({ "en-US": "Updated Test Channel" });
129
+ expect(result.version).toBe(channel.version + 1);
130
+ });
131
+
132
+ test("update channel - changeKey", () => {
133
+ const draft: ChannelDraft = {
134
+ key: "test-channel-2",
135
+ name: { "en-US": "Test Channel 2" },
136
+ };
137
+
138
+ const ctx = { projectKey: "dummy" };
139
+ const channel = repository.create(ctx, draft);
140
+
141
+ const result = repository.processUpdateActions(
142
+ ctx,
143
+ channel,
144
+ channel.version,
145
+ [
146
+ {
147
+ action: "changeKey",
148
+ key: "new-channel-key",
149
+ } as ChannelChangeKeyAction,
150
+ ],
151
+ );
152
+
153
+ expect(result.key).toBe("new-channel-key");
154
+ expect(result.version).toBe(channel.version + 1);
155
+ });
156
+
157
+ test("update channel - changeDescription", () => {
158
+ const draft: ChannelDraft = {
159
+ key: "test-channel-3",
160
+ name: { "en-US": "Test Channel 3" },
161
+ };
162
+
163
+ const ctx = { projectKey: "dummy" };
164
+ const channel = repository.create(ctx, draft);
165
+
166
+ const result = repository.processUpdateActions(
167
+ ctx,
168
+ channel,
169
+ channel.version,
170
+ [
171
+ {
172
+ action: "changeDescription",
173
+ description: { "en-US": "New description" },
174
+ } as ChannelChangeDescriptionAction,
175
+ ],
176
+ );
177
+
178
+ expect(result.description).toEqual({ "en-US": "New description" });
179
+ expect(result.version).toBe(channel.version + 1);
180
+ });
181
+
182
+ test("update channel - setAddress", () => {
183
+ const draft: ChannelDraft = {
184
+ key: "test-channel-4",
185
+ name: { "en-US": "Test Channel 4" },
186
+ };
187
+
188
+ const ctx = { projectKey: "dummy" };
189
+ const channel = repository.create(ctx, draft);
190
+
191
+ const result = repository.processUpdateActions(
192
+ ctx,
193
+ channel,
194
+ channel.version,
195
+ [
196
+ {
197
+ action: "setAddress",
198
+ address: {
199
+ country: "US",
200
+ city: "New York",
201
+ streetName: "Broadway",
202
+ streetNumber: "123",
203
+ postalCode: "10001",
204
+ },
205
+ } as ChannelSetAddressAction,
206
+ ],
207
+ );
208
+
209
+ expect(result.address?.country).toBe("US");
210
+ expect(result.address?.city).toBe("New York");
211
+ expect(result.version).toBe(channel.version + 1);
212
+ });
213
+
214
+ test("update channel - setGeoLocation", () => {
215
+ const draft: ChannelDraft = {
216
+ key: "test-channel-5",
217
+ name: { "en-US": "Test Channel 5" },
218
+ };
219
+
220
+ const ctx = { projectKey: "dummy" };
221
+ const channel = repository.create(ctx, draft);
222
+
223
+ const result = repository.processUpdateActions(
224
+ ctx,
225
+ channel,
226
+ channel.version,
227
+ [
228
+ {
229
+ action: "setGeoLocation",
230
+ geoLocation: {
231
+ type: "Point",
232
+ coordinates: [2.3522, 48.8566], // Paris coordinates
233
+ },
234
+ } as ChannelSetGeoLocationAction,
235
+ ],
236
+ );
237
+
238
+ expect(result.geoLocation).toEqual({
239
+ type: "Point",
240
+ coordinates: [2.3522, 48.8566],
241
+ });
242
+ expect(result.version).toBe(channel.version + 1);
243
+ });
244
+
245
+ test("update channel - setCustomType", () => {
246
+ const draft: ChannelDraft = {
247
+ key: "test-channel-6",
248
+ name: { "en-US": "Test Channel 6" },
249
+ };
250
+
251
+ const ctx = { projectKey: "dummy" };
252
+ const channel = repository.create(ctx, draft);
253
+
254
+ // Set custom type
255
+ const result = repository.processUpdateActions(
256
+ ctx,
257
+ channel,
258
+ channel.version,
259
+ [
260
+ {
261
+ action: "setCustomType",
262
+ type: {
263
+ typeId: "type",
264
+ id: "custom-type-id",
265
+ },
266
+ fields: {
267
+ description: "New custom field value",
268
+ },
269
+ } as ChannelSetCustomTypeAction,
270
+ ],
271
+ );
272
+
273
+ expect(result.custom).toBeDefined();
274
+ expect(result.custom?.fields.description).toBe("New custom field value");
275
+ expect(result.version).toBe(channel.version + 1);
276
+
277
+ // Remove custom type
278
+ const result2 = repository.processUpdateActions(
279
+ ctx,
280
+ result,
281
+ result.version,
282
+ [
283
+ {
284
+ action: "setCustomType",
285
+ } as ChannelSetCustomTypeAction,
286
+ ],
287
+ );
288
+
289
+ expect(result2.custom).toBeUndefined();
290
+ expect(result2.version).toBe(result.version + 1);
291
+ });
292
+
293
+ test("update channel - setCustomField", () => {
294
+ const draft: ChannelDraft = {
295
+ key: "test-channel-7",
296
+ name: { "en-US": "Test Channel 7" },
297
+ custom: {
298
+ type: {
299
+ typeId: "type",
300
+ id: "custom-type-id",
301
+ },
302
+ fields: {
303
+ description: "Initial description",
304
+ },
305
+ },
306
+ };
307
+
308
+ const ctx = { projectKey: "dummy" };
309
+ const channel = repository.create(ctx, draft);
310
+
311
+ // Update custom field
312
+ const result = repository.processUpdateActions(
313
+ ctx,
314
+ channel,
315
+ channel.version,
316
+ [
317
+ {
318
+ action: "setCustomField",
319
+ name: "description",
320
+ value: "Updated description",
321
+ } as ChannelSetCustomFieldAction,
322
+ ],
323
+ );
324
+
325
+ expect(result.custom?.fields.description).toBe("Updated description");
326
+ expect(result.version).toBe(channel.version + 1);
327
+
328
+ // Remove custom field
329
+ const result2 = repository.processUpdateActions(
330
+ ctx,
331
+ result,
332
+ result.version,
333
+ [
334
+ {
335
+ action: "setCustomField",
336
+ name: "description",
337
+ value: null,
338
+ } as ChannelSetCustomFieldAction,
339
+ ],
340
+ );
341
+
342
+ expect(result2.custom?.fields.description).toBeUndefined();
343
+ expect(result2.version).toBe(result.version + 1);
344
+ });
345
+
346
+ test("get and delete channel", () => {
347
+ const draft: ChannelDraft = {
348
+ key: "delete-test",
349
+ name: { "en-US": "Delete Test Channel" },
350
+ };
351
+
352
+ const ctx = { projectKey: "dummy" };
353
+ const channel = repository.create(ctx, draft);
354
+
355
+ // Test get
356
+ const retrieved = repository.get(ctx, channel.id);
357
+ expect(retrieved).toBeDefined();
358
+ expect(retrieved?.id).toBe(channel.id);
359
+
360
+ // Test getByKey
361
+ const retrievedByKey = repository.getByKey(ctx, channel.key!);
362
+ expect(retrievedByKey).toBeDefined();
363
+ expect(retrievedByKey?.key).toBe(channel.key);
364
+
365
+ // Test delete
366
+ const deleted = repository.delete(ctx, channel.id);
367
+ expect(deleted).toBeDefined();
368
+ expect(deleted?.id).toBe(channel.id);
369
+
370
+ // Verify it's deleted
371
+ const notFound = repository.get(ctx, channel.id);
372
+ expect(notFound).toBeNull();
373
+ });
374
+ });
@@ -0,0 +1,262 @@
1
+ import type {
2
+ CustomerGroupChangeNameAction,
3
+ CustomerGroupDraft,
4
+ CustomerGroupSetCustomFieldAction,
5
+ CustomerGroupSetCustomTypeAction,
6
+ CustomerGroupSetKeyAction,
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 { CustomerGroupRepository } from "./customer-group";
13
+
14
+ describe("CustomerGroup Repository", () => {
15
+ const storage = new InMemoryStorage();
16
+ const config: Config = { storage, strict: false };
17
+ const repository = new CustomerGroupRepository(config);
18
+
19
+ // Add a custom type for testing
20
+ storage.add("dummy", "type", {
21
+ ...getBaseResourceProperties(),
22
+ id: "custom-type-id",
23
+ key: "custom-type-key",
24
+ name: { "en-US": "Custom Type" },
25
+ resourceTypeIds: ["customer-group"],
26
+ fieldDefinitions: [
27
+ {
28
+ name: "description",
29
+ label: { "en-US": "Description" },
30
+ required: false,
31
+ type: { name: "String" },
32
+ inputHint: "SingleLine",
33
+ },
34
+ ],
35
+ });
36
+
37
+ test("create customer group", () => {
38
+ const draft: CustomerGroupDraft = {
39
+ key: "premium-customers",
40
+ groupName: "Premium Customers",
41
+ };
42
+
43
+ const ctx = { projectKey: "dummy" };
44
+ const result = repository.create(ctx, draft);
45
+
46
+ expect(result.id).toBeDefined();
47
+ expect(result.version).toBe(1);
48
+ expect(result.key).toBe(draft.key);
49
+ expect(result.name).toBe(draft.groupName);
50
+ expect(result.custom).toBeUndefined();
51
+
52
+ // Test that the customer group is stored
53
+ const items = repository.query(ctx);
54
+ expect(items.count).toBe(1);
55
+ expect(items.results[0].id).toBe(result.id);
56
+ });
57
+
58
+ test("create customer group with custom fields", () => {
59
+ const draft: CustomerGroupDraft = {
60
+ key: "vip-customers",
61
+ groupName: "VIP Customers",
62
+ custom: {
63
+ type: {
64
+ typeId: "type",
65
+ id: "custom-type-id",
66
+ },
67
+ fields: {
68
+ description: "Very important customers",
69
+ },
70
+ },
71
+ };
72
+
73
+ const ctx = { projectKey: "dummy" };
74
+ const result = repository.create(ctx, draft);
75
+
76
+ expect(result.id).toBeDefined();
77
+ expect(result.key).toBe(draft.key);
78
+ expect(result.name).toBe(draft.groupName);
79
+ expect(result.custom).toBeDefined();
80
+ expect(result.custom?.fields.description).toBe("Very important customers");
81
+ });
82
+
83
+ test("update customer group - changeName", () => {
84
+ const draft: CustomerGroupDraft = {
85
+ key: "test-customers",
86
+ groupName: "Test Customers",
87
+ };
88
+
89
+ const ctx = { projectKey: "dummy" };
90
+ const customerGroup = repository.create(ctx, draft);
91
+
92
+ const result = repository.processUpdateActions(
93
+ ctx,
94
+ customerGroup,
95
+ customerGroup.version,
96
+ [
97
+ {
98
+ action: "changeName",
99
+ name: "Updated Test Customers",
100
+ } as CustomerGroupChangeNameAction,
101
+ ],
102
+ );
103
+
104
+ expect(result.name).toBe("Updated Test Customers");
105
+ expect(result.version).toBe(customerGroup.version + 1);
106
+ });
107
+
108
+ test("update customer group - setKey", () => {
109
+ const draft: CustomerGroupDraft = {
110
+ key: "test-customers-2",
111
+ groupName: "Test Customers 2",
112
+ };
113
+
114
+ const ctx = { projectKey: "dummy" };
115
+ const customerGroup = repository.create(ctx, draft);
116
+
117
+ const result = repository.processUpdateActions(
118
+ ctx,
119
+ customerGroup,
120
+ customerGroup.version,
121
+ [
122
+ {
123
+ action: "setKey",
124
+ key: "new-customer-key",
125
+ } as CustomerGroupSetKeyAction,
126
+ ],
127
+ );
128
+
129
+ expect(result.key).toBe("new-customer-key");
130
+ expect(result.version).toBe(customerGroup.version + 1);
131
+ });
132
+
133
+ test("update customer group - setCustomType", () => {
134
+ const draft: CustomerGroupDraft = {
135
+ key: "test-customers-3",
136
+ groupName: "Test Customers 3",
137
+ };
138
+
139
+ const ctx = { projectKey: "dummy" };
140
+ const customerGroup = repository.create(ctx, draft);
141
+
142
+ // Set custom type
143
+ const result = repository.processUpdateActions(
144
+ ctx,
145
+ customerGroup,
146
+ customerGroup.version,
147
+ [
148
+ {
149
+ action: "setCustomType",
150
+ type: {
151
+ typeId: "type",
152
+ id: "custom-type-id",
153
+ },
154
+ fields: {
155
+ description: "New custom field value",
156
+ },
157
+ } as CustomerGroupSetCustomTypeAction,
158
+ ],
159
+ );
160
+
161
+ expect(result.custom).toBeDefined();
162
+ expect(result.custom?.fields.description).toBe("New custom field value");
163
+ expect(result.version).toBe(customerGroup.version + 1);
164
+
165
+ // Remove custom type
166
+ const result2 = repository.processUpdateActions(
167
+ ctx,
168
+ result,
169
+ result.version,
170
+ [
171
+ {
172
+ action: "setCustomType",
173
+ } as CustomerGroupSetCustomTypeAction,
174
+ ],
175
+ );
176
+
177
+ expect(result2.custom).toBeUndefined();
178
+ expect(result2.version).toBe(result.version + 1);
179
+ });
180
+
181
+ test("update customer group - setCustomField", () => {
182
+ const draft: CustomerGroupDraft = {
183
+ key: "test-customers-4",
184
+ groupName: "Test Customers 4",
185
+ custom: {
186
+ type: {
187
+ typeId: "type",
188
+ id: "custom-type-id",
189
+ },
190
+ fields: {
191
+ description: "Initial description",
192
+ },
193
+ },
194
+ };
195
+
196
+ const ctx = { projectKey: "dummy" };
197
+ const customerGroup = repository.create(ctx, draft);
198
+
199
+ // Update custom field
200
+ const result = repository.processUpdateActions(
201
+ ctx,
202
+ customerGroup,
203
+ customerGroup.version,
204
+ [
205
+ {
206
+ action: "setCustomField",
207
+ name: "description",
208
+ value: "Updated description",
209
+ } as CustomerGroupSetCustomFieldAction,
210
+ ],
211
+ );
212
+
213
+ expect(result.custom?.fields.description).toBe("Updated description");
214
+ expect(result.version).toBe(customerGroup.version + 1);
215
+
216
+ // Remove custom field
217
+ const result2 = repository.processUpdateActions(
218
+ ctx,
219
+ result,
220
+ result.version,
221
+ [
222
+ {
223
+ action: "setCustomField",
224
+ name: "description",
225
+ value: null,
226
+ } as CustomerGroupSetCustomFieldAction,
227
+ ],
228
+ );
229
+
230
+ expect(result2.custom?.fields.description).toBeUndefined();
231
+ expect(result2.version).toBe(result.version + 1);
232
+ });
233
+
234
+ test("get and delete customer group", () => {
235
+ const draft: CustomerGroupDraft = {
236
+ key: "delete-test",
237
+ groupName: "Delete Test",
238
+ };
239
+
240
+ const ctx = { projectKey: "dummy" };
241
+ const customerGroup = repository.create(ctx, draft);
242
+
243
+ // Test get
244
+ const retrieved = repository.get(ctx, customerGroup.id);
245
+ expect(retrieved).toBeDefined();
246
+ expect(retrieved?.id).toBe(customerGroup.id);
247
+
248
+ // Test getByKey
249
+ const retrievedByKey = repository.getByKey(ctx, customerGroup.key!);
250
+ expect(retrievedByKey).toBeDefined();
251
+ expect(retrievedByKey?.key).toBe(customerGroup.key);
252
+
253
+ // Test delete
254
+ const deleted = repository.delete(ctx, customerGroup.id);
255
+ expect(deleted).toBeDefined();
256
+ expect(deleted?.id).toBe(customerGroup.id);
257
+
258
+ // Verify it's deleted
259
+ const notFound = repository.get(ctx, customerGroup.id);
260
+ expect(notFound).toBeNull();
261
+ });
262
+ });