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