@labdigital/commercetools-mock 2.28.0 → 2.28.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 +21 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/order/actions.ts +22 -0
- package/src/services/order.test.ts +161 -0
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
OrderSetCustomTypeAction,
|
|
12
12
|
OrderSetCustomerEmailAction,
|
|
13
13
|
OrderSetCustomerIdAction,
|
|
14
|
+
OrderSetDeliveryCustomFieldAction,
|
|
14
15
|
OrderSetLocaleAction,
|
|
15
16
|
OrderSetOrderNumberAction,
|
|
16
17
|
OrderSetShippingAddressAction,
|
|
@@ -23,6 +24,7 @@ import type {
|
|
|
23
24
|
Store,
|
|
24
25
|
SyncInfo,
|
|
25
26
|
} from "@commercetools/platform-sdk";
|
|
27
|
+
import assert from "assert";
|
|
26
28
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
27
29
|
import type { Writable } from "~src/types";
|
|
28
30
|
import {
|
|
@@ -180,6 +182,26 @@ export class OrderUpdateHandler
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
|
|
185
|
+
setDeliveryCustomField(
|
|
186
|
+
context: RepositoryContext,
|
|
187
|
+
resource: Writable<Order>,
|
|
188
|
+
{ deliveryId, name, value }: OrderSetDeliveryCustomFieldAction,
|
|
189
|
+
) {
|
|
190
|
+
assert(resource.shippingInfo, "shippingInfo is not defined");
|
|
191
|
+
|
|
192
|
+
if (Array.isArray(resource.shippingInfo.deliveries)) {
|
|
193
|
+
resource.shippingInfo.deliveries.map((delivery) => {
|
|
194
|
+
if (delivery.id !== deliveryId) throw "No matching delivery id found";
|
|
195
|
+
if (delivery.custom) {
|
|
196
|
+
const update = delivery.custom.fields;
|
|
197
|
+
update[name] = value;
|
|
198
|
+
Object.assign(delivery.custom.fields, update);
|
|
199
|
+
}
|
|
200
|
+
return delivery;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
183
205
|
setLocale(
|
|
184
206
|
context: RepositoryContext,
|
|
185
207
|
resource: Writable<Order>,
|
|
@@ -2,6 +2,7 @@ import type { Order, Payment, State } from "@commercetools/platform-sdk";
|
|
|
2
2
|
import assert from "assert";
|
|
3
3
|
import supertest from "supertest";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
5
|
+
import { generateRandomString } from "~src/helpers";
|
|
5
6
|
import { CommercetoolsMock, getBaseResourceProperties } from "../index";
|
|
6
7
|
|
|
7
8
|
describe("Order Query", () => {
|
|
@@ -402,6 +403,166 @@ describe("Order Update Actions", () => {
|
|
|
402
403
|
expect(response.body.paymentState).toBe("Failed");
|
|
403
404
|
});
|
|
404
405
|
|
|
406
|
+
test("setDeliveryCustomField", async () => {
|
|
407
|
+
const order: Order = {
|
|
408
|
+
...getBaseResourceProperties(),
|
|
409
|
+
customLineItems: [],
|
|
410
|
+
lastMessageSequenceNumber: 0,
|
|
411
|
+
lineItems: [],
|
|
412
|
+
orderNumber: "1389",
|
|
413
|
+
orderState: "Open",
|
|
414
|
+
origin: "Customer",
|
|
415
|
+
paymentInfo: {
|
|
416
|
+
payments: [
|
|
417
|
+
{
|
|
418
|
+
typeId: "payment",
|
|
419
|
+
id: generateRandomString(10),
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
},
|
|
423
|
+
refusedGifts: [],
|
|
424
|
+
shippingInfo: {
|
|
425
|
+
shippingMethodName: "Home delivery (package)",
|
|
426
|
+
price: {
|
|
427
|
+
type: "centPrecision",
|
|
428
|
+
currencyCode: "EUR",
|
|
429
|
+
centAmount: 999,
|
|
430
|
+
fractionDigits: 2,
|
|
431
|
+
},
|
|
432
|
+
shippingRate: {
|
|
433
|
+
price: {
|
|
434
|
+
type: "centPrecision",
|
|
435
|
+
currencyCode: "EUR",
|
|
436
|
+
centAmount: 999,
|
|
437
|
+
fractionDigits: 2,
|
|
438
|
+
},
|
|
439
|
+
tiers: [
|
|
440
|
+
{
|
|
441
|
+
type: "CartScore",
|
|
442
|
+
score: 24,
|
|
443
|
+
price: {
|
|
444
|
+
type: "centPrecision",
|
|
445
|
+
currencyCode: "EUR",
|
|
446
|
+
centAmount: 1998,
|
|
447
|
+
fractionDigits: 2,
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
type: "CartScore",
|
|
452
|
+
score: 47,
|
|
453
|
+
price: {
|
|
454
|
+
type: "centPrecision",
|
|
455
|
+
currencyCode: "EUR",
|
|
456
|
+
centAmount: 2997,
|
|
457
|
+
fractionDigits: 2,
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
type: "CartScore",
|
|
462
|
+
score: 70,
|
|
463
|
+
price: {
|
|
464
|
+
type: "centPrecision",
|
|
465
|
+
currencyCode: "EUR",
|
|
466
|
+
centAmount: 3996,
|
|
467
|
+
fractionDigits: 2,
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
type: "CartScore",
|
|
472
|
+
score: 93,
|
|
473
|
+
price: {
|
|
474
|
+
type: "centPrecision",
|
|
475
|
+
currencyCode: "EUR",
|
|
476
|
+
centAmount: 4995,
|
|
477
|
+
fractionDigits: 2,
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
},
|
|
482
|
+
deliveries: [
|
|
483
|
+
{
|
|
484
|
+
id: "6a458cad-dd46-4f5f-8b73-debOede6a17d",
|
|
485
|
+
key: "CT-Z243002",
|
|
486
|
+
createdAt: "2024-07-29T13:37:48.047Z",
|
|
487
|
+
items: [
|
|
488
|
+
{
|
|
489
|
+
id: "5d209544-2892-45c9-bef0-dde4e250188e",
|
|
490
|
+
quantity: 1,
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
parcels: [],
|
|
494
|
+
custom: {
|
|
495
|
+
type: {
|
|
496
|
+
typeId: "type",
|
|
497
|
+
id: "c493b7bb-d415-450c-b421-e128a8b26569",
|
|
498
|
+
},
|
|
499
|
+
fields: {
|
|
500
|
+
location: "test",
|
|
501
|
+
status: "created",
|
|
502
|
+
carrier: "test_carrier",
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
shippingMethodState: "MatchesCart",
|
|
508
|
+
},
|
|
509
|
+
shipping: [],
|
|
510
|
+
shippingMode: "Single",
|
|
511
|
+
syncInfo: [],
|
|
512
|
+
totalPrice: {
|
|
513
|
+
type: "centPrecision",
|
|
514
|
+
fractionDigits: 2,
|
|
515
|
+
centAmount: 2000,
|
|
516
|
+
currencyCode: "EUR",
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
ctMock.project("dummy").add("order", order);
|
|
520
|
+
|
|
521
|
+
const response = await supertest(ctMock.app).get(
|
|
522
|
+
`/dummy/orders/order-number=${order.orderNumber}`,
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
// check if status is set
|
|
526
|
+
const _updateResponse = await supertest(ctMock.app)
|
|
527
|
+
.post(`/dummy/orders/${response.body.id}`)
|
|
528
|
+
.send({
|
|
529
|
+
version: 0,
|
|
530
|
+
actions: [
|
|
531
|
+
{
|
|
532
|
+
action: "setDeliveryCustomField",
|
|
533
|
+
deliveryId: "6a458cad-dd46-4f5f-8b73-debOede6a17d",
|
|
534
|
+
name: "status",
|
|
535
|
+
value: "delayed",
|
|
536
|
+
},
|
|
537
|
+
],
|
|
538
|
+
});
|
|
539
|
+
expect(_updateResponse.status).toBe(200);
|
|
540
|
+
expect(_updateResponse.body.version).toBe(1);
|
|
541
|
+
expect(
|
|
542
|
+
_updateResponse.body.shippingInfo.deliveries[0].custom.fields.status,
|
|
543
|
+
).toBe("delayed");
|
|
544
|
+
|
|
545
|
+
// check if other field can be set
|
|
546
|
+
const _updateResponse2 = await supertest(ctMock.app)
|
|
547
|
+
.post(`/dummy/orders/${response.body.id}`)
|
|
548
|
+
.send({
|
|
549
|
+
version: 1,
|
|
550
|
+
actions: [
|
|
551
|
+
{
|
|
552
|
+
action: "setDeliveryCustomField",
|
|
553
|
+
deliveryId: "6a458cad-dd46-4f5f-8b73-debOede6a17d",
|
|
554
|
+
name: "carrier",
|
|
555
|
+
value: "dhl",
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
});
|
|
559
|
+
expect(_updateResponse2.status).toBe(200);
|
|
560
|
+
expect(_updateResponse2.body.version).toBe(2);
|
|
561
|
+
expect(
|
|
562
|
+
_updateResponse2.body.shippingInfo.deliveries[0].custom.fields.carrier,
|
|
563
|
+
).toBe("dhl");
|
|
564
|
+
});
|
|
565
|
+
|
|
405
566
|
test("updateSyncInfo", async () => {
|
|
406
567
|
assert(order, "order not created");
|
|
407
568
|
|