@labdigital/commercetools-mock 2.55.0 → 2.56.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.js +177 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.test.ts +13 -37
- package/src/lib/predicateParser.ts +12 -1
- package/src/repositories/cart/actions.ts +178 -0
- package/src/repositories/cart/helpers.ts +175 -3
- package/src/repositories/cart/index.test.ts +89 -2
- package/src/repositories/cart/index.ts +18 -2
- package/src/services/cart.test.ts +287 -2
|
@@ -111,10 +111,12 @@ describe("Carts Query", () => {
|
|
|
111
111
|
describe("Cart Update Actions", () => {
|
|
112
112
|
const ctMock = new CommercetoolsMock();
|
|
113
113
|
let cart: Cart | undefined;
|
|
114
|
+
let taxCategory: TaxCategory;
|
|
114
115
|
|
|
115
116
|
const createCart = async (currency: string) => {
|
|
116
117
|
const response = await supertest(ctMock.app).post("/dummy/carts").send({
|
|
117
118
|
currency,
|
|
119
|
+
country: "NL",
|
|
118
120
|
});
|
|
119
121
|
expect(response.status).toBe(201);
|
|
120
122
|
cart = response.body;
|
|
@@ -220,6 +222,18 @@ describe("Cart Update Actions", () => {
|
|
|
220
222
|
|
|
221
223
|
beforeEach(async () => {
|
|
222
224
|
await createCart("EUR");
|
|
225
|
+
taxCategory = await createTaxCategory({
|
|
226
|
+
name: "Standard VAT",
|
|
227
|
+
key: "standard-vat",
|
|
228
|
+
rates: [
|
|
229
|
+
{
|
|
230
|
+
name: "NL VAT",
|
|
231
|
+
amount: 0.21,
|
|
232
|
+
includedInPrice: false,
|
|
233
|
+
country: "NL",
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
223
237
|
});
|
|
224
238
|
|
|
225
239
|
afterEach(() => {
|
|
@@ -640,11 +654,11 @@ describe("Cart Update Actions", () => {
|
|
|
640
654
|
.post(`/dummy/carts/${cart.id}`)
|
|
641
655
|
.send({
|
|
642
656
|
version: 1,
|
|
643
|
-
actions: [{ action: "setCountry", country: "
|
|
657
|
+
actions: [{ action: "setCountry", country: "BE" }],
|
|
644
658
|
});
|
|
645
659
|
expect(response.status).toBe(200);
|
|
646
660
|
expect(response.body.version).toBe(2);
|
|
647
|
-
expect(response.body.country).toBe("
|
|
661
|
+
expect(response.body.country).toBe("BE");
|
|
648
662
|
});
|
|
649
663
|
|
|
650
664
|
test("setDirectDiscounts", async () => {
|
|
@@ -1327,4 +1341,275 @@ describe("Cart Update Actions", () => {
|
|
|
1327
1341
|
expect(updatedLineItem.shippingDetails).toBeDefined();
|
|
1328
1342
|
expect(updatedLineItem.shippingDetails.targets).toHaveLength(1);
|
|
1329
1343
|
});
|
|
1344
|
+
|
|
1345
|
+
test("addCustomLineItem", async () => {
|
|
1346
|
+
assert(cart, "cart not created");
|
|
1347
|
+
const type = await supertest(ctMock.app)
|
|
1348
|
+
.post("/dummy/types")
|
|
1349
|
+
.send({
|
|
1350
|
+
key: "custom-line-item-type",
|
|
1351
|
+
name: { en: "Custom Line Item Type" },
|
|
1352
|
+
resourceTypeIds: ["custom-line-item"],
|
|
1353
|
+
fieldDefinitions: [
|
|
1354
|
+
{
|
|
1355
|
+
name: "description",
|
|
1356
|
+
label: { en: "Description" },
|
|
1357
|
+
required: false,
|
|
1358
|
+
type: { name: "String" },
|
|
1359
|
+
inputHint: "SingleLine",
|
|
1360
|
+
},
|
|
1361
|
+
],
|
|
1362
|
+
})
|
|
1363
|
+
.then((res) => res.body);
|
|
1364
|
+
|
|
1365
|
+
const response = await supertest(ctMock.app)
|
|
1366
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1367
|
+
.send({
|
|
1368
|
+
version: 1,
|
|
1369
|
+
actions: [
|
|
1370
|
+
{
|
|
1371
|
+
action: "addCustomLineItem",
|
|
1372
|
+
name: { en: "Custom Service Fee" },
|
|
1373
|
+
slug: "service-fee",
|
|
1374
|
+
money: {
|
|
1375
|
+
currencyCode: "EUR",
|
|
1376
|
+
centAmount: 1000,
|
|
1377
|
+
},
|
|
1378
|
+
quantity: 1,
|
|
1379
|
+
taxCategory: {
|
|
1380
|
+
typeId: "tax-category",
|
|
1381
|
+
id: taxCategory.id,
|
|
1382
|
+
},
|
|
1383
|
+
custom: {
|
|
1384
|
+
type: { typeId: "type", key: type.key },
|
|
1385
|
+
fields: { description: "Premium support service" },
|
|
1386
|
+
},
|
|
1387
|
+
},
|
|
1388
|
+
],
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
expect(response.status).toBe(200);
|
|
1392
|
+
expect(response.body.version).toBe(2);
|
|
1393
|
+
expect(response.body.customLineItems).toHaveLength(1);
|
|
1394
|
+
|
|
1395
|
+
const customLineItem = response.body.customLineItems[0];
|
|
1396
|
+
expect(customLineItem.name).toEqual({ en: "Custom Service Fee" });
|
|
1397
|
+
expect(customLineItem.slug).toBe("service-fee");
|
|
1398
|
+
expect(customLineItem.money.centAmount).toBe(1000);
|
|
1399
|
+
expect(customLineItem.quantity).toBe(1);
|
|
1400
|
+
expect(customLineItem.totalPrice.centAmount).toBe(1000);
|
|
1401
|
+
expect(customLineItem.taxCategory.id).toBe(taxCategory.id);
|
|
1402
|
+
expect(customLineItem.taxedPrice).toBeDefined();
|
|
1403
|
+
expect(customLineItem.taxRate).toBeDefined();
|
|
1404
|
+
expect(customLineItem.taxRate.amount).toBe(0.21);
|
|
1405
|
+
expect(customLineItem.id).toBeDefined();
|
|
1406
|
+
expect(customLineItem.custom).toBeDefined();
|
|
1407
|
+
expect(customLineItem.custom.fields.description).toBe(
|
|
1408
|
+
"Premium support service",
|
|
1409
|
+
);
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
test("removeCustomLineItem by ID", async () => {
|
|
1413
|
+
assert(cart, "cart not created");
|
|
1414
|
+
|
|
1415
|
+
const addResponse = await supertest(ctMock.app)
|
|
1416
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1417
|
+
.send({
|
|
1418
|
+
version: 1,
|
|
1419
|
+
actions: [
|
|
1420
|
+
{
|
|
1421
|
+
action: "addCustomLineItem",
|
|
1422
|
+
name: { en: "Service Fee" },
|
|
1423
|
+
slug: "service-fee",
|
|
1424
|
+
money: {
|
|
1425
|
+
currencyCode: "EUR",
|
|
1426
|
+
centAmount: 1000,
|
|
1427
|
+
},
|
|
1428
|
+
quantity: 1,
|
|
1429
|
+
},
|
|
1430
|
+
],
|
|
1431
|
+
});
|
|
1432
|
+
|
|
1433
|
+
expect(addResponse.status).toBe(200);
|
|
1434
|
+
expect(addResponse.body.customLineItems).toHaveLength(1);
|
|
1435
|
+
|
|
1436
|
+
const customLineItemId = addResponse.body.customLineItems[0].id;
|
|
1437
|
+
const removeResponse = await supertest(ctMock.app)
|
|
1438
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1439
|
+
.send({
|
|
1440
|
+
version: addResponse.body.version,
|
|
1441
|
+
actions: [
|
|
1442
|
+
{
|
|
1443
|
+
action: "removeCustomLineItem",
|
|
1444
|
+
customLineItemId,
|
|
1445
|
+
},
|
|
1446
|
+
],
|
|
1447
|
+
});
|
|
1448
|
+
|
|
1449
|
+
expect(removeResponse.status).toBe(200);
|
|
1450
|
+
expect(removeResponse.body.customLineItems).toHaveLength(0);
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
test("removeCustomLineItem by key", async () => {
|
|
1454
|
+
assert(cart, "cart not created");
|
|
1455
|
+
|
|
1456
|
+
const addResponse = await supertest(ctMock.app)
|
|
1457
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1458
|
+
.send({
|
|
1459
|
+
version: 1,
|
|
1460
|
+
actions: [
|
|
1461
|
+
{
|
|
1462
|
+
action: "addCustomLineItem",
|
|
1463
|
+
name: { en: "Service Fee" },
|
|
1464
|
+
slug: "service-fee",
|
|
1465
|
+
key: "custom-service-fee",
|
|
1466
|
+
money: {
|
|
1467
|
+
currencyCode: "EUR",
|
|
1468
|
+
centAmount: 1000,
|
|
1469
|
+
},
|
|
1470
|
+
quantity: 1,
|
|
1471
|
+
},
|
|
1472
|
+
],
|
|
1473
|
+
});
|
|
1474
|
+
|
|
1475
|
+
expect(addResponse.status).toBe(200);
|
|
1476
|
+
expect(addResponse.body.customLineItems).toHaveLength(1);
|
|
1477
|
+
|
|
1478
|
+
const removeResponse = await supertest(ctMock.app)
|
|
1479
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1480
|
+
.send({
|
|
1481
|
+
version: addResponse.body.version,
|
|
1482
|
+
actions: [
|
|
1483
|
+
{
|
|
1484
|
+
action: "removeCustomLineItem",
|
|
1485
|
+
customLineItemKey: "custom-service-fee",
|
|
1486
|
+
},
|
|
1487
|
+
],
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
expect(removeResponse.status).toBe(200);
|
|
1491
|
+
expect(removeResponse.body.customLineItems).toHaveLength(0);
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1494
|
+
test("changeCustomLineItemQuantity", async () => {
|
|
1495
|
+
assert(cart, "cart not created");
|
|
1496
|
+
const addResponse = await supertest(ctMock.app)
|
|
1497
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1498
|
+
.send({
|
|
1499
|
+
version: 1,
|
|
1500
|
+
actions: [
|
|
1501
|
+
{
|
|
1502
|
+
action: "addCustomLineItem",
|
|
1503
|
+
name: { en: "Service Fee" },
|
|
1504
|
+
slug: "service-fee",
|
|
1505
|
+
money: {
|
|
1506
|
+
currencyCode: "EUR",
|
|
1507
|
+
centAmount: 1000,
|
|
1508
|
+
},
|
|
1509
|
+
quantity: 1,
|
|
1510
|
+
},
|
|
1511
|
+
],
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
const customLineItemId = addResponse.body.customLineItems[0].id;
|
|
1515
|
+
const changeResponse = await supertest(ctMock.app)
|
|
1516
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1517
|
+
.send({
|
|
1518
|
+
version: addResponse.body.version,
|
|
1519
|
+
actions: [
|
|
1520
|
+
{
|
|
1521
|
+
action: "changeCustomLineItemQuantity",
|
|
1522
|
+
customLineItemId,
|
|
1523
|
+
quantity: 3,
|
|
1524
|
+
},
|
|
1525
|
+
],
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
expect(changeResponse.status).toBe(200);
|
|
1529
|
+
expect(changeResponse.body.customLineItems).toHaveLength(1);
|
|
1530
|
+
|
|
1531
|
+
const customLineItem = changeResponse.body.customLineItems[0];
|
|
1532
|
+
expect(customLineItem.quantity).toBe(3);
|
|
1533
|
+
expect(customLineItem.totalPrice.centAmount).toBe(3000);
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
test("changeCustomLineItemMoney", async () => {
|
|
1537
|
+
assert(cart, "cart not created");
|
|
1538
|
+
const addResponse = await supertest(ctMock.app)
|
|
1539
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1540
|
+
.send({
|
|
1541
|
+
version: 1,
|
|
1542
|
+
actions: [
|
|
1543
|
+
{
|
|
1544
|
+
action: "addCustomLineItem",
|
|
1545
|
+
name: { en: "Service Fee" },
|
|
1546
|
+
slug: "service-fee",
|
|
1547
|
+
money: {
|
|
1548
|
+
currencyCode: "EUR",
|
|
1549
|
+
centAmount: 1000,
|
|
1550
|
+
},
|
|
1551
|
+
quantity: 2,
|
|
1552
|
+
},
|
|
1553
|
+
],
|
|
1554
|
+
});
|
|
1555
|
+
|
|
1556
|
+
const customLineItemId = addResponse.body.customLineItems[0].id;
|
|
1557
|
+
const changeResponse = await supertest(ctMock.app)
|
|
1558
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1559
|
+
.send({
|
|
1560
|
+
version: addResponse.body.version,
|
|
1561
|
+
actions: [
|
|
1562
|
+
{
|
|
1563
|
+
action: "changeCustomLineItemMoney",
|
|
1564
|
+
customLineItemId,
|
|
1565
|
+
money: {
|
|
1566
|
+
currencyCode: "EUR",
|
|
1567
|
+
centAmount: 1500,
|
|
1568
|
+
},
|
|
1569
|
+
},
|
|
1570
|
+
],
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
expect(changeResponse.status).toBe(200);
|
|
1574
|
+
expect(changeResponse.body.customLineItems).toHaveLength(1);
|
|
1575
|
+
|
|
1576
|
+
const customLineItem = changeResponse.body.customLineItems[0];
|
|
1577
|
+
expect(customLineItem.money.centAmount).toBe(1500);
|
|
1578
|
+
expect(customLineItem.totalPrice.centAmount).toBe(3000);
|
|
1579
|
+
});
|
|
1580
|
+
|
|
1581
|
+
test("addCustomLineItem with tax calculation", async () => {
|
|
1582
|
+
assert(cart, "cart not created");
|
|
1583
|
+
|
|
1584
|
+
const response = await supertest(ctMock.app)
|
|
1585
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
1586
|
+
.send({
|
|
1587
|
+
version: 1,
|
|
1588
|
+
actions: [
|
|
1589
|
+
{
|
|
1590
|
+
action: "addCustomLineItem",
|
|
1591
|
+
name: { en: "Taxed Service" },
|
|
1592
|
+
slug: "taxed-service",
|
|
1593
|
+
money: {
|
|
1594
|
+
currencyCode: "EUR",
|
|
1595
|
+
centAmount: 1000,
|
|
1596
|
+
},
|
|
1597
|
+
quantity: 1,
|
|
1598
|
+
taxCategory: {
|
|
1599
|
+
typeId: "tax-category",
|
|
1600
|
+
id: taxCategory.id,
|
|
1601
|
+
},
|
|
1602
|
+
},
|
|
1603
|
+
],
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
expect(response.status).toBe(200);
|
|
1607
|
+
const customLineItem = response.body.customLineItems[0];
|
|
1608
|
+
|
|
1609
|
+
expect(customLineItem.taxedPrice).toBeDefined();
|
|
1610
|
+
expect(customLineItem.taxedPrice.totalNet.centAmount).toBe(1000);
|
|
1611
|
+
expect(customLineItem.taxedPrice.totalGross.centAmount).toBe(1210);
|
|
1612
|
+
expect(customLineItem.taxedPrice.taxPortions).toHaveLength(1);
|
|
1613
|
+
expect(customLineItem.taxedPrice.taxPortions[0].rate).toBe(0.21);
|
|
1614
|
+
});
|
|
1330
1615
|
});
|