@darkpos/pricing 1.0.43 → 1.0.45
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/__TEST__/item/getItemsModifierDescription.test.js +75 -78
- package/__TEST__/mocks/addItemMock.js +18729 -19357
- package/__TEST__/mocks/partially-paid/order-modifiers.json +48 -51
- package/__TEST__/mocks/partially-paid/order-partially-paid.json +893 -860
- package/__TEST__/mocks/scripts/calculate-partially-paid/index.js +2 -2
- package/__TEST__/mocks/scripts/calculate-unpaid/index.js +2 -2
- package/__TEST__/mocks/unpaid/order-modifiers.json +48 -52
- package/__TEST__/modifier/calculate.test.js +1 -0
- package/__TEST__/modifier/getMatchTagsModifiers.test.js +72 -18
- package/__TEST__/modifier/getModifierIndex.test.js +10 -7
- package/__TEST__/modifier/getRecommendedModifiers.test.js +6 -4
- package/__TEST__/modifier/hasAttribute.test.js +11 -5
- package/__TEST__/modifier/hasMatchTags.test.js +33 -11
- package/__TEST__/modifier/sort.test.js +1 -1
- package/__TEST__/order/conditionsNotMet.test.js +133 -0
- package/__TEST__/order/manualSplit.test.js +104 -0
- package/__TEST__/order/order-payment-modifier.test.js +1117 -0
- package/__TEST__/order/order.test.js +53 -105
- package/__TEST__/order/pickEndDate.test.js +7 -153
- package/__TEST__/order/validateConditionsCalculate.test.js +396 -0
- package/lib/constants/index.js +1 -1
- package/lib/index.js +11 -2
- package/lib/item/calculate.js +93 -18
- package/lib/item/getAmounts.js +14 -0
- package/lib/item/getBalance.js +0 -1
- package/lib/item/getItemModifiersDescription.js +1 -0
- package/lib/item/getItemsBalance.js +9 -0
- package/lib/item/getItemsTotals.js +27 -0
- package/lib/item/getTotal.js +3 -1
- package/lib/item/hasPaymentMethodType.js +17 -0
- package/lib/item/hasPaymentModifierWithPaymentId.js +9 -0
- package/lib/item/index.js +15 -8
- package/lib/item/removePaymentModifiersByPaymentId.js +13 -0
- package/lib/modifier/areConditionsMet.js +61 -0
- package/lib/modifier/calculatePaymentDiscountModifier.js +31 -0
- package/lib/modifier/calculatePaymentFeeModifier.js +27 -0
- package/lib/modifier/calculatePaymentModifier.js +67 -0
- package/lib/modifier/createDiscountModifier.js +2 -1
- package/lib/modifier/createFeeModifier.js +2 -1
- package/lib/modifier/getChildren.js +8 -0
- package/lib/modifier/getComputedAmount.js +9 -0
- package/lib/modifier/hasPaymentMethodType.js +14 -0
- package/lib/modifier/index.js +33 -9
- package/lib/modifier/isCalculatedPaymentModifier.js +4 -0
- package/lib/modifier/isChild.js +6 -0
- package/lib/modifier/isDiscount.js +6 -2
- package/lib/modifier/isFee.js +5 -2
- package/lib/modifier/isPaymentMethodModifier.js +4 -1
- package/lib/modifier/isPaymentTypeModifier.js +4 -1
- package/lib/modifier/isPercentage.js +10 -0
- package/lib/modifier/isValid.js +12 -0
- package/lib/modifier/sort.js +28 -0
- package/lib/modifier/validate.js +14 -0
- package/lib/modifier/validateDateDaysDiff.js +30 -0
- package/lib/modifier/validateInArr.js +12 -0
- package/lib/modifier/validateNumberCondition.js +20 -0
- package/lib/modifier/validateRequiredModifiers.js +16 -0
- package/lib/order/addItemModifier.js +72 -28
- package/lib/order/applyPayment.js +61 -0
- package/lib/order/calculate.js +45 -22
- package/lib/order/getBalance.js +0 -1
- package/lib/order/getOrdersBalance.js +8 -0
- package/lib/order/index.js +9 -10
- package/lib/order/manualSplit.js +34 -0
- package/lib/order/manualSplitByQuantity.js +50 -0
- package/lib/store/getRecommendedEndDate.js +13 -0
- package/lib/store/index.js +25 -0
- package/package.json +6 -4
- package/lib/item/getBalanceToPay.js +0 -12
- package/lib/item/getTotals.js +0 -40
- package/lib/item/markModifiersAsLocked.js +0 -11
- package/lib/modifier/createPaymentModifier.js +0 -12
- package/lib/modifier/findByPaymentMethod.js +0 -10
- package/lib/modifier/findByPaymentType.js +0 -10
- package/lib/modifier/getLockedModifiers.js +0 -5
- package/lib/order/markModifiersAsLocked.js +0 -14
- package/lib/order/removeModifiersWithPaymentMethods.js +0 -29
- package/lib/order/removeModifiersWithPaymentTypes.js +0 -27
- package/lib/{order → store}/pickEndDate.js +2 -2
|
@@ -119,13 +119,15 @@ describe('Order actions', () => {
|
|
|
119
119
|
|
|
120
120
|
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
121
121
|
|
|
122
|
-
const newOrder = pricingService.order.calculate(order
|
|
122
|
+
const newOrder = pricingService.order.calculate(order, {
|
|
123
|
+
paymentMethod: 'cash',
|
|
124
|
+
});
|
|
123
125
|
expect(newOrder).toHaveProperty('total', 68);
|
|
124
126
|
expect(newOrder).toHaveProperty('subTotal', 70);
|
|
125
127
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
126
128
|
discount: -2,
|
|
127
129
|
});
|
|
128
|
-
expect(newOrder.items[0]).toHaveProperty('total', 58.
|
|
130
|
+
expect(newOrder.items[0]).toHaveProperty('total', 58.29);
|
|
129
131
|
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
130
132
|
discount: -1.7142857142857142,
|
|
131
133
|
_included: 0,
|
|
@@ -135,7 +137,7 @@ describe('Order actions', () => {
|
|
|
135
137
|
_simple: 60,
|
|
136
138
|
_actual: 60,
|
|
137
139
|
});
|
|
138
|
-
expect(newOrder.items[1]).toHaveProperty('total', 9.
|
|
140
|
+
expect(newOrder.items[1]).toHaveProperty('total', 9.71);
|
|
139
141
|
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
140
142
|
discount: -0.2857142857142857,
|
|
141
143
|
_included: 0,
|
|
@@ -172,9 +174,9 @@ describe('Order actions', () => {
|
|
|
172
174
|
expect(newOrder).toHaveProperty('total', 18.58);
|
|
173
175
|
expect(newOrder).toHaveProperty('subTotal', 20.64);
|
|
174
176
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
175
|
-
discount: -2.
|
|
177
|
+
discount: -2.064,
|
|
176
178
|
});
|
|
177
|
-
expect(newOrder.items[0]).toHaveProperty('total', 14.
|
|
179
|
+
expect(newOrder.items[0]).toHaveProperty('total', 14.39);
|
|
178
180
|
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
179
181
|
discount: -1.599,
|
|
180
182
|
_included: 0,
|
|
@@ -184,7 +186,7 @@ describe('Order actions', () => {
|
|
|
184
186
|
_simple: 15.99,
|
|
185
187
|
_actual: 15.99,
|
|
186
188
|
});
|
|
187
|
-
expect(newOrder.items[1]).toHaveProperty('total', 4.
|
|
189
|
+
expect(newOrder.items[1]).toHaveProperty('total', 4.19);
|
|
188
190
|
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
189
191
|
discount: -0.465,
|
|
190
192
|
_included: 0,
|
|
@@ -681,11 +683,11 @@ describe('Order actions', () => {
|
|
|
681
683
|
expect(newOrder).toHaveProperty('subTotal', 109.4);
|
|
682
684
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
683
685
|
discount: -16.41,
|
|
684
|
-
tax: 7.
|
|
686
|
+
tax: 7.206725,
|
|
685
687
|
});
|
|
686
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
687
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
688
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
688
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.6);
|
|
689
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69);
|
|
690
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.91);
|
|
689
691
|
expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
|
|
690
692
|
'amount',
|
|
691
693
|
13.2
|
|
@@ -701,7 +703,7 @@ describe('Order actions', () => {
|
|
|
701
703
|
);
|
|
702
704
|
expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
|
|
703
705
|
'amount',
|
|
704
|
-
0.
|
|
706
|
+
0.985025
|
|
705
707
|
);
|
|
706
708
|
|
|
707
709
|
expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
|
|
@@ -710,7 +712,7 @@ describe('Order actions', () => {
|
|
|
710
712
|
);
|
|
711
713
|
expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
|
|
712
714
|
'amount',
|
|
713
|
-
0.
|
|
715
|
+
0.4247
|
|
714
716
|
);
|
|
715
717
|
});
|
|
716
718
|
|
|
@@ -773,11 +775,11 @@ describe('Order actions', () => {
|
|
|
773
775
|
expect(newOrder).toHaveProperty('subTotal', 109.4);
|
|
774
776
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
775
777
|
discount: -16.41,
|
|
776
|
-
tax: 7.
|
|
778
|
+
tax: 7.206725,
|
|
777
779
|
});
|
|
778
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
779
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
780
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
780
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.6);
|
|
781
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69);
|
|
782
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.91);
|
|
781
783
|
expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
|
|
782
784
|
'amount',
|
|
783
785
|
13.2
|
|
@@ -865,11 +867,11 @@ describe('Order actions', () => {
|
|
|
865
867
|
expect(newOrder).toHaveProperty('subTotal', 109.4);
|
|
866
868
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
867
869
|
discount: -16.41,
|
|
868
|
-
tax: 7.
|
|
870
|
+
tax: 7.206725,
|
|
869
871
|
});
|
|
870
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
871
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
872
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
872
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.6);
|
|
873
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69);
|
|
874
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.91);
|
|
873
875
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
874
876
|
'amount',
|
|
875
877
|
-13.2
|
|
@@ -957,11 +959,11 @@ describe('Order actions', () => {
|
|
|
957
959
|
expect(newOrder).toHaveProperty('subTotal', 109.4);
|
|
958
960
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
959
961
|
discount: -16.41,
|
|
960
|
-
tax: 7.
|
|
962
|
+
tax: 7.206725,
|
|
961
963
|
});
|
|
962
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
963
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
964
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
964
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.6);
|
|
965
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69);
|
|
966
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.91);
|
|
965
967
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
966
968
|
'amount',
|
|
967
969
|
-13.2
|
|
@@ -977,7 +979,7 @@ describe('Order actions', () => {
|
|
|
977
979
|
);
|
|
978
980
|
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
979
981
|
'amount',
|
|
980
|
-
0.
|
|
982
|
+
0.985025
|
|
981
983
|
);
|
|
982
984
|
|
|
983
985
|
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
@@ -986,7 +988,7 @@ describe('Order actions', () => {
|
|
|
986
988
|
);
|
|
987
989
|
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
988
990
|
'amount',
|
|
989
|
-
0.
|
|
991
|
+
0.4247
|
|
990
992
|
);
|
|
991
993
|
});
|
|
992
994
|
|
|
@@ -1138,18 +1140,18 @@ describe('Order actions', () => {
|
|
|
1138
1140
|
expect(newOrder).toHaveProperty('subTotal', 3);
|
|
1139
1141
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
1140
1142
|
fixed: -1,
|
|
1141
|
-
tax: 0.
|
|
1143
|
+
tax: 0.155775,
|
|
1142
1144
|
});
|
|
1143
|
-
expect(newOrder.items[0]).toHaveProperty('total', 0.
|
|
1144
|
-
expect(newOrder.items[1]).toHaveProperty('total', 0.
|
|
1145
|
-
expect(newOrder.items[2]).toHaveProperty('total', 0.
|
|
1145
|
+
expect(newOrder.items[0]).toHaveProperty('total', 0.72);
|
|
1146
|
+
expect(newOrder.items[1]).toHaveProperty('total', 0.72);
|
|
1147
|
+
expect(newOrder.items[2]).toHaveProperty('total', 0.72);
|
|
1146
1148
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
1147
1149
|
'amount',
|
|
1148
1150
|
-0.3333333333333334
|
|
1149
1151
|
);
|
|
1150
1152
|
expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
|
|
1151
1153
|
'amount',
|
|
1152
|
-
0.
|
|
1154
|
+
0.051925
|
|
1153
1155
|
);
|
|
1154
1156
|
|
|
1155
1157
|
expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
|
|
@@ -1158,7 +1160,7 @@ describe('Order actions', () => {
|
|
|
1158
1160
|
);
|
|
1159
1161
|
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
1160
1162
|
'amount',
|
|
1161
|
-
0.
|
|
1163
|
+
0.051925
|
|
1162
1164
|
);
|
|
1163
1165
|
|
|
1164
1166
|
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
@@ -1167,7 +1169,7 @@ describe('Order actions', () => {
|
|
|
1167
1169
|
);
|
|
1168
1170
|
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
1169
1171
|
'amount',
|
|
1170
|
-
0.
|
|
1172
|
+
0.051925
|
|
1171
1173
|
);
|
|
1172
1174
|
});
|
|
1173
1175
|
|
|
@@ -1262,19 +1264,19 @@ describe('Order actions', () => {
|
|
|
1262
1264
|
|
|
1263
1265
|
const [item1, item2, item3] = newOrder.items;
|
|
1264
1266
|
expect(newOrder).toHaveProperty('total', 12.5);
|
|
1265
|
-
expect(item1).toHaveProperty('total', 3.
|
|
1267
|
+
expect(item1).toHaveProperty('total', 3.66);
|
|
1266
1268
|
expect(item1.modifiers[1].compute).toHaveProperty(
|
|
1267
1269
|
'amount',
|
|
1268
1270
|
5.846153846153846
|
|
1269
1271
|
);
|
|
1270
1272
|
|
|
1271
|
-
expect(item2).toHaveProperty('total', 5.
|
|
1273
|
+
expect(item2).toHaveProperty('total', 5.38);
|
|
1272
1274
|
expect(item2.modifiers[1].compute).toHaveProperty(
|
|
1273
1275
|
'amount',
|
|
1274
1276
|
8.615384615384615
|
|
1275
1277
|
);
|
|
1276
1278
|
|
|
1277
|
-
expect(item3).toHaveProperty('total', 3.
|
|
1279
|
+
expect(item3).toHaveProperty('total', 3.46);
|
|
1278
1280
|
expect(item3.modifiers[1].compute).toHaveProperty(
|
|
1279
1281
|
'amount',
|
|
1280
1282
|
5.538461538461538
|
|
@@ -1589,62 +1591,6 @@ describe('Order actions', () => {
|
|
|
1589
1591
|
'M-L 2pc Suit',
|
|
1590
1592
|
]);
|
|
1591
1593
|
});
|
|
1592
|
-
test('Get calculated UNPAID Order, multiple items and paymentModifiers', () => {
|
|
1593
|
-
const paymentModifiers = orderModifiersNotPaid.map(orderMod =>
|
|
1594
|
-
pricingService.modifier.createPaymentModifier({
|
|
1595
|
-
modifier: orderMod,
|
|
1596
|
-
items: inputItemsNotPaidOrder,
|
|
1597
|
-
})
|
|
1598
|
-
);
|
|
1599
|
-
|
|
1600
|
-
let order = { ...orderNotPaid };
|
|
1601
|
-
|
|
1602
|
-
order = pricingService.order.addModifiers({
|
|
1603
|
-
modifiers: paymentModifiers,
|
|
1604
|
-
order,
|
|
1605
|
-
});
|
|
1606
|
-
|
|
1607
|
-
const newOrder = pricingService.order.calculate(order);
|
|
1608
|
-
|
|
1609
|
-
expect(newOrder).toHaveProperty('total', 34.45);
|
|
1610
|
-
expect(newOrder).toHaveProperty('subTotal', 42.45);
|
|
1611
|
-
expect(newOrder).toHaveProperty('subTotals', {
|
|
1612
|
-
discount: -10,
|
|
1613
|
-
fee: 2,
|
|
1614
|
-
});
|
|
1615
|
-
expect(newOrder.items[0]).toHaveProperty('total', 8.074852767962309);
|
|
1616
|
-
expect(newOrder.items[1]).toHaveProperty('total', 7.709658421672556);
|
|
1617
|
-
expect(newOrder.items[2]).toHaveProperty('total', 11.361601884570083);
|
|
1618
|
-
expect(newOrder.items[3]).toHaveProperty('total', 7.303886925795053);
|
|
1619
|
-
});
|
|
1620
|
-
test('Get calculated PARTIALLY PAID Order, multiple items and paymentModifiers', () => {
|
|
1621
|
-
const paymentModifiers = orderModifiersPartiallyPaid.map(orderMod =>
|
|
1622
|
-
pricingService.modifier.createPaymentModifier({
|
|
1623
|
-
modifier: orderMod,
|
|
1624
|
-
items: inputItemsPartiallyPaidOrder,
|
|
1625
|
-
})
|
|
1626
|
-
);
|
|
1627
|
-
|
|
1628
|
-
let order = { ...orderPartiallyPaid };
|
|
1629
|
-
|
|
1630
|
-
order = pricingService.order.addModifiers({
|
|
1631
|
-
modifiers: paymentModifiers,
|
|
1632
|
-
order,
|
|
1633
|
-
});
|
|
1634
|
-
|
|
1635
|
-
const newOrder = pricingService.order.calculate(order);
|
|
1636
|
-
|
|
1637
|
-
expect(newOrder).toHaveProperty('total', 36.45);
|
|
1638
|
-
expect(newOrder).toHaveProperty('subTotal', 42.45);
|
|
1639
|
-
expect(newOrder).toHaveProperty('subTotals', {
|
|
1640
|
-
discount: -10,
|
|
1641
|
-
fee: 4,
|
|
1642
|
-
});
|
|
1643
|
-
expect(newOrder.items[0]).toHaveProperty('total', 8.083543307086615);
|
|
1644
|
-
expect(newOrder.items[1]).toHaveProperty('total', 7.703779527559055);
|
|
1645
|
-
expect(newOrder.items[2]).toHaveProperty('total', 11.36191226096738);
|
|
1646
|
-
expect(newOrder.items[3]).toHaveProperty('total', 9.300764904386952);
|
|
1647
|
-
});
|
|
1648
1594
|
|
|
1649
1595
|
test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
|
|
1650
1596
|
const orderItems = [
|
|
@@ -1914,9 +1860,11 @@ describe('Order actions', () => {
|
|
|
1914
1860
|
},
|
|
1915
1861
|
];
|
|
1916
1862
|
|
|
1917
|
-
const balanceToPay = pricingService.item.
|
|
1863
|
+
const balanceToPay = pricingService.item.getItemsBalance({
|
|
1864
|
+
items: orderItems,
|
|
1865
|
+
});
|
|
1918
1866
|
|
|
1919
|
-
expect(balanceToPay).toBe(102.
|
|
1867
|
+
expect(balanceToPay).toBe(102.8);
|
|
1920
1868
|
});
|
|
1921
1869
|
|
|
1922
1870
|
test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
|
|
@@ -1992,18 +1940,18 @@ describe('Order actions', () => {
|
|
|
1992
1940
|
|
|
1993
1941
|
const newOrder = pricingService.order.calculate(order);
|
|
1994
1942
|
|
|
1995
|
-
expect(newOrder).toHaveProperty('total', 710.
|
|
1943
|
+
expect(newOrder).toHaveProperty('total', 710.36);
|
|
1996
1944
|
expect(newOrder).toHaveProperty('subTotal', 775.6);
|
|
1997
1945
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
1998
1946
|
percentage: -116.34,
|
|
1999
|
-
tax: 51.
|
|
1947
|
+
tax: 51.09265,
|
|
2000
1948
|
});
|
|
2001
|
-
expect(newOrder.items[0]).toHaveProperty('total', 65.
|
|
2002
|
-
expect(newOrder.items[1]).toHaveProperty('total', 53.
|
|
2003
|
-
expect(newOrder.items[2]).toHaveProperty('total', 65.
|
|
2004
|
-
expect(newOrder.items[3]).toHaveProperty('total', 144.
|
|
2005
|
-
expect(newOrder.items[4]).toHaveProperty('total', 271.
|
|
2006
|
-
expect(newOrder.items[5]).toHaveProperty('total', 109.
|
|
1949
|
+
expect(newOrder.items[0]).toHaveProperty('total', 65.85);
|
|
1950
|
+
expect(newOrder.items[1]).toHaveProperty('total', 53.03);
|
|
1951
|
+
expect(newOrder.items[2]).toHaveProperty('total', 65.76);
|
|
1952
|
+
expect(newOrder.items[3]).toHaveProperty('total', 144.71);
|
|
1953
|
+
expect(newOrder.items[4]).toHaveProperty('total', 271.1);
|
|
1954
|
+
expect(newOrder.items[5]).toHaveProperty('total', 109.91);
|
|
2007
1955
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2008
1956
|
'amount',
|
|
2009
1957
|
-10.785
|
|
@@ -2100,13 +2048,13 @@ describe('Order actions', () => {
|
|
|
2100
2048
|
|
|
2101
2049
|
const newOrder = pricingService.order.calculate(order);
|
|
2102
2050
|
|
|
2103
|
-
expect(newOrder).toHaveProperty('total', 137.
|
|
2051
|
+
expect(newOrder).toHaveProperty('total', 137.93);
|
|
2104
2052
|
expect(newOrder).toHaveProperty('subTotal', 128);
|
|
2105
2053
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
2106
2054
|
tax: 9.92,
|
|
2107
2055
|
});
|
|
2108
|
-
expect(newOrder.items[0]).toHaveProperty('total', 40.
|
|
2109
|
-
expect(newOrder.items[1]).toHaveProperty('total', 45.
|
|
2056
|
+
expect(newOrder.items[0]).toHaveProperty('total', 40.95);
|
|
2057
|
+
expect(newOrder.items[1]).toHaveProperty('total', 45.26);
|
|
2110
2058
|
expect(newOrder.items[2]).toHaveProperty('total', 51.72);
|
|
2111
2059
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2112
2060
|
'amount',
|
|
@@ -1,45 +1,11 @@
|
|
|
1
1
|
const moment = require('moment-timezone');
|
|
2
|
-
const
|
|
3
|
-
|
|
2
|
+
const usePricing = require('../../lib/index');
|
|
3
|
+
|
|
4
|
+
const pricingService = usePricing();
|
|
5
|
+
const { pickEndDate } = pricingService.store;
|
|
4
6
|
|
|
5
7
|
describe('pickEndDate function', () => {
|
|
6
8
|
test('Get calculated Order, one item', () => {
|
|
7
|
-
const settings = {
|
|
8
|
-
localization: {
|
|
9
|
-
locale: 'en-US',
|
|
10
|
-
hour12: true,
|
|
11
|
-
currency: 'USD',
|
|
12
|
-
phoneFormat: 'NATIONAL',
|
|
13
|
-
timezone: 'America/New_York',
|
|
14
|
-
defaultCountry: {
|
|
15
|
-
label: 'United States',
|
|
16
|
-
value: 'US',
|
|
17
|
-
},
|
|
18
|
-
dateFormat: 'default',
|
|
19
|
-
},
|
|
20
|
-
schedule: {
|
|
21
|
-
open: [
|
|
22
|
-
{
|
|
23
|
-
groupId: '666b542d5ed0ff34672d9c14',
|
|
24
|
-
days: [6, 4, 3, 1, 2, 5],
|
|
25
|
-
startTime: '04:00',
|
|
26
|
-
endTime: '17:05',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
startTime: '07:00',
|
|
30
|
-
endTime: '22:04',
|
|
31
|
-
days: [1, 2],
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
close: [
|
|
35
|
-
{
|
|
36
|
-
date: '2024-08-27',
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const pickEndDate = pickEndDateFunction({ settings, _, moment });
|
|
43
9
|
const schedule = {
|
|
44
10
|
addDays: 1,
|
|
45
11
|
hour: 17,
|
|
@@ -56,8 +22,8 @@ describe('pickEndDate function', () => {
|
|
|
56
22
|
|
|
57
23
|
const expectedDate = now
|
|
58
24
|
.clone()
|
|
59
|
-
.add(
|
|
60
|
-
.set({ hour:
|
|
25
|
+
.add(2, 'days')
|
|
26
|
+
.set({ hour: schedule.hour, minute: schedule.minute, second: 0 })
|
|
61
27
|
.utc()
|
|
62
28
|
.format();
|
|
63
29
|
|
|
@@ -65,37 +31,6 @@ describe('pickEndDate function', () => {
|
|
|
65
31
|
});
|
|
66
32
|
|
|
67
33
|
test('Order falls on a closed day', () => {
|
|
68
|
-
const settings = {
|
|
69
|
-
localization: {
|
|
70
|
-
locale: 'en-US',
|
|
71
|
-
hour12: true,
|
|
72
|
-
currency: 'USD',
|
|
73
|
-
phoneFormat: 'NATIONAL',
|
|
74
|
-
timezone: 'America/New_York',
|
|
75
|
-
defaultCountry: {
|
|
76
|
-
label: 'United States',
|
|
77
|
-
value: 'US',
|
|
78
|
-
},
|
|
79
|
-
dateFormat: 'default',
|
|
80
|
-
},
|
|
81
|
-
schedule: {
|
|
82
|
-
open: [
|
|
83
|
-
{
|
|
84
|
-
groupId: '666b542d5ed0ff34672d9c14',
|
|
85
|
-
days: [1, 2, 3, 4, 5], // Monday to Friday
|
|
86
|
-
startTime: '04:00',
|
|
87
|
-
endTime: '17:05',
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
close: [
|
|
91
|
-
{
|
|
92
|
-
date: '2024-08-28', // Wednesday is closed
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const pickEndDate = pickEndDateFunction({ settings, _, moment });
|
|
99
34
|
const schedule = {
|
|
100
35
|
addDays: 1,
|
|
101
36
|
hour: 17,
|
|
@@ -113,7 +48,7 @@ describe('pickEndDate function', () => {
|
|
|
113
48
|
const expectedDate = now
|
|
114
49
|
.clone()
|
|
115
50
|
.add(2, 'days') // Skips the closed Wednesday, goes to Thursday
|
|
116
|
-
.set({ hour:
|
|
51
|
+
.set({ hour: schedule.hour, minute: 0, second: 0 })
|
|
117
52
|
.utc()
|
|
118
53
|
.format();
|
|
119
54
|
|
|
@@ -121,33 +56,6 @@ describe('pickEndDate function', () => {
|
|
|
121
56
|
});
|
|
122
57
|
|
|
123
58
|
test('Order calculated on a weekend', () => {
|
|
124
|
-
const settings = {
|
|
125
|
-
localization: {
|
|
126
|
-
locale: 'en-US',
|
|
127
|
-
hour12: true,
|
|
128
|
-
currency: 'USD',
|
|
129
|
-
phoneFormat: 'NATIONAL',
|
|
130
|
-
timezone: 'America/New_York',
|
|
131
|
-
defaultCountry: {
|
|
132
|
-
label: 'United States',
|
|
133
|
-
value: 'US',
|
|
134
|
-
},
|
|
135
|
-
dateFormat: 'default',
|
|
136
|
-
},
|
|
137
|
-
schedule: {
|
|
138
|
-
open: [
|
|
139
|
-
{
|
|
140
|
-
groupId: '666b542d5ed0ff34672d9c14',
|
|
141
|
-
days: [1, 2, 3, 4, 5], // Monday to Friday
|
|
142
|
-
startTime: '04:00',
|
|
143
|
-
endTime: '17:05',
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
close: [],
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const pickEndDate = pickEndDateFunction({ settings, _, moment });
|
|
151
59
|
const schedule = {
|
|
152
60
|
addDays: 1,
|
|
153
61
|
hour: 17,
|
|
@@ -173,33 +81,6 @@ describe('pickEndDate function', () => {
|
|
|
173
81
|
});
|
|
174
82
|
|
|
175
83
|
test('Order time before cut-off hour', () => {
|
|
176
|
-
const settings = {
|
|
177
|
-
localization: {
|
|
178
|
-
locale: 'en-US',
|
|
179
|
-
hour12: true,
|
|
180
|
-
currency: 'USD',
|
|
181
|
-
phoneFormat: 'NATIONAL',
|
|
182
|
-
timezone: 'America/New_York',
|
|
183
|
-
defaultCountry: {
|
|
184
|
-
label: 'United States',
|
|
185
|
-
value: 'US',
|
|
186
|
-
},
|
|
187
|
-
dateFormat: 'default',
|
|
188
|
-
},
|
|
189
|
-
schedule: {
|
|
190
|
-
open: [
|
|
191
|
-
{
|
|
192
|
-
groupId: '666b542d5ed0ff34672d9c14',
|
|
193
|
-
days: [1, 2, 3, 4, 5], // Monday to Friday
|
|
194
|
-
startTime: '04:00',
|
|
195
|
-
endTime: '17:05',
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
close: [],
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const pickEndDate = pickEndDateFunction({ settings, _, moment });
|
|
203
84
|
const schedule = {
|
|
204
85
|
addDays: 0, // Same day
|
|
205
86
|
hour: 17,
|
|
@@ -223,33 +104,6 @@ describe('pickEndDate function', () => {
|
|
|
223
104
|
expect(result).toBe(expectedDate);
|
|
224
105
|
});
|
|
225
106
|
test('Order time after cut-off hour', () => {
|
|
226
|
-
const settings = {
|
|
227
|
-
localization: {
|
|
228
|
-
locale: 'en-US',
|
|
229
|
-
hour12: true,
|
|
230
|
-
currency: 'USD',
|
|
231
|
-
phoneFormat: 'NATIONAL',
|
|
232
|
-
timezone: 'America/New_York',
|
|
233
|
-
defaultCountry: {
|
|
234
|
-
label: 'United States',
|
|
235
|
-
value: 'US',
|
|
236
|
-
},
|
|
237
|
-
dateFormat: 'default',
|
|
238
|
-
},
|
|
239
|
-
schedule: {
|
|
240
|
-
open: [
|
|
241
|
-
{
|
|
242
|
-
groupId: '666b542d5ed0ff34672d9c14',
|
|
243
|
-
days: [1, 2, 3, 4, 5], // Monday to Friday
|
|
244
|
-
startTime: '04:00',
|
|
245
|
-
endTime: '17:05',
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
close: [],
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const pickEndDate = pickEndDateFunction({ settings, _, moment });
|
|
253
107
|
const schedule = {
|
|
254
108
|
hour: 17,
|
|
255
109
|
minute: 0,
|