@labdigital/commercetools-mock 2.32.0 → 2.33.1
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.cjs +49 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +66 -0
- package/src/repositories/order/actions.ts +9 -0
- package/src/services/cart.test.ts +134 -0
- package/src/services/order.test.ts +16 -0
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type CartRemoveDiscountCodeAction,
|
|
13
13
|
type CartRemoveLineItemAction,
|
|
14
14
|
type CartSetBillingAddressAction,
|
|
15
|
+
type CartSetBillingAddressCustomTypeAction,
|
|
15
16
|
type CartSetCountryAction,
|
|
16
17
|
type CartSetCustomFieldAction,
|
|
17
18
|
type CartSetCustomShippingMethodAction,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
type CartSetLineItemShippingDetailsAction,
|
|
22
23
|
type CartSetLocaleAction,
|
|
23
24
|
type CartSetShippingAddressAction,
|
|
25
|
+
type CartSetShippingAddressCustomTypeAction,
|
|
24
26
|
type CartSetShippingMethodAction,
|
|
25
27
|
type CustomFields,
|
|
26
28
|
type GeneralError,
|
|
@@ -323,6 +325,38 @@ export class CartUpdateHandler
|
|
|
323
325
|
);
|
|
324
326
|
}
|
|
325
327
|
|
|
328
|
+
setBillingAddressCustomType(
|
|
329
|
+
context: RepositoryContext,
|
|
330
|
+
resource: Writable<Cart>,
|
|
331
|
+
custom: CartSetBillingAddressCustomTypeAction,
|
|
332
|
+
) {
|
|
333
|
+
if (!resource.billingAddress) {
|
|
334
|
+
throw new Error("Resource has no billing address");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!custom.type) {
|
|
338
|
+
resource.billingAddress.custom = undefined;
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const resolvedType = this._storage.getByResourceIdentifier<"type">(
|
|
343
|
+
context.projectKey,
|
|
344
|
+
custom.type,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
if (!resolvedType) {
|
|
348
|
+
throw new Error(`Type ${custom.type} not found`);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
resource.billingAddress.custom = {
|
|
352
|
+
type: {
|
|
353
|
+
typeId: "type",
|
|
354
|
+
id: resolvedType.id,
|
|
355
|
+
},
|
|
356
|
+
fields: custom.fields || {},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
326
360
|
setCountry(
|
|
327
361
|
context: RepositoryContext,
|
|
328
362
|
resource: Writable<Cart>,
|
|
@@ -503,6 +537,38 @@ export class CartUpdateHandler
|
|
|
503
537
|
};
|
|
504
538
|
}
|
|
505
539
|
|
|
540
|
+
setShippingAddressCustomType(
|
|
541
|
+
context: RepositoryContext,
|
|
542
|
+
resource: Writable<Cart>,
|
|
543
|
+
custom: CartSetShippingAddressCustomTypeAction,
|
|
544
|
+
) {
|
|
545
|
+
if (!resource.shippingAddress) {
|
|
546
|
+
throw new Error("Resource has no shipping address");
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (!custom.type) {
|
|
550
|
+
resource.shippingAddress.custom = undefined;
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const resolvedType = this._storage.getByResourceIdentifier<"type">(
|
|
555
|
+
context.projectKey,
|
|
556
|
+
custom.type,
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
if (!resolvedType) {
|
|
560
|
+
throw new Error(`Type ${custom.type} not found`);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
resource.shippingAddress.custom = {
|
|
564
|
+
type: {
|
|
565
|
+
typeId: "type",
|
|
566
|
+
id: resolvedType.id,
|
|
567
|
+
},
|
|
568
|
+
fields: custom.fields || {},
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
|
|
506
572
|
setShippingMethod(
|
|
507
573
|
context: RepositoryContext,
|
|
508
574
|
resource: Writable<Cart>,
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
OrderSetDeliveryCustomFieldAction,
|
|
16
16
|
OrderSetLocaleAction,
|
|
17
17
|
OrderSetOrderNumberAction,
|
|
18
|
+
OrderSetPurchaseOrderNumberAction,
|
|
18
19
|
OrderSetShippingAddressAction,
|
|
19
20
|
OrderSetStoreAction,
|
|
20
21
|
OrderTransitionStateAction,
|
|
@@ -227,6 +228,14 @@ export class OrderUpdateHandler
|
|
|
227
228
|
resource.orderNumber = orderNumber;
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
setPurchaseOrderNumber(
|
|
232
|
+
context: RepositoryContext,
|
|
233
|
+
resource: Writable<Order>,
|
|
234
|
+
{ purchaseOrderNumber }: OrderSetPurchaseOrderNumberAction,
|
|
235
|
+
) {
|
|
236
|
+
resource.purchaseOrderNumber = purchaseOrderNumber;
|
|
237
|
+
}
|
|
238
|
+
|
|
230
239
|
setShippingAddress(
|
|
231
240
|
context: RepositoryContext,
|
|
232
241
|
resource: Writable<Order>,
|
|
@@ -605,6 +605,140 @@ describe("Cart Update Actions", () => {
|
|
|
605
605
|
expect(response.body.shippingAddress).toEqual(address);
|
|
606
606
|
});
|
|
607
607
|
|
|
608
|
+
test("setBillingAddressCustomType", async () => {
|
|
609
|
+
assert(cart, "cart not created");
|
|
610
|
+
|
|
611
|
+
const address: Address = {
|
|
612
|
+
streetName: "Street name",
|
|
613
|
+
city: "Utrecht",
|
|
614
|
+
country: "NL",
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
const type = await supertest(ctMock.app)
|
|
618
|
+
.post(`/dummy/types`)
|
|
619
|
+
.send({
|
|
620
|
+
key: "my-type",
|
|
621
|
+
name: {
|
|
622
|
+
en: "My Type",
|
|
623
|
+
},
|
|
624
|
+
description: {
|
|
625
|
+
en: "My Type Description",
|
|
626
|
+
},
|
|
627
|
+
fieldDefinitions: [
|
|
628
|
+
{
|
|
629
|
+
name: "foo",
|
|
630
|
+
label: {
|
|
631
|
+
en: "foo",
|
|
632
|
+
},
|
|
633
|
+
required: false,
|
|
634
|
+
type: {
|
|
635
|
+
name: "String",
|
|
636
|
+
},
|
|
637
|
+
inputHint: "SingleLine",
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
})
|
|
641
|
+
.then((x) => x.body);
|
|
642
|
+
|
|
643
|
+
assert(type, "type not created");
|
|
644
|
+
|
|
645
|
+
const response = await supertest(ctMock.app)
|
|
646
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
647
|
+
.send({
|
|
648
|
+
version: 1,
|
|
649
|
+
actions: [
|
|
650
|
+
{ action: "setBillingAddress", address },
|
|
651
|
+
{
|
|
652
|
+
action: "setBillingAddressCustomType",
|
|
653
|
+
type: {
|
|
654
|
+
typeId: "type",
|
|
655
|
+
type: "my-type",
|
|
656
|
+
key: "my-type",
|
|
657
|
+
},
|
|
658
|
+
fields: {
|
|
659
|
+
foo: "bar",
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
],
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
expect(response.status).toBe(200);
|
|
666
|
+
expect(response.body.version).toBe(3);
|
|
667
|
+
expect(response.body.billingAddress).toEqual({
|
|
668
|
+
...address,
|
|
669
|
+
custom: {
|
|
670
|
+
type: { typeId: "type", id: type.id },
|
|
671
|
+
fields: { foo: "bar" },
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
test("setShippingAddressCustomType", async () => {
|
|
676
|
+
assert(cart, "cart not created");
|
|
677
|
+
|
|
678
|
+
const address: Address = {
|
|
679
|
+
streetName: "Street name",
|
|
680
|
+
city: "Utrecht",
|
|
681
|
+
country: "NL",
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
const type = await supertest(ctMock.app)
|
|
685
|
+
.post(`/dummy/types`)
|
|
686
|
+
.send({
|
|
687
|
+
key: "my-type",
|
|
688
|
+
name: {
|
|
689
|
+
en: "My Type",
|
|
690
|
+
},
|
|
691
|
+
description: {
|
|
692
|
+
en: "My Type Description",
|
|
693
|
+
},
|
|
694
|
+
fieldDefinitions: [
|
|
695
|
+
{
|
|
696
|
+
name: "foo",
|
|
697
|
+
label: {
|
|
698
|
+
en: "foo",
|
|
699
|
+
},
|
|
700
|
+
required: false,
|
|
701
|
+
type: {
|
|
702
|
+
name: "String",
|
|
703
|
+
},
|
|
704
|
+
inputHint: "SingleLine",
|
|
705
|
+
},
|
|
706
|
+
],
|
|
707
|
+
})
|
|
708
|
+
.then((x) => x.body);
|
|
709
|
+
|
|
710
|
+
assert(type, "type not created");
|
|
711
|
+
|
|
712
|
+
const response = await supertest(ctMock.app)
|
|
713
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
714
|
+
.send({
|
|
715
|
+
version: 1,
|
|
716
|
+
actions: [
|
|
717
|
+
{ action: "setShippingAddress", address },
|
|
718
|
+
{
|
|
719
|
+
action: "setShippingAddressCustomType",
|
|
720
|
+
type: {
|
|
721
|
+
typeId: "type",
|
|
722
|
+
type: "my-type",
|
|
723
|
+
key: "my-type",
|
|
724
|
+
},
|
|
725
|
+
fields: {
|
|
726
|
+
foo: "bar",
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
],
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
expect(response.status).toBe(200);
|
|
733
|
+
expect(response.body.version).toBe(3);
|
|
734
|
+
expect(response.body.shippingAddress).toEqual({
|
|
735
|
+
...address,
|
|
736
|
+
custom: {
|
|
737
|
+
type: { typeId: "type", id: type.id },
|
|
738
|
+
fields: { foo: "bar" },
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
});
|
|
608
742
|
test("setLineItemShippingDetails", async () => {
|
|
609
743
|
const product = await supertest(ctMock.app)
|
|
610
744
|
.post(`/dummy/products`)
|
|
@@ -371,6 +371,22 @@ describe("Order Update Actions", () => {
|
|
|
371
371
|
expect(response.body.orderNumber).toBe("5000123");
|
|
372
372
|
});
|
|
373
373
|
|
|
374
|
+
test("setPurchaseOrderNumber", async () => {
|
|
375
|
+
assert(order, "order not created");
|
|
376
|
+
|
|
377
|
+
const response = await supertest(ctMock.app)
|
|
378
|
+
.post(`/dummy/orders/${order.id}`)
|
|
379
|
+
.send({
|
|
380
|
+
version: 1,
|
|
381
|
+
actions: [
|
|
382
|
+
{ action: "setPurchaseOrderNumber", purchaseOrderNumber: "abc123" },
|
|
383
|
+
],
|
|
384
|
+
});
|
|
385
|
+
expect(response.status).toBe(200);
|
|
386
|
+
expect(response.body.version).toBe(2);
|
|
387
|
+
expect(response.body.purchaseOrderNumber).toBe("abc123");
|
|
388
|
+
});
|
|
389
|
+
|
|
374
390
|
test("changeOrderState", async () => {
|
|
375
391
|
assert(order, "order not created");
|
|
376
392
|
|