@darkpos/pricing 1.0.22 → 1.0.24

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.
@@ -94,7 +94,6 @@ describe('Order actions', () => {
94
94
  expect(newOrder).toHaveProperty('subTotals', {
95
95
  discount: -6,
96
96
  });
97
- // console.log(JSON.stringify(newOrder, 0, 2));
98
97
  });
99
98
  test('Get calculated Order, multiple items and indirect modifiers', () => {
100
99
  const item1 = {
@@ -125,23 +124,23 @@ describe('Order actions', () => {
125
124
  expect(newOrder).toHaveProperty('subTotals', {
126
125
  discount: -2,
127
126
  });
128
- expect(newOrder.items[0]).toHaveProperty('total', 58.28);
127
+ expect(newOrder.items[0]).toHaveProperty('total', 58.29);
129
128
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
130
- discount: -1.72,
129
+ discount: -1.7142857142857142,
131
130
  _included: 0,
132
- _xincluded: -1.72,
131
+ _xincluded: -1.7142857142857142,
133
132
  _direct: 0,
134
- _xdirect: -1.72,
133
+ _xdirect: -1.7142857142857142,
135
134
  _simple: 60,
136
135
  _actual: 60,
137
136
  });
138
- expect(newOrder.items[1]).toHaveProperty('total', 9.72);
137
+ expect(newOrder.items[1]).toHaveProperty('total', 9.71);
139
138
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
140
- discount: -0.28,
139
+ discount: -0.2857142857142857,
141
140
  _included: 0,
142
- _xincluded: -0.28,
141
+ _xincluded: -0.2857142857142857,
143
142
  _direct: 0,
144
- _xdirect: -0.28,
143
+ _xdirect: -0.2857142857142857,
145
144
  _simple: 10,
146
145
  _actual: 10,
147
146
  });
@@ -176,21 +175,21 @@ describe('Order actions', () => {
176
175
  });
177
176
  expect(newOrder.items[0]).toHaveProperty('total', 14.39);
178
177
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
179
- discount: -1.6,
178
+ discount: -1.599,
180
179
  _included: 0,
181
- _xincluded: -1.6,
180
+ _xincluded: -1.599,
182
181
  _direct: 0,
183
- _xdirect: -1.6,
182
+ _xdirect: -1.599,
184
183
  _simple: 15.99,
185
184
  _actual: 15.99,
186
185
  });
187
186
  expect(newOrder.items[1]).toHaveProperty('total', 4.19);
188
187
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
189
- discount: -0.46,
188
+ discount: -0.465,
190
189
  _included: 0,
191
- _xincluded: -0.46,
190
+ _xincluded: -0.465,
192
191
  _direct: 0,
193
- _xdirect: -0.46,
192
+ _xdirect: -0.465,
194
193
  _simple: 4.65,
195
194
  _actual: 4.65,
196
195
  });
@@ -627,19 +626,658 @@ describe('Order actions', () => {
627
626
  });
628
627
  });
629
628
 
629
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 order tax (sort 99)', () => {
630
+ const item1 = {
631
+ _id: 1,
632
+ price: 44,
633
+ quantity: 2,
634
+ };
635
+ const item2 = {
636
+ _id: 2,
637
+ price: 14.95,
638
+ quantity: 1,
639
+ };
640
+ const item3 = {
641
+ _id: 3,
642
+ price: 2.15,
643
+ quantity: 3,
644
+ };
645
+ const discountMod = {
646
+ _id: 1,
647
+ compute: {
648
+ amount: 15,
649
+ type: 'percentage',
650
+ action: 'subtract',
651
+ },
652
+ name: `15% Discount`,
653
+ type: 'discount',
654
+ properties: {
655
+ sort: 1,
656
+ },
657
+ };
658
+ const taxMod = {
659
+ _id: 2,
660
+ name: `7.75% tax`,
661
+ type: 'tax',
662
+ compute: {
663
+ amount: 7.75,
664
+ type: 'percentage',
665
+ action: 'add',
666
+ },
667
+ properties: {
668
+ sort: 99,
669
+ },
670
+ };
671
+
672
+ const order = {
673
+ items: [item1, item2, item3],
674
+ modifiers: [discountMod, taxMod],
675
+ };
676
+
677
+ const newOrder = pricingService.order.calculate(order);
678
+
679
+ expect(newOrder).toHaveProperty('total', 100.2);
680
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
681
+ expect(newOrder).toHaveProperty('subTotals', {
682
+ discount: -16.41,
683
+ tax: 7.21,
684
+ });
685
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
686
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
687
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
688
+ expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
689
+ 'amount',
690
+ 13.2
691
+ );
692
+ expect(newOrder.items[0].modifiers[1].compute).toHaveProperty(
693
+ 'amount',
694
+ 5.797
695
+ );
696
+
697
+ expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
698
+ 'amount',
699
+ 2.2425
700
+ );
701
+ expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
702
+ 'amount',
703
+ 0.985025
704
+ );
705
+
706
+ expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
707
+ 'amount',
708
+ 0.9675
709
+ );
710
+ expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
711
+ 'amount',
712
+ 0.4247
713
+ );
714
+ });
715
+
716
+ test(`CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 item tax (sort 99)`, () => {
717
+ const taxMod = {
718
+ _id: 2,
719
+ name: `7.75% tax`,
720
+ type: 'tax',
721
+ compute: {
722
+ amount: 7.75,
723
+ type: 'percentage',
724
+ action: 'add',
725
+ },
726
+ properties: {
727
+ sort: 99,
728
+ },
729
+ };
730
+
731
+ const discountMod = {
732
+ _id: 1,
733
+ compute: {
734
+ amount: 15,
735
+ type: 'percentage',
736
+ action: 'subtract',
737
+ },
738
+ name: `15% Discount`,
739
+ type: 'discount',
740
+ properties: {
741
+ sort: 1,
742
+ },
743
+ };
744
+
745
+ const item1 = {
746
+ _id: 1,
747
+ price: 44,
748
+ quantity: 2,
749
+ modifiers: [taxMod],
750
+ };
751
+ const item2 = {
752
+ _id: 2,
753
+ price: 14.95,
754
+ quantity: 1,
755
+ modifiers: [taxMod],
756
+ };
757
+ const item3 = {
758
+ _id: 3,
759
+ price: 2.15,
760
+ quantity: 3,
761
+ modifiers: [taxMod],
762
+ };
763
+
764
+ const order = {
765
+ items: [item1, item2, item3],
766
+ modifiers: [discountMod],
767
+ };
768
+
769
+ const newOrder = pricingService.order.calculate(order);
770
+
771
+ expect(newOrder).toHaveProperty('total', 100.2);
772
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
773
+ expect(newOrder).toHaveProperty('subTotals', {
774
+ discount: -16.41,
775
+ tax: 7.21,
776
+ });
777
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
778
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
779
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
780
+ expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
781
+ 'amount',
782
+ 13.2
783
+ );
784
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
785
+ 'amount',
786
+ 5.797
787
+ );
788
+
789
+ expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
790
+ 'amount',
791
+ 2.2425
792
+ );
793
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
794
+ 'amount',
795
+ 0.98483125
796
+ );
797
+
798
+ expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
799
+ 'amount',
800
+ 0.9675
801
+ );
802
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
803
+ 'amount',
804
+ 0.42489375
805
+ );
806
+ });
807
+
808
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (sort 1), 1 item tax (sort 99)', () => {
809
+ const taxMod = {
810
+ _id: 2,
811
+ name: `7.75% tax`,
812
+ type: 'tax',
813
+ compute: {
814
+ amount: 7.75,
815
+ type: 'percentage',
816
+ action: 'add',
817
+ },
818
+ properties: {
819
+ sort: 99,
820
+ },
821
+ };
822
+
823
+ const discountMod = {
824
+ _id: 1,
825
+ compute: {
826
+ amount: 15,
827
+ type: 'percentage',
828
+ action: 'subtract',
829
+ },
830
+ name: `15% Discount`,
831
+ type: 'discount',
832
+ properties: {
833
+ sort: 1,
834
+ },
835
+ };
836
+
837
+ const item1 = {
838
+ _id: 1,
839
+ price: 44,
840
+ quantity: 2,
841
+ modifiers: [taxMod, discountMod],
842
+ };
843
+ const item2 = {
844
+ _id: 2,
845
+ price: 14.95,
846
+ quantity: 1,
847
+ modifiers: [taxMod, discountMod],
848
+ };
849
+ const item3 = {
850
+ _id: 3,
851
+ price: 2.15,
852
+ quantity: 3,
853
+ modifiers: [taxMod, discountMod],
854
+ };
855
+
856
+ const order = {
857
+ items: [item1, item2, item3],
858
+ modifiers: [],
859
+ };
860
+
861
+ const newOrder = pricingService.order.calculate(order);
862
+
863
+ expect(newOrder).toHaveProperty('total', 100.2);
864
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
865
+ expect(newOrder).toHaveProperty('subTotals', {
866
+ discount: -16.41,
867
+ tax: 7.21,
868
+ });
869
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
870
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
871
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
872
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
873
+ 'amount',
874
+ -13.2
875
+ );
876
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
877
+ 'amount',
878
+ 5.797
879
+ );
880
+
881
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
882
+ 'amount',
883
+ -2.2425
884
+ );
885
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
886
+ 'amount',
887
+ 0.98483125
888
+ );
889
+
890
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
891
+ 'amount',
892
+ -0.9675
893
+ );
894
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
895
+ 'amount',
896
+ 0.42489375
897
+ );
898
+ });
899
+
900
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (sort 1), 1 order tax (sort 99)', () => {
901
+ const taxMod = {
902
+ _id: 2,
903
+ name: `7.75% tax`,
904
+ type: 'tax',
905
+ compute: {
906
+ amount: 7.75,
907
+ type: 'percentage',
908
+ action: 'add',
909
+ },
910
+ properties: {
911
+ sort: 99,
912
+ },
913
+ };
914
+
915
+ const discountMod = {
916
+ _id: 1,
917
+ compute: {
918
+ amount: 15,
919
+ type: 'percentage',
920
+ action: 'subtract',
921
+ },
922
+ name: `15% Discount`,
923
+ type: 'discount',
924
+ properties: {
925
+ sort: 1,
926
+ },
927
+ };
928
+
929
+ const item1 = {
930
+ _id: 1,
931
+ price: 44,
932
+ quantity: 2,
933
+ modifiers: [discountMod],
934
+ };
935
+ const item2 = {
936
+ _id: 2,
937
+ price: 14.95,
938
+ quantity: 1,
939
+ modifiers: [discountMod],
940
+ };
941
+ const item3 = {
942
+ _id: 3,
943
+ price: 2.15,
944
+ quantity: 3,
945
+ modifiers: [discountMod],
946
+ };
947
+
948
+ const order = {
949
+ items: [item1, item2, item3],
950
+ modifiers: [taxMod],
951
+ };
952
+
953
+ const newOrder = pricingService.order.calculate(order);
954
+
955
+ expect(newOrder).toHaveProperty('total', 100.2);
956
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
957
+ expect(newOrder).toHaveProperty('subTotals', {
958
+ discount: -16.41,
959
+ tax: 7.21,
960
+ });
961
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
962
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
963
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
964
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
965
+ 'amount',
966
+ -13.2
967
+ );
968
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
969
+ 'amount',
970
+ 5.797
971
+ );
972
+
973
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
974
+ 'amount',
975
+ -2.2425
976
+ );
977
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
978
+ 'amount',
979
+ 0.985025
980
+ );
981
+
982
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
983
+ 'amount',
984
+ -0.9675
985
+ );
986
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
987
+ 'amount',
988
+ 0.4247
989
+ );
990
+ });
991
+
992
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (ignoreQty), 1 order tax', () => {
993
+ const taxMod = {
994
+ _id: 2,
995
+ name: `7.75% tax`,
996
+ type: 'tax',
997
+ compute: {
998
+ amount: 7.75,
999
+ type: 'percentage',
1000
+ action: 'add',
1001
+ },
1002
+ };
1003
+
1004
+ const discountMod = {
1005
+ _id: 1,
1006
+ compute: {
1007
+ amount: 1,
1008
+ type: 'fixed',
1009
+ action: 'subtract',
1010
+ },
1011
+ name: `1 USD`,
1012
+ type: 'fixed',
1013
+ properties: {
1014
+ ignoreQuantity: true,
1015
+ },
1016
+ };
1017
+
1018
+ const item1 = {
1019
+ _id: 1,
1020
+ price: 1,
1021
+ quantity: 1,
1022
+ modifiers: [discountMod],
1023
+ };
1024
+ const item2 = {
1025
+ _id: 2,
1026
+ price: 1,
1027
+ quantity: 1,
1028
+ modifiers: [discountMod],
1029
+ };
1030
+ const item3 = {
1031
+ _id: 3,
1032
+ price: 0.5,
1033
+ quantity: 2,
1034
+ modifiers: [discountMod],
1035
+ };
1036
+
1037
+ const order = {
1038
+ items: [item1, item2, item3],
1039
+ modifiers: [taxMod],
1040
+ };
1041
+
1042
+ const newOrder = pricingService.order.calculate(order);
1043
+
1044
+ expect(newOrder).toHaveProperty('total', 0);
1045
+ expect(newOrder).toHaveProperty('subTotal', 3);
1046
+ expect(newOrder).toHaveProperty('subTotals', {
1047
+ fixed: -3,
1048
+ tax: 0,
1049
+ });
1050
+ expect(newOrder.items[0]).toHaveProperty('total', 0);
1051
+ expect(newOrder.items[1]).toHaveProperty('total', 0);
1052
+ expect(newOrder.items[2]).toHaveProperty('total', 0);
1053
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1054
+ 'amount',
1055
+ -1
1056
+ );
1057
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1058
+ 'amount',
1059
+ 0
1060
+ );
1061
+
1062
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1063
+ 'amount',
1064
+ -1
1065
+ );
1066
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1067
+ 'amount',
1068
+ 0
1069
+ );
1070
+
1071
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1072
+ 'amount',
1073
+ -1
1074
+ );
1075
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1076
+ 'amount',
1077
+ 0
1078
+ );
1079
+ });
1080
+
1081
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 order tax (sort 2)', () => {
1082
+ const taxMod = {
1083
+ _id: 2,
1084
+ name: `7.75% tax`,
1085
+ type: 'tax',
1086
+ compute: {
1087
+ amount: 7.75,
1088
+ type: 'percentage',
1089
+ action: 'add',
1090
+ },
1091
+ properties: {
1092
+ sort: 2,
1093
+ },
1094
+ };
1095
+
1096
+ const discountMod = {
1097
+ _id: 1,
1098
+ compute: {
1099
+ amount: 1,
1100
+ type: 'fixed',
1101
+ action: 'subtract',
1102
+ },
1103
+ name: `1 USD`,
1104
+ type: 'fixed',
1105
+ properties: {
1106
+ sort: 1,
1107
+ },
1108
+ };
1109
+
1110
+ const item1 = {
1111
+ _id: 1,
1112
+ price: 1,
1113
+ quantity: 1,
1114
+ modifiers: [],
1115
+ };
1116
+ const item2 = {
1117
+ _id: 2,
1118
+ price: 1,
1119
+ quantity: 1,
1120
+ modifiers: [],
1121
+ };
1122
+ const item3 = {
1123
+ _id: 3,
1124
+ price: 0.5,
1125
+ quantity: 2,
1126
+ modifiers: [],
1127
+ };
1128
+
1129
+ const order = {
1130
+ items: [item1, item2, item3],
1131
+ modifiers: [taxMod, discountMod],
1132
+ };
1133
+
1134
+ const newOrder = pricingService.order.calculate(order);
1135
+
1136
+ expect(newOrder).toHaveProperty('total', 2.16);
1137
+ expect(newOrder).toHaveProperty('subTotal', 3);
1138
+ expect(newOrder).toHaveProperty('subTotals', {
1139
+ fixed: -1,
1140
+ tax: 0.16,
1141
+ });
1142
+ expect(newOrder.items[0]).toHaveProperty('total', 0.72);
1143
+ expect(newOrder.items[1]).toHaveProperty('total', 0.72);
1144
+ expect(newOrder.items[2]).toHaveProperty('total', 0.72);
1145
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1146
+ 'amount',
1147
+ -0.3333333333333334
1148
+ );
1149
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1150
+ 'amount',
1151
+ 0.051925
1152
+ );
1153
+
1154
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1155
+ 'amount',
1156
+ -0.3333333333333333
1157
+ );
1158
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1159
+ 'amount',
1160
+ 0.051925
1161
+ );
1162
+
1163
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1164
+ 'amount',
1165
+ -0.16666666666666666
1166
+ );
1167
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1168
+ 'amount',
1169
+ 0.051925
1170
+ );
1171
+ });
1172
+
1173
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount, 1 order tax', () => {
1174
+ const taxMod = {
1175
+ _id: 2,
1176
+ name: `7.75% tax`,
1177
+ type: 'tax',
1178
+ compute: {
1179
+ amount: 7.75,
1180
+ type: 'percentage',
1181
+ action: 'add',
1182
+ },
1183
+ };
1184
+
1185
+ const discountMod = {
1186
+ _id: 1,
1187
+ compute: {
1188
+ amount: 1,
1189
+ type: 'fixed',
1190
+ action: 'subtract',
1191
+ },
1192
+ name: `1 USD`,
1193
+ type: 'fixed',
1194
+ };
1195
+
1196
+ const item1 = {
1197
+ _id: 1,
1198
+ price: 1,
1199
+ quantity: 1,
1200
+ modifiers: [discountMod],
1201
+ };
1202
+ const item2 = {
1203
+ _id: 2,
1204
+ price: 1,
1205
+ quantity: 1,
1206
+ modifiers: [discountMod],
1207
+ };
1208
+ const item3 = {
1209
+ _id: 3,
1210
+ price: 0.5,
1211
+ quantity: 2,
1212
+ modifiers: [discountMod],
1213
+ };
1214
+
1215
+ const order = {
1216
+ items: [item1, item2, item3],
1217
+ modifiers: [taxMod],
1218
+ };
1219
+
1220
+ const newOrder = pricingService.order.calculate(order);
1221
+
1222
+ expect(newOrder).toHaveProperty('total', 0);
1223
+ expect(newOrder).toHaveProperty('subTotal', 3);
1224
+ expect(newOrder).toHaveProperty('subTotals', {
1225
+ fixed: -3,
1226
+ tax: 0,
1227
+ });
1228
+ expect(newOrder.items[0]).toHaveProperty('total', 0);
1229
+ expect(newOrder.items[1]).toHaveProperty('total', 0);
1230
+ expect(newOrder.items[2]).toHaveProperty('total', 0);
1231
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1232
+ 'amount',
1233
+ -1
1234
+ );
1235
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1236
+ 'amount',
1237
+ 0
1238
+ );
1239
+
1240
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1241
+ 'amount',
1242
+ -1
1243
+ );
1244
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1245
+ 'amount',
1246
+ 0
1247
+ );
1248
+
1249
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1250
+ 'amount',
1251
+ -1
1252
+ );
1253
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1254
+ 'amount',
1255
+ 0
1256
+ );
1257
+ });
1258
+
630
1259
  test('CU-3und87h : Calculate order with 20 USD credit', () => {
631
1260
  const newOrder = pricingService.order.calculate(orderCredit);
632
1261
 
633
1262
  const [item1, item2, item3] = newOrder.items;
634
1263
  expect(newOrder).toHaveProperty('total', 12.5);
635
- expect(item1).toHaveProperty('total', 3.64);
636
- expect(item1.modifiers[1].compute).toHaveProperty('amount', 5.86);
1264
+ expect(item1).toHaveProperty('total', 3.65);
1265
+ expect(item1.modifiers[1].compute).toHaveProperty(
1266
+ 'amount',
1267
+ 5.846153846153846
1268
+ );
637
1269
 
638
- expect(item2).toHaveProperty('total', 5.39);
639
- expect(item2.modifiers[1].compute).toHaveProperty('amount', 8.61);
1270
+ expect(item2).toHaveProperty('total', 5.38);
1271
+ expect(item2.modifiers[1].compute).toHaveProperty(
1272
+ 'amount',
1273
+ 8.615384615384615
1274
+ );
640
1275
 
641
- expect(item3).toHaveProperty('total', 3.47);
642
- expect(item3.modifiers[1].compute).toHaveProperty('amount', 5.53);
1276
+ expect(item3).toHaveProperty('total', 3.46);
1277
+ expect(item3.modifiers[1].compute).toHaveProperty(
1278
+ 'amount',
1279
+ 5.538461538461538
1280
+ );
643
1281
  });
644
1282
 
645
1283
  test('Auto split a Parent Order', () => {
@@ -973,7 +1611,7 @@ describe('Order actions', () => {
973
1611
  discount: -10,
974
1612
  fee: 2,
975
1613
  });
976
- expect(newOrder.items[0]).toHaveProperty('total', 8.08);
1614
+ expect(newOrder.items[0]).toHaveProperty('total', 8.07);
977
1615
  expect(newOrder.items[1]).toHaveProperty('total', 7.71);
978
1616
  expect(newOrder.items[2]).toHaveProperty('total', 11.36);
979
1617
  expect(newOrder.items[3]).toHaveProperty('total', 7.3);
@@ -992,6 +1630,7 @@ describe('Order actions', () => {
992
1630
  modifiers: paymentModifiers,
993
1631
  order,
994
1632
  });
1633
+
995
1634
  const newOrder = pricingService.order.calculate(order);
996
1635
 
997
1636
  expect(newOrder).toHaveProperty('total', 36.45);
@@ -1000,9 +1639,422 @@ describe('Order actions', () => {
1000
1639
  discount: -10,
1001
1640
  fee: 4,
1002
1641
  });
1003
- expect(newOrder.items[0]).toHaveProperty('total', 8.06);
1004
- expect(newOrder.items[1]).toHaveProperty('total', 7.71);
1005
- expect(newOrder.items[2]).toHaveProperty('total', 11.37);
1006
- expect(newOrder.items[3]).toHaveProperty('total', 9.31);
1642
+ expect(newOrder.items[0]).toHaveProperty('total', 8.08);
1643
+ expect(newOrder.items[1]).toHaveProperty('total', 7.7);
1644
+ expect(newOrder.items[2]).toHaveProperty('total', 11.36);
1645
+ expect(newOrder.items[3]).toHaveProperty('total', 9.3);
1007
1646
  });
1647
+
1648
+ test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
1649
+ const orderItems = [
1650
+ {
1651
+ __typename: 'OrderItem',
1652
+ modifiers: [
1653
+ {
1654
+ __typename: 'Modifier',
1655
+ addModifiers: [],
1656
+ delModifiers: [],
1657
+ conditions: null,
1658
+ compute: {
1659
+ __typename: 'Compute',
1660
+ type: 'percentage',
1661
+ action: 'add',
1662
+ amount: 7.75,
1663
+ },
1664
+ _createdAt: '2023-08-22T16:30:44.899Z',
1665
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1666
+ _id: '64e4e29b9f97bb39b2c97833',
1667
+ modifierId: '63d43d0bc159330012809f6a',
1668
+ _parentId: null,
1669
+ locked: false,
1670
+ name: '7.75% Tax',
1671
+ sku: '',
1672
+ description: '',
1673
+ group: 'Tax',
1674
+ type: 'tax',
1675
+ attributes: ['sort'],
1676
+ color: '',
1677
+ backgroundColor: '',
1678
+ icon: '',
1679
+ url: '',
1680
+ tags: ['default'],
1681
+ order: 99,
1682
+ included: false,
1683
+ direct: true,
1684
+ hidden: true,
1685
+ print: true,
1686
+ required: true,
1687
+ recommended: false,
1688
+ default: false,
1689
+ code: '',
1690
+ properties: {
1691
+ sort: 99,
1692
+ },
1693
+ _computed: {
1694
+ amount: 0.42625,
1695
+ description: '7.75% Tax ($0.43)',
1696
+ },
1697
+ },
1698
+ ],
1699
+ notes: [],
1700
+ totalPaid: 0,
1701
+ status: {
1702
+ picked: {
1703
+ value: false,
1704
+ date: '',
1705
+ },
1706
+ paid: {
1707
+ value: false,
1708
+ date: '',
1709
+ },
1710
+ tracker: [],
1711
+ },
1712
+ _id: '64e4e29b9f97bb39b2c97832',
1713
+ itemId: '64d3a7632d91061420342650',
1714
+ name: 'NAPKIN CKTL SAMSARA',
1715
+ description: '',
1716
+ modifiersTotalAmount: 0,
1717
+ location: null,
1718
+ price: 5.5,
1719
+ pieces: 1,
1720
+ quantity: 1,
1721
+ path: [],
1722
+ menuId: '63d43ec012bb091db8c62f87',
1723
+ serial: null,
1724
+ sku: '025096975858',
1725
+ total: 5.93,
1726
+ subTotals: {
1727
+ _included: 0,
1728
+ _xincluded: 0.42625,
1729
+ _direct: 0.42625,
1730
+ _xdirect: 0,
1731
+ _simple: 5.5,
1732
+ _actual: 5.5,
1733
+ tax: 0.42625,
1734
+ },
1735
+ taxes: [],
1736
+ properties: false,
1737
+ },
1738
+ {
1739
+ __typename: 'OrderItem',
1740
+ modifiers: [
1741
+ {
1742
+ __typename: 'Modifier',
1743
+ addModifiers: [],
1744
+ delModifiers: [],
1745
+ conditions: null,
1746
+ compute: {
1747
+ __typename: 'Compute',
1748
+ type: 'percentage',
1749
+ action: 'add',
1750
+ amount: 7.75,
1751
+ },
1752
+ _createdAt: '2023-08-22T16:30:44.899Z',
1753
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1754
+ _id: '64e4e2939f97bb39b2c977f5',
1755
+ modifierId: '63d43d0bc159330012809f6a',
1756
+ _parentId: null,
1757
+ locked: false,
1758
+ name: '7.75% Tax',
1759
+ sku: '',
1760
+ description: '',
1761
+ group: 'Tax',
1762
+ type: 'tax',
1763
+ attributes: ['sort'],
1764
+ color: '',
1765
+ backgroundColor: '',
1766
+ icon: '',
1767
+ url: '',
1768
+ tags: ['default'],
1769
+ order: 99,
1770
+ included: false,
1771
+ direct: true,
1772
+ hidden: true,
1773
+ print: true,
1774
+ required: true,
1775
+ recommended: false,
1776
+ default: false,
1777
+ code: '',
1778
+ properties: {
1779
+ sort: 99,
1780
+ },
1781
+ _computed: {
1782
+ amount: 2.47225,
1783
+ description: '7.75% Tax ($2.47)',
1784
+ },
1785
+ },
1786
+ ],
1787
+ notes: [],
1788
+ totalPaid: 0,
1789
+ status: {
1790
+ picked: {
1791
+ value: false,
1792
+ date: '',
1793
+ },
1794
+ paid: {
1795
+ value: false,
1796
+ date: '',
1797
+ },
1798
+ tracker: [],
1799
+ },
1800
+ _id: '64e4e2939f97bb39b2c977f4',
1801
+ itemId: '64c58811c3b8118e1c2f144e',
1802
+ name: 'Boxwood Orb 2/Asst.',
1803
+ description: '',
1804
+ modifiersTotalAmount: 0,
1805
+ location: null,
1806
+ price: 15.95,
1807
+ pieces: 1,
1808
+ quantity: 2,
1809
+ path: [],
1810
+ menuId: '63d43ec012bb091db8c62f87',
1811
+ serial: null,
1812
+ sku: '023271797394',
1813
+ total: 34.37,
1814
+ subTotals: {
1815
+ _included: 0,
1816
+ _xincluded: 2.47225,
1817
+ _direct: 2.47225,
1818
+ _xdirect: 0,
1819
+ _simple: 31.9,
1820
+ _actual: 31.9,
1821
+ tax: 2.47225,
1822
+ },
1823
+ taxes: [],
1824
+ properties: false,
1825
+ },
1826
+ {
1827
+ __typename: 'OrderItem',
1828
+ modifiers: [
1829
+ {
1830
+ __typename: 'Modifier',
1831
+ addModifiers: [],
1832
+ delModifiers: [],
1833
+ conditions: null,
1834
+ compute: {
1835
+ __typename: 'Compute',
1836
+ type: 'percentage',
1837
+ action: 'add',
1838
+ amount: 7.75,
1839
+ },
1840
+ _createdAt: '2023-08-22T16:30:44.899Z',
1841
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1842
+ _id: '64e4e2879f97bb39b2c97799',
1843
+ modifierId: '63d43d0bc159330012809f6a',
1844
+ _parentId: null,
1845
+ locked: false,
1846
+ name: '7.75% Tax',
1847
+ sku: '',
1848
+ description: '',
1849
+ group: 'Tax',
1850
+ type: 'tax',
1851
+ attributes: ['sort'],
1852
+ color: '',
1853
+ backgroundColor: '',
1854
+ icon: '',
1855
+ url: '',
1856
+ tags: ['default'],
1857
+ order: 99,
1858
+ included: false,
1859
+ direct: true,
1860
+ hidden: true,
1861
+ print: true,
1862
+ required: true,
1863
+ recommended: false,
1864
+ default: false,
1865
+ code: '',
1866
+ properties: {
1867
+ sort: 99,
1868
+ },
1869
+ _computed: {
1870
+ amount: 4.495,
1871
+ description: '7.75% Tax ($4.50)',
1872
+ },
1873
+ },
1874
+ ],
1875
+ notes: [],
1876
+ totalPaid: 0,
1877
+ status: {
1878
+ picked: {
1879
+ value: false,
1880
+ date: '',
1881
+ },
1882
+ paid: {
1883
+ value: false,
1884
+ date: '',
1885
+ },
1886
+ tracker: [],
1887
+ },
1888
+ _id: '64e4e2879f97bb39b2c97798',
1889
+ itemId: '6453fce8ecba74556efe8c71',
1890
+ name: 'BASKET WILLOW MARKET',
1891
+ description: '',
1892
+ modifiersTotalAmount: 0,
1893
+ location: null,
1894
+ price: 58,
1895
+ pieces: 1,
1896
+ quantity: 1,
1897
+ path: [],
1898
+ menuId: '63d43ec012bb091db8c62f87',
1899
+ serial: null,
1900
+ sku: 'LC1900',
1901
+ total: 62.5,
1902
+ subTotals: {
1903
+ _included: 0,
1904
+ _xincluded: 4.495,
1905
+ _direct: 4.495,
1906
+ _xdirect: 0,
1907
+ _simple: 58,
1908
+ _actual: 58,
1909
+ tax: 4.495,
1910
+ },
1911
+ taxes: [],
1912
+ properties: false,
1913
+ },
1914
+ ];
1915
+
1916
+ const balanceToPay = pricingService.item.getBalanceToPay({ orderItems });
1917
+
1918
+ expect(balanceToPay).toBe(102.79);
1919
+ });
1920
+ });
1921
+
1922
+ test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
1923
+ const taxMod = {
1924
+ _id: 2,
1925
+ name: `7.75% tax`,
1926
+ type: 'tax',
1927
+ compute: {
1928
+ amount: 7.75,
1929
+ type: 'percentage',
1930
+ action: 'add',
1931
+ },
1932
+ properties: {
1933
+ sort: 2,
1934
+ },
1935
+ };
1936
+
1937
+ const discountMod = {
1938
+ _id: 1,
1939
+ compute: {
1940
+ amount: 15,
1941
+ type: 'percentage',
1942
+ action: 'subtract',
1943
+ },
1944
+ name: `15%`,
1945
+ type: 'percentage',
1946
+ properties: {
1947
+ sort: 1,
1948
+ },
1949
+ };
1950
+
1951
+ const item1 = {
1952
+ _id: 1,
1953
+ price: 35.95,
1954
+ quantity: 2,
1955
+ modifiers: [taxMod],
1956
+ };
1957
+ const item2 = {
1958
+ _id: 2,
1959
+ price: 28.95,
1960
+ quantity: 2,
1961
+ modifiers: [taxMod],
1962
+ };
1963
+ const item3 = {
1964
+ _id: 3,
1965
+ price: 17.95,
1966
+ quantity: 4,
1967
+ modifiers: [taxMod],
1968
+ };
1969
+ const item4 = {
1970
+ _id: 4,
1971
+ price: 158,
1972
+ quantity: 1,
1973
+ modifiers: [taxMod],
1974
+ };
1975
+ const item5 = {
1976
+ _id: 5,
1977
+ price: 148,
1978
+ quantity: 2,
1979
+ modifiers: [taxMod],
1980
+ };
1981
+ const item6 = {
1982
+ _id: 6,
1983
+ price: 120,
1984
+ quantity: 1,
1985
+ modifiers: [taxMod],
1986
+ };
1987
+
1988
+ const order = {
1989
+ items: [item1, item2, item3, item4, item5, item6],
1990
+ modifiers: [discountMod],
1991
+ };
1992
+
1993
+ const newOrder = pricingService.order.calculate(order);
1994
+
1995
+ expect(newOrder).toHaveProperty('total', 710.35);
1996
+ expect(newOrder).toHaveProperty('subTotal', 775.6);
1997
+ expect(newOrder).toHaveProperty('subTotals', {
1998
+ percentage: -116.34,
1999
+ tax: 51.09,
2000
+ });
2001
+ expect(newOrder.items[0]).toHaveProperty('total', 65.85);
2002
+ expect(newOrder.items[1]).toHaveProperty('total', 53.03);
2003
+ expect(newOrder.items[2]).toHaveProperty('total', 65.76);
2004
+ expect(newOrder.items[3]).toHaveProperty('total', 144.71);
2005
+ expect(newOrder.items[4]).toHaveProperty('total', 271.1);
2006
+ expect(newOrder.items[5]).toHaveProperty('total', 109.91);
2007
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2008
+ 'amount',
2009
+ -10.785
2010
+ );
2011
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
2012
+ 'amount',
2013
+ 4.7364125
2014
+ );
2015
+
2016
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
2017
+ 'amount',
2018
+ -8.685
2019
+ );
2020
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
2021
+ 'amount',
2022
+ 3.8141625
2023
+ );
2024
+
2025
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
2026
+ 'amount',
2027
+ -10.77
2028
+ );
2029
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
2030
+ 'amount',
2031
+ 4.729825
2032
+ );
2033
+
2034
+ expect(newOrder.items[3].modifiers[0]._computed).toHaveProperty(
2035
+ 'amount',
2036
+ -23.7
2037
+ );
2038
+ expect(newOrder.items[3].modifiers[1]._computed).toHaveProperty(
2039
+ 'amount',
2040
+ 10.40825
2041
+ );
2042
+
2043
+ expect(newOrder.items[4].modifiers[0]._computed).toHaveProperty(
2044
+ 'amount',
2045
+ -44.4
2046
+ );
2047
+ expect(newOrder.items[4].modifiers[1]._computed).toHaveProperty(
2048
+ 'amount',
2049
+ 19.499
2050
+ );
2051
+
2052
+ expect(newOrder.items[5].modifiers[0]._computed).toHaveProperty(
2053
+ 'amount',
2054
+ -18
2055
+ );
2056
+ expect(newOrder.items[5].modifiers[1]._computed).toHaveProperty(
2057
+ 'amount',
2058
+ 7.905
2059
+ );
1008
2060
  });