@darkpos/pricing 1.0.44 → 1.0.46

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.
Files changed (67) hide show
  1. package/__TEST__/item/getItemsModifierDescription.test.js +75 -85
  2. package/__TEST__/mocks/scripts/calculate-partially-paid/index.js +2 -2
  3. package/__TEST__/mocks/scripts/calculate-unpaid/index.js +2 -2
  4. package/__TEST__/modifier/hasModifier.test.js +1626 -0
  5. package/__TEST__/order/addItem.test.js +2 -4
  6. package/__TEST__/order/manualSplit.test.js +104 -0
  7. package/__TEST__/order/order-payment-modifier.test.js +1117 -0
  8. package/__TEST__/order/order.test.js +50 -104
  9. package/__TEST__/order/pickEndDate.test.js +7 -153
  10. package/__TEST__/order/validateConditionsCalculate.test.js +42 -43
  11. package/lib/item/calculate.js +67 -9
  12. package/lib/item/getAmounts.js +14 -0
  13. package/lib/item/getBalance.js +0 -1
  14. package/lib/item/getInvalidRequiredModifiers.js +24 -0
  15. package/lib/item/getItemModifiersDescription.js +2 -1
  16. package/lib/item/getItemsBalance.js +9 -0
  17. package/lib/item/getItemsTotals.js +27 -0
  18. package/lib/item/getPipeModifiers.js +10 -0
  19. package/lib/item/getTotal.js +3 -1
  20. package/lib/item/hasModifier.js +21 -9
  21. package/lib/item/hasModifiers.js +3 -4
  22. package/lib/item/hasPaymentMethodType.js +17 -0
  23. package/lib/item/hasPaymentModifierWithPaymentId.js +9 -0
  24. package/lib/item/index.js +19 -10
  25. package/lib/item/removePaymentModifiersByPaymentId.js +13 -0
  26. package/lib/modifier/areConditionsMet.js +3 -13
  27. package/lib/modifier/calculatePaymentDiscountModifier.js +31 -0
  28. package/lib/modifier/calculatePaymentFeeModifier.js +27 -0
  29. package/lib/modifier/calculatePaymentModifier.js +67 -0
  30. package/lib/modifier/createDiscountModifier.js +2 -1
  31. package/lib/modifier/createFeeModifier.js +2 -1
  32. package/lib/modifier/duplicate.js +1 -1
  33. package/lib/modifier/getChildren.js +8 -0
  34. package/lib/modifier/getComputedAmount.js +9 -0
  35. package/lib/modifier/getGroupRelatedModifiers.js +5 -1
  36. package/lib/modifier/getItemModifiers.js +1 -3
  37. package/lib/modifier/hasPaymentMethodType.js +14 -0
  38. package/lib/modifier/index.js +23 -4
  39. package/lib/modifier/isCalculatedPaymentModifier.js +4 -0
  40. package/lib/modifier/isChild.js +6 -0
  41. package/lib/modifier/isDiscount.js +6 -2
  42. package/lib/modifier/isFee.js +5 -2
  43. package/lib/modifier/isPaymentMethodModifier.js +4 -1
  44. package/lib/modifier/isPaymentTypeModifier.js +4 -1
  45. package/lib/modifier/isPercentage.js +10 -0
  46. package/lib/modifier/isRelatedModifier.js +13 -0
  47. package/lib/modifier/removeGroupData.js +20 -0
  48. package/lib/modifier/sort.js +28 -0
  49. package/lib/order/addItemModifier.js +8 -1
  50. package/lib/order/applyPayment.js +61 -0
  51. package/lib/order/calculate.js +34 -16
  52. package/lib/order/getBalance.js +0 -1
  53. package/lib/order/getOrdersBalance.js +8 -0
  54. package/lib/order/index.js +9 -8
  55. package/lib/order/manualSplit.js +34 -0
  56. package/lib/order/manualSplitByQuantity.js +50 -0
  57. package/lib/store/pickEndDate.js +2 -2
  58. package/package.json +7 -4
  59. package/lib/item/getBalanceToPay.js +0 -12
  60. package/lib/item/getTotals.js +0 -40
  61. package/lib/item/isSelected.js +0 -13
  62. package/lib/item/markModifiersAsLocked.js +0 -13
  63. package/lib/modifier/createPaymentModifier.js +0 -12
  64. package/lib/modifier/getLockedModifiers.js +0 -5
  65. package/lib/order/markModifiersAsLocked.js +0 -14
  66. package/lib/order/removeModifiersWithPaymentMethods.js +0 -28
  67. package/lib/order/removeModifiersWithPaymentTypes.js +0 -26
@@ -127,7 +127,7 @@ describe('Order actions', () => {
127
127
  expect(newOrder).toHaveProperty('subTotals', {
128
128
  discount: -2,
129
129
  });
130
- expect(newOrder.items[0]).toHaveProperty('total', 58.285714285714285);
130
+ expect(newOrder.items[0]).toHaveProperty('total', 58.29);
131
131
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
132
132
  discount: -1.7142857142857142,
133
133
  _included: 0,
@@ -137,7 +137,7 @@ describe('Order actions', () => {
137
137
  _simple: 60,
138
138
  _actual: 60,
139
139
  });
140
- expect(newOrder.items[1]).toHaveProperty('total', 9.714285714285714);
140
+ expect(newOrder.items[1]).toHaveProperty('total', 9.71);
141
141
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
142
142
  discount: -0.2857142857142857,
143
143
  _included: 0,
@@ -174,9 +174,9 @@ describe('Order actions', () => {
174
174
  expect(newOrder).toHaveProperty('total', 18.58);
175
175
  expect(newOrder).toHaveProperty('subTotal', 20.64);
176
176
  expect(newOrder).toHaveProperty('subTotals', {
177
- discount: -2.06,
177
+ discount: -2.064,
178
178
  });
179
- expect(newOrder.items[0]).toHaveProperty('total', 14.391);
179
+ expect(newOrder.items[0]).toHaveProperty('total', 14.39);
180
180
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
181
181
  discount: -1.599,
182
182
  _included: 0,
@@ -186,7 +186,7 @@ describe('Order actions', () => {
186
186
  _simple: 15.99,
187
187
  _actual: 15.99,
188
188
  });
189
- expect(newOrder.items[1]).toHaveProperty('total', 4.185);
189
+ expect(newOrder.items[1]).toHaveProperty('total', 4.19);
190
190
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
191
191
  discount: -0.465,
192
192
  _included: 0,
@@ -683,11 +683,11 @@ describe('Order actions', () => {
683
683
  expect(newOrder).toHaveProperty('subTotal', 109.4);
684
684
  expect(newOrder).toHaveProperty('subTotals', {
685
685
  discount: -16.41,
686
- tax: 7.21,
686
+ tax: 7.206725,
687
687
  });
688
- expect(newOrder.items[0]).toHaveProperty('total', 80.597);
689
- expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
690
- expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
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);
691
691
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
692
692
  'amount',
693
693
  13.2
@@ -703,7 +703,7 @@ describe('Order actions', () => {
703
703
  );
704
704
  expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
705
705
  'amount',
706
- 0.98483125
706
+ 0.985025
707
707
  );
708
708
 
709
709
  expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
@@ -712,7 +712,7 @@ describe('Order actions', () => {
712
712
  );
713
713
  expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
714
714
  'amount',
715
- 0.42489375
715
+ 0.4247
716
716
  );
717
717
  });
718
718
 
@@ -775,11 +775,11 @@ describe('Order actions', () => {
775
775
  expect(newOrder).toHaveProperty('subTotal', 109.4);
776
776
  expect(newOrder).toHaveProperty('subTotals', {
777
777
  discount: -16.41,
778
- tax: 7.21,
778
+ tax: 7.206725,
779
779
  });
780
- expect(newOrder.items[0]).toHaveProperty('total', 80.597);
781
- expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
782
- expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
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);
783
783
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
784
784
  'amount',
785
785
  13.2
@@ -867,11 +867,11 @@ describe('Order actions', () => {
867
867
  expect(newOrder).toHaveProperty('subTotal', 109.4);
868
868
  expect(newOrder).toHaveProperty('subTotals', {
869
869
  discount: -16.41,
870
- tax: 7.21,
870
+ tax: 7.206725,
871
871
  });
872
- expect(newOrder.items[0]).toHaveProperty('total', 80.597);
873
- expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
874
- expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
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);
875
875
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
876
876
  'amount',
877
877
  -13.2
@@ -959,11 +959,11 @@ describe('Order actions', () => {
959
959
  expect(newOrder).toHaveProperty('subTotal', 109.4);
960
960
  expect(newOrder).toHaveProperty('subTotals', {
961
961
  discount: -16.41,
962
- tax: 7.21,
962
+ tax: 7.206725,
963
963
  });
964
- expect(newOrder.items[0]).toHaveProperty('total', 80.597);
965
- expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
966
- expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
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);
967
967
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
968
968
  'amount',
969
969
  -13.2
@@ -979,7 +979,7 @@ describe('Order actions', () => {
979
979
  );
980
980
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
981
981
  'amount',
982
- 0.98483125
982
+ 0.985025
983
983
  );
984
984
 
985
985
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
@@ -988,7 +988,7 @@ describe('Order actions', () => {
988
988
  );
989
989
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
990
990
  'amount',
991
- 0.42489375
991
+ 0.4247
992
992
  );
993
993
  });
994
994
 
@@ -1140,18 +1140,18 @@ describe('Order actions', () => {
1140
1140
  expect(newOrder).toHaveProperty('subTotal', 3);
1141
1141
  expect(newOrder).toHaveProperty('subTotals', {
1142
1142
  fixed: -1,
1143
- tax: 0.16,
1143
+ tax: 0.155775,
1144
1144
  });
1145
- expect(newOrder.items[0]).toHaveProperty('total', 0.7183333333333333);
1146
- expect(newOrder.items[1]).toHaveProperty('total', 0.7183333333333334);
1147
- expect(newOrder.items[2]).toHaveProperty('total', 0.7183333333333334);
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);
1148
1148
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1149
1149
  'amount',
1150
1150
  -0.3333333333333334
1151
1151
  );
1152
1152
  expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1153
1153
  'amount',
1154
- 0.05166666666666666
1154
+ 0.051925
1155
1155
  );
1156
1156
 
1157
1157
  expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
@@ -1160,7 +1160,7 @@ describe('Order actions', () => {
1160
1160
  );
1161
1161
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1162
1162
  'amount',
1163
- 0.05166666666666667
1163
+ 0.051925
1164
1164
  );
1165
1165
 
1166
1166
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
@@ -1169,7 +1169,7 @@ describe('Order actions', () => {
1169
1169
  );
1170
1170
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1171
1171
  'amount',
1172
- 0.05166666666666667
1172
+ 0.051925
1173
1173
  );
1174
1174
  });
1175
1175
 
@@ -1264,19 +1264,19 @@ describe('Order actions', () => {
1264
1264
 
1265
1265
  const [item1, item2, item3] = newOrder.items;
1266
1266
  expect(newOrder).toHaveProperty('total', 12.5);
1267
- expect(item1).toHaveProperty('total', 3.653846153846154);
1267
+ expect(item1).toHaveProperty('total', 3.66);
1268
1268
  expect(item1.modifiers[1].compute).toHaveProperty(
1269
1269
  'amount',
1270
1270
  5.846153846153846
1271
1271
  );
1272
1272
 
1273
- expect(item2).toHaveProperty('total', 5.3846153846153854615384615385);
1273
+ expect(item2).toHaveProperty('total', 5.38);
1274
1274
  expect(item2.modifiers[1].compute).toHaveProperty(
1275
1275
  'amount',
1276
1276
  8.615384615384615
1277
1277
  );
1278
1278
 
1279
- expect(item3).toHaveProperty('total', 3.461538461538462);
1279
+ expect(item3).toHaveProperty('total', 3.46);
1280
1280
  expect(item3.modifiers[1].compute).toHaveProperty(
1281
1281
  'amount',
1282
1282
  5.538461538461538
@@ -1591,62 +1591,6 @@ describe('Order actions', () => {
1591
1591
  'M-L 2pc Suit',
1592
1592
  ]);
1593
1593
  });
1594
- test('Get calculated UNPAID Order, multiple items and paymentModifiers', () => {
1595
- const paymentModifiers = orderModifiersNotPaid.map(orderMod =>
1596
- pricingService.modifier.createPaymentModifier({
1597
- modifier: orderMod,
1598
- items: inputItemsNotPaidOrder,
1599
- })
1600
- );
1601
-
1602
- let order = { ...orderNotPaid };
1603
-
1604
- order = pricingService.order.addModifiers({
1605
- modifiers: paymentModifiers,
1606
- order,
1607
- });
1608
- const paymentMethod = { type: 'cash' };
1609
- const newOrder = pricingService.order.calculate(order, { paymentMethod });
1610
-
1611
- expect(newOrder).toHaveProperty('total', 34.45);
1612
- expect(newOrder).toHaveProperty('subTotal', 42.45);
1613
- expect(newOrder).toHaveProperty('subTotals', {
1614
- discount: -10,
1615
- fee: 2,
1616
- });
1617
- expect(newOrder.items[0]).toHaveProperty('total', 8.074852767962309);
1618
- expect(newOrder.items[1]).toHaveProperty('total', 7.709658421672556);
1619
- expect(newOrder.items[2]).toHaveProperty('total', 11.361601884570083);
1620
- expect(newOrder.items[3]).toHaveProperty('total', 7.303886925795053);
1621
- });
1622
- test('Get calculated PARTIALLY PAID Order, multiple items and paymentModifiers', () => {
1623
- const paymentModifiers = orderModifiersPartiallyPaid.map(orderMod =>
1624
- pricingService.modifier.createPaymentModifier({
1625
- modifier: orderMod,
1626
- items: inputItemsPartiallyPaidOrder,
1627
- })
1628
- );
1629
-
1630
- let order = { ...orderPartiallyPaid };
1631
-
1632
- order = pricingService.order.addModifiers({
1633
- modifiers: paymentModifiers,
1634
- order,
1635
- });
1636
- const paymentMethod = { type: 'cash' };
1637
- const newOrder = pricingService.order.calculate(order, { paymentMethod });
1638
-
1639
- expect(newOrder).toHaveProperty('total', 36.45);
1640
- expect(newOrder).toHaveProperty('subTotal', 42.45);
1641
- expect(newOrder).toHaveProperty('subTotals', {
1642
- discount: -10,
1643
- fee: 4,
1644
- });
1645
- expect(newOrder.items[0]).toHaveProperty('total', 8.083543307086615);
1646
- expect(newOrder.items[1]).toHaveProperty('total', 7.703779527559055);
1647
- expect(newOrder.items[2]).toHaveProperty('total', 11.36191226096738);
1648
- expect(newOrder.items[3]).toHaveProperty('total', 9.300764904386952);
1649
- });
1650
1594
 
1651
1595
  test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
1652
1596
  const orderItems = [
@@ -1916,9 +1860,11 @@ describe('Order actions', () => {
1916
1860
  },
1917
1861
  ];
1918
1862
 
1919
- const balanceToPay = pricingService.item.getBalanceToPay({ orderItems });
1863
+ const balanceToPay = pricingService.item.getItemsBalance({
1864
+ items: orderItems,
1865
+ });
1920
1866
 
1921
- expect(balanceToPay).toBe(102.79);
1867
+ expect(balanceToPay).toBe(102.8);
1922
1868
  });
1923
1869
 
1924
1870
  test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
@@ -1994,18 +1940,18 @@ describe('Order actions', () => {
1994
1940
 
1995
1941
  const newOrder = pricingService.order.calculate(order);
1996
1942
 
1997
- expect(newOrder).toHaveProperty('total', 710.35);
1943
+ expect(newOrder).toHaveProperty('total', 710.36);
1998
1944
  expect(newOrder).toHaveProperty('subTotal', 775.6);
1999
1945
  expect(newOrder).toHaveProperty('subTotals', {
2000
1946
  percentage: -116.34,
2001
- tax: 51.09,
1947
+ tax: 51.09265,
2002
1948
  });
2003
- expect(newOrder.items[0]).toHaveProperty('total', 65.8514125);
2004
- expect(newOrder.items[1]).toHaveProperty('total', 53.0291625);
2005
- expect(newOrder.items[2]).toHaveProperty('total', 65.759825);
2006
- expect(newOrder.items[3]).toHaveProperty('total', 144.70825);
2007
- expect(newOrder.items[4]).toHaveProperty('total', 271.099);
2008
- expect(newOrder.items[5]).toHaveProperty('total', 109.905);
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);
2009
1955
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2010
1956
  'amount',
2011
1957
  -10.785
@@ -2102,13 +2048,13 @@ describe('Order actions', () => {
2102
2048
 
2103
2049
  const newOrder = pricingService.order.calculate(order);
2104
2050
 
2105
- expect(newOrder).toHaveProperty('total', 137.92);
2051
+ expect(newOrder).toHaveProperty('total', 137.93);
2106
2052
  expect(newOrder).toHaveProperty('subTotal', 128);
2107
2053
  expect(newOrder).toHaveProperty('subTotals', {
2108
2054
  tax: 9.92,
2109
2055
  });
2110
- expect(newOrder.items[0]).toHaveProperty('total', 40.945);
2111
- expect(newOrder.items[1]).toHaveProperty('total', 45.255);
2056
+ expect(newOrder.items[0]).toHaveProperty('total', 40.95);
2057
+ expect(newOrder.items[1]).toHaveProperty('total', 45.26);
2112
2058
  expect(newOrder.items[2]).toHaveProperty('total', 51.72);
2113
2059
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2114
2060
  'amount',
@@ -1,45 +1,11 @@
1
1
  const moment = require('moment-timezone');
2
- const _ = require('lodash');
3
- const pickEndDateFunction = require('../../lib/store/pickEndDate');
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(3, 'days')
60
- .set({ hour: 0, minute: 0, second: 0 })
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: 0, minute: 0, second: 0 })
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,
@@ -250,6 +250,7 @@ describe('Conditions not met for the item', () => {
250
250
  itemId: '123',
251
251
  price: 100,
252
252
  modifiers: [],
253
+ total: 100,
253
254
  };
254
255
  order.items.push(item);
255
256
  const modifier = {
@@ -261,6 +262,8 @@ describe('Conditions not met for the item', () => {
261
262
  operand: '$in',
262
263
  },
263
264
  ],
265
+ _id: 'abcd',
266
+ modifierId: '123',
264
267
  },
265
268
  compute: {
266
269
  amount: 30,
@@ -270,10 +273,7 @@ describe('Conditions not met for the item', () => {
270
273
  };
271
274
  item.modifiers.push(modifier);
272
275
  const { calculate } = pricingService.order;
273
- const paymentMethod = {
274
- key: 'credit',
275
- };
276
- const calculatedOrder = calculate(order, { paymentMethod });
276
+ const calculatedOrder = calculate(order, { paymentType: 'credit' });
277
277
  expect(calculatedOrder).toHaveProperty('total', 100);
278
278
  expect(calculatedOrder).toHaveProperty('subTotal', 100);
279
279
  });
@@ -288,6 +288,7 @@ describe('Conditions not met for the item', () => {
288
288
  itemId: '123',
289
289
  price: 100,
290
290
  modifiers: [],
291
+ total: 100,
291
292
  };
292
293
  order.items.push(item);
293
294
  const modifier = {
@@ -305,22 +306,20 @@ describe('Conditions not met for the item', () => {
305
306
  type: 'fixed',
306
307
  action: 'subtract',
307
308
  },
309
+ _id: '123',
310
+ modifierId: 'abc',
308
311
  };
309
312
  item.modifiers.push(modifier);
310
313
  const { calculate } = pricingService.order;
311
- // Calculate the order
312
- const paymentMethod = {
313
- key: 'cash',
314
- };
315
- const calculatedOrder = calculate(order, { paymentMethod });
314
+
315
+ const calculatedOrder = calculate(order, { paymentMethod: 'cash' });
316
316
  expect(calculatedOrder).toHaveProperty('total', 70);
317
317
  expect(calculatedOrder).toHaveProperty('subTotal', 100);
318
318
  });
319
319
  test('#9: paymentTypes condition is not met, item price remains the same', () => {
320
320
  const order = {
321
- id: 'ord-123',
321
+ _id: 'ord-123',
322
322
  items: [],
323
- modifiers: [],
324
323
  };
325
324
  const item = {
326
325
  quantity: 1,
@@ -344,53 +343,53 @@ describe('Conditions not met for the item', () => {
344
343
  type: 'fixed',
345
344
  action: 'subtract',
346
345
  },
346
+ _id: '111',
347
+ modifierId: 'ccc',
347
348
  };
348
349
  item.modifiers.push(modifier);
349
350
  const { calculate } = pricingService.order;
350
- const paymentMethod = {
351
- type: 'credit',
352
- };
351
+
353
352
  // Calculate the order
354
- const calculatedOrder = calculate(order, { paymentMethod });
353
+ const calculatedOrder = calculate(order, { paymentType: 'credit' });
355
354
  expect(calculatedOrder).toHaveProperty('total', 100);
356
355
  expect(calculatedOrder).toHaveProperty('subTotal', 100);
357
356
  });
358
357
  test('#10: paymentTypes condition is met, item total is updated', () => {
359
- const order = {
360
- id: 'ord-123',
361
- items: [],
362
- modifiers: [],
363
- };
364
358
  const item = {
365
359
  quantity: 1,
366
360
  itemId: '123',
367
361
  price: 100,
368
- modifiers: [],
369
- };
370
- order.items.push(item);
371
- const modifier = {
372
- conditions: {
373
- rules: [
374
- {
375
- key: 'paymentTypes',
376
- value: ['cash'],
377
- operand: '$in',
362
+ modifiers: [
363
+ {
364
+ conditions: {
365
+ rules: [
366
+ {
367
+ key: 'paymentTypes',
368
+ value: ['cash'],
369
+ operand: '$in',
370
+ },
371
+ ],
378
372
  },
379
- ],
380
- },
381
- compute: {
382
- amount: 30,
383
- type: 'fixed',
384
- action: 'subtract',
385
- },
373
+ compute: {
374
+ amount: 30,
375
+ type: 'fixed',
376
+ action: 'subtract',
377
+ },
378
+ _id: '123',
379
+ modifierId: 'bcd',
380
+ },
381
+ ],
382
+ total: 100,
386
383
  };
387
- item.modifiers.push(modifier);
388
384
  const { calculate } = pricingService.order;
389
- // Calculate the order
390
- const paymentMethod = {
391
- type: 'cash',
392
- };
393
- const calculatedOrder = calculate(order, { paymentMethod });
385
+
386
+ const calculatedOrder = calculate(
387
+ {
388
+ _id: 'ord-123',
389
+ items: [item],
390
+ },
391
+ { paymentType: 'cash' }
392
+ );
394
393
  expect(calculatedOrder).toHaveProperty('total', 70);
395
394
  expect(calculatedOrder).toHaveProperty('subTotal', 100);
396
395
  });