@darkpos/pricing 1.0.111 → 1.0.112
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.
|
@@ -1626,12 +1626,48 @@ describe('Conditions not met for the item', () => {
|
|
|
1626
1626
|
});
|
|
1627
1627
|
|
|
1628
1628
|
test('Total number of items conditions is met, using between', () => {
|
|
1629
|
-
const item1 = {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1629
|
+
const item1 = {
|
|
1630
|
+
pieces: 1,
|
|
1631
|
+
itemId: '1',
|
|
1632
|
+
price: 100,
|
|
1633
|
+
modifiers: [],
|
|
1634
|
+
quantity: 1,
|
|
1635
|
+
};
|
|
1636
|
+
const item2 = {
|
|
1637
|
+
pieces: 1,
|
|
1638
|
+
itemId: '2',
|
|
1639
|
+
price: 100,
|
|
1640
|
+
modifiers: [],
|
|
1641
|
+
quantity: 1,
|
|
1642
|
+
};
|
|
1643
|
+
const item3 = {
|
|
1644
|
+
pieces: 1,
|
|
1645
|
+
itemId: '3',
|
|
1646
|
+
price: 100,
|
|
1647
|
+
modifiers: [],
|
|
1648
|
+
quantity: 1,
|
|
1649
|
+
};
|
|
1650
|
+
const item4 = {
|
|
1651
|
+
pieces: 1,
|
|
1652
|
+
itemId: '4',
|
|
1653
|
+
price: 100,
|
|
1654
|
+
modifiers: [],
|
|
1655
|
+
quantity: 1,
|
|
1656
|
+
};
|
|
1657
|
+
const item5 = {
|
|
1658
|
+
pieces: 1,
|
|
1659
|
+
itemId: '5',
|
|
1660
|
+
price: 100,
|
|
1661
|
+
modifiers: [],
|
|
1662
|
+
quantity: 1,
|
|
1663
|
+
};
|
|
1664
|
+
const item6 = {
|
|
1665
|
+
pieces: 1,
|
|
1666
|
+
itemId: '6',
|
|
1667
|
+
price: 100,
|
|
1668
|
+
modifiers: [],
|
|
1669
|
+
quantity: 1,
|
|
1670
|
+
};
|
|
1635
1671
|
|
|
1636
1672
|
const order = {
|
|
1637
1673
|
id: 'ord-123',
|
|
@@ -1667,10 +1703,34 @@ describe('Conditions not met for the item', () => {
|
|
|
1667
1703
|
});
|
|
1668
1704
|
|
|
1669
1705
|
test('Total number of items conditions is not met, using between', () => {
|
|
1670
|
-
const item1 = {
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1706
|
+
const item1 = {
|
|
1707
|
+
pieces: 1,
|
|
1708
|
+
itemId: '1',
|
|
1709
|
+
price: 100,
|
|
1710
|
+
modifiers: [],
|
|
1711
|
+
quantity: 1,
|
|
1712
|
+
};
|
|
1713
|
+
const item2 = {
|
|
1714
|
+
pieces: 1,
|
|
1715
|
+
itemId: '2',
|
|
1716
|
+
price: 100,
|
|
1717
|
+
modifiers: [],
|
|
1718
|
+
quantity: 1,
|
|
1719
|
+
};
|
|
1720
|
+
const item3 = {
|
|
1721
|
+
pieces: 1,
|
|
1722
|
+
itemId: '3',
|
|
1723
|
+
price: 100,
|
|
1724
|
+
modifiers: [],
|
|
1725
|
+
quantity: 1,
|
|
1726
|
+
};
|
|
1727
|
+
const item4 = {
|
|
1728
|
+
pieces: 1,
|
|
1729
|
+
itemId: '4',
|
|
1730
|
+
price: 100,
|
|
1731
|
+
modifiers: [],
|
|
1732
|
+
quantity: 1,
|
|
1733
|
+
};
|
|
1674
1734
|
|
|
1675
1735
|
const order = {
|
|
1676
1736
|
id: 'ord-123',
|
|
@@ -1706,10 +1766,34 @@ describe('Conditions not met for the item', () => {
|
|
|
1706
1766
|
});
|
|
1707
1767
|
|
|
1708
1768
|
test('Total number of items conditions is met, using gt', () => {
|
|
1709
|
-
const item1 = {
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1769
|
+
const item1 = {
|
|
1770
|
+
pieces: 1,
|
|
1771
|
+
itemId: '1',
|
|
1772
|
+
price: 100,
|
|
1773
|
+
modifiers: [],
|
|
1774
|
+
quantity: 1,
|
|
1775
|
+
};
|
|
1776
|
+
const item2 = {
|
|
1777
|
+
pieces: 1,
|
|
1778
|
+
itemId: '2',
|
|
1779
|
+
price: 100,
|
|
1780
|
+
modifiers: [],
|
|
1781
|
+
quantity: 1,
|
|
1782
|
+
};
|
|
1783
|
+
const item3 = {
|
|
1784
|
+
pieces: 1,
|
|
1785
|
+
itemId: '3',
|
|
1786
|
+
price: 100,
|
|
1787
|
+
modifiers: [],
|
|
1788
|
+
quantity: 1,
|
|
1789
|
+
};
|
|
1790
|
+
const item4 = {
|
|
1791
|
+
pieces: 1,
|
|
1792
|
+
itemId: '4',
|
|
1793
|
+
price: 100,
|
|
1794
|
+
modifiers: [],
|
|
1795
|
+
quantity: 1,
|
|
1796
|
+
};
|
|
1713
1797
|
|
|
1714
1798
|
const order = {
|
|
1715
1799
|
id: 'ord-123',
|
|
@@ -1742,10 +1826,34 @@ describe('Conditions not met for the item', () => {
|
|
|
1742
1826
|
});
|
|
1743
1827
|
|
|
1744
1828
|
test('Total number of items conditions is not met, using gt', () => {
|
|
1745
|
-
const item1 = {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1829
|
+
const item1 = {
|
|
1830
|
+
pieces: 1,
|
|
1831
|
+
itemId: '1',
|
|
1832
|
+
price: 100,
|
|
1833
|
+
modifiers: [],
|
|
1834
|
+
quantity: 1,
|
|
1835
|
+
};
|
|
1836
|
+
const item2 = {
|
|
1837
|
+
pieces: 1,
|
|
1838
|
+
itemId: '2',
|
|
1839
|
+
price: 100,
|
|
1840
|
+
modifiers: [],
|
|
1841
|
+
quantity: 1,
|
|
1842
|
+
};
|
|
1843
|
+
const item3 = {
|
|
1844
|
+
pieces: 1,
|
|
1845
|
+
itemId: '3',
|
|
1846
|
+
price: 100,
|
|
1847
|
+
modifiers: [],
|
|
1848
|
+
quantity: 1,
|
|
1849
|
+
};
|
|
1850
|
+
const item4 = {
|
|
1851
|
+
pieces: 1,
|
|
1852
|
+
itemId: '4',
|
|
1853
|
+
price: 100,
|
|
1854
|
+
modifiers: [],
|
|
1855
|
+
quantity: 1,
|
|
1856
|
+
};
|
|
1749
1857
|
|
|
1750
1858
|
const order = {
|
|
1751
1859
|
id: 'ord-123',
|
|
@@ -1776,4 +1884,54 @@ describe('Conditions not met for the item', () => {
|
|
|
1776
1884
|
false
|
|
1777
1885
|
);
|
|
1778
1886
|
});
|
|
1887
|
+
|
|
1888
|
+
test('Total number of items conditions is met with 2 items with each one having qty 3, using between', () => {
|
|
1889
|
+
const item1 = {
|
|
1890
|
+
pieces: 1,
|
|
1891
|
+
itemId: '1',
|
|
1892
|
+
price: 100,
|
|
1893
|
+
modifiers: [],
|
|
1894
|
+
quantity: 3,
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1897
|
+
const item2 = {
|
|
1898
|
+
pieces: 1,
|
|
1899
|
+
itemId: '1',
|
|
1900
|
+
price: 100,
|
|
1901
|
+
modifiers: [],
|
|
1902
|
+
quantity: 3,
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
const order = {
|
|
1906
|
+
id: 'ord-123',
|
|
1907
|
+
items: [item1, item2],
|
|
1908
|
+
modifiers: [],
|
|
1909
|
+
};
|
|
1910
|
+
const modifier = {
|
|
1911
|
+
conditions: {
|
|
1912
|
+
rules: [
|
|
1913
|
+
{
|
|
1914
|
+
key: 'totalNumberOfItems',
|
|
1915
|
+
value: {
|
|
1916
|
+
from: 5,
|
|
1917
|
+
to: 10,
|
|
1918
|
+
},
|
|
1919
|
+
operand: '$between',
|
|
1920
|
+
},
|
|
1921
|
+
],
|
|
1922
|
+
},
|
|
1923
|
+
};
|
|
1924
|
+
const { addItemModifier } = pricingService.order;
|
|
1925
|
+
const calculatedOrder = pricingService.order.calculate(
|
|
1926
|
+
addItemModifier({
|
|
1927
|
+
order,
|
|
1928
|
+
modifier,
|
|
1929
|
+
itemIndex: 0,
|
|
1930
|
+
})
|
|
1931
|
+
);
|
|
1932
|
+
expect(calculatedOrder.items[0].modifiers.length).toEqual(1);
|
|
1933
|
+
expect(calculatedOrder.items[0].modifiers[0].conditions.valid).toEqual(
|
|
1934
|
+
true
|
|
1935
|
+
);
|
|
1936
|
+
});
|
|
1779
1937
|
});
|
|
@@ -10,6 +10,14 @@ module.exports = ({ actions, utils }) => {
|
|
|
10
10
|
return customer.stats[key];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
const getTotalItemsQuantity = ({ items }) => {
|
|
14
|
+
if (!items || !Array.isArray(items)) return 0;
|
|
15
|
+
return items.reduce(
|
|
16
|
+
(total, item) => utils.math.add(total, item.quantity || 0),
|
|
17
|
+
0
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
const modifierConditionPass = (
|
|
14
22
|
modifier,
|
|
15
23
|
{
|
|
@@ -28,7 +36,7 @@ module.exports = ({ actions, utils }) => {
|
|
|
28
36
|
switch (condition.key) {
|
|
29
37
|
case 'totalNumberOfItems':
|
|
30
38
|
return actions.validateNumberCondition({
|
|
31
|
-
value:
|
|
39
|
+
value: getTotalItemsQuantity({ items: allItems }),
|
|
32
40
|
condition,
|
|
33
41
|
});
|
|
34
42
|
case 'itemSet': {
|
|
@@ -57,10 +65,8 @@ module.exports = ({ actions, utils }) => {
|
|
|
57
65
|
}
|
|
58
66
|
});
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
matchingItems.forEach(matchItem => {
|
|
63
|
-
totalItemsLength += matchItem.quantity || 0;
|
|
68
|
+
const totalItemsLength = getTotalItemsQuantity({
|
|
69
|
+
items: matchingItems,
|
|
64
70
|
});
|
|
65
71
|
|
|
66
72
|
const itemIndex = matchingItems.findIndex(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.112",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"supertest": "^6.2.3",
|
|
56
56
|
"supervisor": "^0.12.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "ecde0ddb5fed6841e2ff1fa688120201557971cb"
|
|
59
59
|
}
|