@labdigital/commercetools-mock 2.53.1 → 2.54.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.js +52 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.test.ts +39 -0
- package/src/lib/predicateParser.ts +2 -0
- package/src/repositories/business-unit.ts +157 -2
- package/src/services/business-units.test.ts +586 -15
- package/src/testing/business-unit.ts +48 -0
- package/src/testing/type.ts +20 -0
package/package.json
CHANGED
|
@@ -151,6 +151,45 @@ describe("Predicate filter", () => {
|
|
|
151
151
|
expect(match("numberProperty in (1234)")).toBeTruthy();
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
+
test("in operator with and clause", async () => {
|
|
155
|
+
expect(
|
|
156
|
+
match("numberProperty in (1234) and stringProperty=:val", {
|
|
157
|
+
val: "foobar",
|
|
158
|
+
}),
|
|
159
|
+
).toBeTruthy();
|
|
160
|
+
expect(
|
|
161
|
+
match("numberProperty in (1234) and stringProperty=:val", {
|
|
162
|
+
val: "other",
|
|
163
|
+
}),
|
|
164
|
+
).toBeFalsy();
|
|
165
|
+
expect(
|
|
166
|
+
match("numberProperty in (1235) and stringProperty=:val", {
|
|
167
|
+
val: "foobar",
|
|
168
|
+
}),
|
|
169
|
+
).toBeFalsy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("within operator with and clause", async () => {
|
|
173
|
+
expect(
|
|
174
|
+
match(
|
|
175
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 2500) and stringProperty=:val",
|
|
176
|
+
{ val: "foobar" },
|
|
177
|
+
),
|
|
178
|
+
).toBeTruthy();
|
|
179
|
+
expect(
|
|
180
|
+
match(
|
|
181
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 2500) and stringProperty=:val",
|
|
182
|
+
{ val: "other" },
|
|
183
|
+
),
|
|
184
|
+
).toBeFalsy();
|
|
185
|
+
expect(
|
|
186
|
+
match(
|
|
187
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 1000) and stringProperty=:val",
|
|
188
|
+
{ val: "foobar" },
|
|
189
|
+
),
|
|
190
|
+
).toBeFalsy();
|
|
191
|
+
});
|
|
192
|
+
|
|
154
193
|
test("arrayProperty contains all (...)", async () => {
|
|
155
194
|
expect(match(`arrayProperty contains all ("foo", "bar")`)).toBeTruthy();
|
|
156
195
|
expect(
|
|
@@ -382,6 +382,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
382
382
|
})
|
|
383
383
|
.led("IN", 20, ({ left, bp }) => {
|
|
384
384
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
385
|
+
lexer.expect(")");
|
|
385
386
|
return (obj: any, vars: object) => {
|
|
386
387
|
let symbols = expr;
|
|
387
388
|
if (!Array.isArray(symbols)) {
|
|
@@ -426,6 +427,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
426
427
|
|
|
427
428
|
lexer.expect("(");
|
|
428
429
|
const expr = parser.parse({ terminals: [")"] });
|
|
430
|
+
lexer.expect(")");
|
|
429
431
|
|
|
430
432
|
return (obj: any, vars: object) => {
|
|
431
433
|
const value = resolveValue(obj, left);
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
BusinessUnitAddBillingAddressIdAction,
|
|
2
3
|
BusinessUnitAddShippingAddressIdAction,
|
|
3
4
|
BusinessUnitChangeApprovalRuleModeAction,
|
|
5
|
+
BusinessUnitChangeAssociateAction,
|
|
4
6
|
BusinessUnitChangeAssociateModeAction,
|
|
5
7
|
BusinessUnitChangeStatusAction,
|
|
8
|
+
BusinessUnitRemoveAssociateAction,
|
|
9
|
+
BusinessUnitRemoveBillingAddressIdAction,
|
|
10
|
+
BusinessUnitRemoveShippingAddressIdAction,
|
|
11
|
+
BusinessUnitSetAddressCustomFieldAction,
|
|
12
|
+
BusinessUnitSetAddressCustomTypeAction,
|
|
13
|
+
BusinessUnitSetCustomFieldAction,
|
|
6
14
|
BusinessUnitSetCustomTypeAction,
|
|
15
|
+
BusinessUnitSetDefaultBillingAddressAction,
|
|
7
16
|
BusinessUnitSetDefaultShippingAddressAction,
|
|
8
17
|
BusinessUnitUpdateAction,
|
|
9
18
|
CompanyDraft,
|
|
@@ -194,15 +203,25 @@ class BusinessUnitUpdateHandler
|
|
|
194
203
|
changeAddress(
|
|
195
204
|
context: RepositoryContext,
|
|
196
205
|
resource: Writable<BusinessUnit>,
|
|
197
|
-
{ address }: BusinessUnitChangeAddressAction,
|
|
206
|
+
{ addressId, address }: BusinessUnitChangeAddressAction,
|
|
198
207
|
) {
|
|
208
|
+
const existingAddressIndex = resource.addresses.findIndex(
|
|
209
|
+
(addr) => addr.id === addressId,
|
|
210
|
+
);
|
|
211
|
+
if (existingAddressIndex === -1) {
|
|
212
|
+
throw new Error(`Address with id ${addressId} not found`);
|
|
213
|
+
}
|
|
214
|
+
|
|
199
215
|
const newAddress = createAddress(
|
|
200
216
|
address,
|
|
201
217
|
context.projectKey,
|
|
202
218
|
this._storage,
|
|
203
219
|
);
|
|
204
220
|
if (newAddress) {
|
|
205
|
-
resource.addresses
|
|
221
|
+
resource.addresses[existingAddressIndex] = {
|
|
222
|
+
...newAddress,
|
|
223
|
+
id: addressId,
|
|
224
|
+
};
|
|
206
225
|
}
|
|
207
226
|
}
|
|
208
227
|
|
|
@@ -261,6 +280,40 @@ class BusinessUnitUpdateHandler
|
|
|
261
280
|
resource.associates = newAssociates || undefined;
|
|
262
281
|
}
|
|
263
282
|
|
|
283
|
+
removeAssociate(
|
|
284
|
+
context: RepositoryContext,
|
|
285
|
+
resource: Writable<BusinessUnit>,
|
|
286
|
+
{ customer }: BusinessUnitRemoveAssociateAction,
|
|
287
|
+
) {
|
|
288
|
+
resource.associates = resource.associates.filter(
|
|
289
|
+
(associate) => associate.customer.id !== customer.id,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
changeAssociate(
|
|
294
|
+
context: RepositoryContext,
|
|
295
|
+
resource: Writable<BusinessUnit>,
|
|
296
|
+
{ associate }: BusinessUnitChangeAssociateAction,
|
|
297
|
+
) {
|
|
298
|
+
const existingAssociateIndex = resource.associates.findIndex(
|
|
299
|
+
(a) => a.customer.id === associate.customer.id,
|
|
300
|
+
);
|
|
301
|
+
if (existingAssociateIndex === -1) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
`Associate with customer id ${associate.customer.id} not found`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const newAssociate = createAssociate(
|
|
308
|
+
associate,
|
|
309
|
+
context.projectKey,
|
|
310
|
+
this._storage,
|
|
311
|
+
);
|
|
312
|
+
if (newAssociate) {
|
|
313
|
+
resource.associates[existingAssociateIndex] = newAssociate;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
264
317
|
setContactEmail(
|
|
265
318
|
context: RepositoryContext,
|
|
266
319
|
resource: Writable<BusinessUnit>,
|
|
@@ -314,6 +367,108 @@ class BusinessUnitUpdateHandler
|
|
|
314
367
|
}
|
|
315
368
|
}
|
|
316
369
|
|
|
370
|
+
removeShippingAddressId(
|
|
371
|
+
context: RepositoryContext,
|
|
372
|
+
resource: Writable<BusinessUnit>,
|
|
373
|
+
{ addressId }: BusinessUnitRemoveShippingAddressIdAction,
|
|
374
|
+
) {
|
|
375
|
+
if (resource.shippingAddressIds) {
|
|
376
|
+
resource.shippingAddressIds = resource.shippingAddressIds.filter(
|
|
377
|
+
(id) => id !== addressId,
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (resource.defaultShippingAddressId === addressId) {
|
|
381
|
+
resource.defaultShippingAddressId = undefined;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
addBillingAddressId(
|
|
386
|
+
context: RepositoryContext,
|
|
387
|
+
resource: Writable<BusinessUnit>,
|
|
388
|
+
{ addressId }: BusinessUnitAddBillingAddressIdAction,
|
|
389
|
+
) {
|
|
390
|
+
if (!resource.billingAddressIds) {
|
|
391
|
+
resource.billingAddressIds = [];
|
|
392
|
+
}
|
|
393
|
+
if (addressId) {
|
|
394
|
+
resource.billingAddressIds.push(addressId);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
removeBillingAddressId(
|
|
399
|
+
context: RepositoryContext,
|
|
400
|
+
resource: Writable<BusinessUnit>,
|
|
401
|
+
{ addressId }: BusinessUnitRemoveBillingAddressIdAction,
|
|
402
|
+
) {
|
|
403
|
+
if (resource.billingAddressIds) {
|
|
404
|
+
resource.billingAddressIds = resource.billingAddressIds.filter(
|
|
405
|
+
(id) => id !== addressId,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
if (resource.defaultBillingAddressId === addressId) {
|
|
409
|
+
resource.defaultBillingAddressId = undefined;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
setDefaultBillingAddress(
|
|
414
|
+
context: RepositoryContext,
|
|
415
|
+
resource: Writable<BusinessUnit>,
|
|
416
|
+
{ addressId }: BusinessUnitSetDefaultBillingAddressAction,
|
|
417
|
+
) {
|
|
418
|
+
resource.defaultBillingAddressId = addressId;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
setCustomField(
|
|
422
|
+
context: RepositoryContext,
|
|
423
|
+
resource: Writable<BusinessUnit>,
|
|
424
|
+
{ name, value }: BusinessUnitSetCustomFieldAction,
|
|
425
|
+
) {
|
|
426
|
+
if (!resource.custom) {
|
|
427
|
+
throw new Error("Resource has no custom type");
|
|
428
|
+
}
|
|
429
|
+
resource.custom.fields[name] = value;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
setAddressCustomField(
|
|
433
|
+
context: RepositoryContext,
|
|
434
|
+
resource: Writable<BusinessUnit>,
|
|
435
|
+
{ addressId, name, value }: BusinessUnitSetAddressCustomFieldAction,
|
|
436
|
+
) {
|
|
437
|
+
const address = resource.addresses.find((addr) => addr.id === addressId);
|
|
438
|
+
if (!address) {
|
|
439
|
+
throw new Error(`Address with id ${addressId} not found`);
|
|
440
|
+
}
|
|
441
|
+
if (!address.custom) {
|
|
442
|
+
// If the address doesn't have custom fields, we need to initialize them
|
|
443
|
+
// This might require a type to be set first, but we'll just create minimal structure
|
|
444
|
+
throw new Error(
|
|
445
|
+
"Address has no custom type set. Use setAddressCustomType first.",
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
address.custom.fields[name] = value;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
setAddressCustomType(
|
|
452
|
+
context: RepositoryContext,
|
|
453
|
+
resource: Writable<BusinessUnit>,
|
|
454
|
+
{ addressId, type, fields }: BusinessUnitSetAddressCustomTypeAction,
|
|
455
|
+
) {
|
|
456
|
+
const address = resource.addresses.find((addr) => addr.id === addressId);
|
|
457
|
+
if (!address) {
|
|
458
|
+
throw new Error(`Address with id ${addressId} not found`);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (!type) {
|
|
462
|
+
address.custom = undefined;
|
|
463
|
+
} else {
|
|
464
|
+
address.custom = createCustomFields(
|
|
465
|
+
{ type, fields },
|
|
466
|
+
context.projectKey,
|
|
467
|
+
this._storage,
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
317
472
|
removeAddress(
|
|
318
473
|
context: RepositoryContext,
|
|
319
474
|
resource: Writable<BusinessUnit>,
|