@darkpos/pricing 1.0.52 → 1.0.54
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/addIndirectModifier.test.js +3 -3
- package/__TEST__/item.test.js +28 -1
- package/__TEST__/mocks/addItemMock.js +2 -2
- package/__TEST__/mocks/order-credit.json +1 -1
- package/__TEST__/mocks/partially-paid/order-partially-paid.json +2 -2
- package/__TEST__/mocks/unpaid/order-not-paid.json +1 -1
- package/__TEST__/modifier/createIndirectModifier.test.js +26 -91
- package/__TEST__/modifier/hasModifier.test.js +2 -2
- package/__TEST__/order/order-payment-modifier.test.js +2 -2
- package/__TEST__/order/order.test.js +493 -7
- package/lib/item/addIndirectModifier.js +1 -1
- package/lib/item/calculate.js +9 -27
- package/lib/modifier/calculate.js +27 -6
- package/lib/modifier/createFeeModifier.js +1 -1
- package/lib/modifier/createIndirectModifier.js +6 -7
- package/lib/modifier/index.js +4 -2
- package/lib/modifier/isFixedSubtract.js +4 -0
- package/lib/modifier/isQuantityMultiplier.js +5 -0
- package/lib/order/calculate.js +62 -59
- package/package.json +3 -2
- package/lib/modifier/isIgnoreQuantity.js +0 -5
|
@@ -21,6 +21,9 @@ describe('Order actions', () => {
|
|
|
21
21
|
},
|
|
22
22
|
name: 'modifier1',
|
|
23
23
|
type: 'discount',
|
|
24
|
+
properties: {
|
|
25
|
+
isQuantityMultiplier: true,
|
|
26
|
+
},
|
|
24
27
|
},
|
|
25
28
|
{
|
|
26
29
|
compute: {
|
|
@@ -30,11 +33,17 @@ describe('Order actions', () => {
|
|
|
30
33
|
},
|
|
31
34
|
name: 'modifier2',
|
|
32
35
|
type: 'discount',
|
|
36
|
+
properties: {
|
|
37
|
+
isQuantityMultiplier: true,
|
|
38
|
+
},
|
|
33
39
|
},
|
|
34
40
|
{
|
|
35
41
|
compute: { amount: 2, type: 'fixed', action: 'subtract' },
|
|
36
42
|
name: 'modifier3',
|
|
37
43
|
type: 'discount',
|
|
44
|
+
properties: {
|
|
45
|
+
isQuantityMultiplier: true,
|
|
46
|
+
},
|
|
38
47
|
},
|
|
39
48
|
];
|
|
40
49
|
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
@@ -61,6 +70,9 @@ describe('Order actions', () => {
|
|
|
61
70
|
},
|
|
62
71
|
name: 'modifier1',
|
|
63
72
|
type: 'discount',
|
|
73
|
+
properties: {
|
|
74
|
+
isQuantityMultiplier: true,
|
|
75
|
+
},
|
|
64
76
|
},
|
|
65
77
|
],
|
|
66
78
|
};
|
|
@@ -107,6 +119,9 @@ describe('Order actions', () => {
|
|
|
107
119
|
},
|
|
108
120
|
name: 'modifier1',
|
|
109
121
|
type: 'discount',
|
|
122
|
+
properties: {
|
|
123
|
+
isQuantityMultiplier: true,
|
|
124
|
+
},
|
|
110
125
|
};
|
|
111
126
|
|
|
112
127
|
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
@@ -720,6 +735,7 @@ describe('Order actions', () => {
|
|
|
720
735
|
},
|
|
721
736
|
properties: {
|
|
722
737
|
sort: 99,
|
|
738
|
+
isQuantityMultiplier: true,
|
|
723
739
|
},
|
|
724
740
|
};
|
|
725
741
|
|
|
@@ -734,6 +750,7 @@ describe('Order actions', () => {
|
|
|
734
750
|
type: 'discount',
|
|
735
751
|
properties: {
|
|
736
752
|
sort: 1,
|
|
753
|
+
isQuantityMultiplier: true,
|
|
737
754
|
},
|
|
738
755
|
};
|
|
739
756
|
|
|
@@ -812,6 +829,7 @@ describe('Order actions', () => {
|
|
|
812
829
|
},
|
|
813
830
|
properties: {
|
|
814
831
|
sort: 99,
|
|
832
|
+
isQuantityMultiplier: true,
|
|
815
833
|
},
|
|
816
834
|
};
|
|
817
835
|
|
|
@@ -826,6 +844,7 @@ describe('Order actions', () => {
|
|
|
826
844
|
type: 'discount',
|
|
827
845
|
properties: {
|
|
828
846
|
sort: 1,
|
|
847
|
+
isQuantityMultiplier: true,
|
|
829
848
|
},
|
|
830
849
|
};
|
|
831
850
|
|
|
@@ -904,6 +923,7 @@ describe('Order actions', () => {
|
|
|
904
923
|
},
|
|
905
924
|
properties: {
|
|
906
925
|
sort: 99,
|
|
926
|
+
isQuantityMultiplier: true,
|
|
907
927
|
},
|
|
908
928
|
};
|
|
909
929
|
|
|
@@ -918,6 +938,7 @@ describe('Order actions', () => {
|
|
|
918
938
|
type: 'discount',
|
|
919
939
|
properties: {
|
|
920
940
|
sort: 1,
|
|
941
|
+
isQuantityMultiplier: true,
|
|
921
942
|
},
|
|
922
943
|
};
|
|
923
944
|
|
|
@@ -1006,7 +1027,7 @@ describe('Order actions', () => {
|
|
|
1006
1027
|
name: `1 USD`,
|
|
1007
1028
|
type: 'fixed',
|
|
1008
1029
|
properties: {
|
|
1009
|
-
|
|
1030
|
+
isQuantityMultiplier: false,
|
|
1010
1031
|
},
|
|
1011
1032
|
};
|
|
1012
1033
|
|
|
@@ -1085,6 +1106,7 @@ describe('Order actions', () => {
|
|
|
1085
1106
|
},
|
|
1086
1107
|
properties: {
|
|
1087
1108
|
sort: 2,
|
|
1109
|
+
isQuantityMultiplier: true,
|
|
1088
1110
|
},
|
|
1089
1111
|
};
|
|
1090
1112
|
|
|
@@ -1099,6 +1121,7 @@ describe('Order actions', () => {
|
|
|
1099
1121
|
type: 'fixed',
|
|
1100
1122
|
properties: {
|
|
1101
1123
|
sort: 1,
|
|
1124
|
+
isQuantityMultiplier: true,
|
|
1102
1125
|
},
|
|
1103
1126
|
};
|
|
1104
1127
|
|
|
@@ -1157,7 +1180,7 @@ describe('Order actions', () => {
|
|
|
1157
1180
|
|
|
1158
1181
|
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
1159
1182
|
'amount',
|
|
1160
|
-
-0.
|
|
1183
|
+
-0.3333333333333333
|
|
1161
1184
|
);
|
|
1162
1185
|
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
1163
1186
|
'amount',
|
|
@@ -1871,6 +1894,7 @@ describe('Order actions', () => {
|
|
|
1871
1894
|
},
|
|
1872
1895
|
properties: {
|
|
1873
1896
|
sort: 2,
|
|
1897
|
+
isQuantityMultiplier: true,
|
|
1874
1898
|
},
|
|
1875
1899
|
};
|
|
1876
1900
|
|
|
@@ -1885,6 +1909,7 @@ describe('Order actions', () => {
|
|
|
1885
1909
|
type: 'percentage',
|
|
1886
1910
|
properties: {
|
|
1887
1911
|
sort: 1,
|
|
1912
|
+
isQuantityMultiplier: true,
|
|
1888
1913
|
},
|
|
1889
1914
|
};
|
|
1890
1915
|
|
|
@@ -2087,7 +2112,7 @@ describe('Order actions', () => {
|
|
|
2087
2112
|
expect(newOrderFixedModifier).toHaveProperty('total', 20);
|
|
2088
2113
|
});
|
|
2089
2114
|
|
|
2090
|
-
test('CU-86dtxh2y5: #2.A- Get calculated Order, One item and fixed Fee Modifier (
|
|
2115
|
+
test('CU-86dtxh2y5: #2.A- Get calculated Order, One item and fixed Fee Modifier (isQuantityMultiplier: true)', () => {
|
|
2091
2116
|
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2092
2117
|
items: [
|
|
2093
2118
|
{
|
|
@@ -2103,6 +2128,9 @@ describe('Order actions', () => {
|
|
|
2103
2128
|
},
|
|
2104
2129
|
name: 'fee 20 USD',
|
|
2105
2130
|
type: 'fee',
|
|
2131
|
+
properties: {
|
|
2132
|
+
isQuantityMultiplier: true,
|
|
2133
|
+
},
|
|
2106
2134
|
},
|
|
2107
2135
|
],
|
|
2108
2136
|
},
|
|
@@ -2111,7 +2139,7 @@ describe('Order actions', () => {
|
|
|
2111
2139
|
expect(newOrderFixedModifier).toHaveProperty('total', 50);
|
|
2112
2140
|
});
|
|
2113
2141
|
|
|
2114
|
-
test('CU-86dtxh2y5: #2.B- Get calculated Order, One item and fixed Fee Modifier (
|
|
2142
|
+
test('CU-86dtxh2y5: #2.B- Get calculated Order, One item and fixed Fee Modifier (isQuantityMultiplier: false)', () => {
|
|
2115
2143
|
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2116
2144
|
items: [
|
|
2117
2145
|
{
|
|
@@ -2128,7 +2156,7 @@ describe('Order actions', () => {
|
|
|
2128
2156
|
name: 'fee 20 USD',
|
|
2129
2157
|
type: 'fee',
|
|
2130
2158
|
properties: {
|
|
2131
|
-
|
|
2159
|
+
isQuantityMultiplier: false,
|
|
2132
2160
|
},
|
|
2133
2161
|
},
|
|
2134
2162
|
],
|
|
@@ -2158,7 +2186,7 @@ describe('Order actions', () => {
|
|
|
2158
2186
|
expect(newOrderFixedModifier).toHaveProperty('total', 120);
|
|
2159
2187
|
});
|
|
2160
2188
|
|
|
2161
|
-
test('CU-86dtxh2y5: #4- Get calculated Order, One item and fixed Fee Modifier, using createFeeModifier (
|
|
2189
|
+
test('CU-86dtxh2y5: #4- Get calculated Order, One item and fixed Fee Modifier, using createFeeModifier (isQuantityMultiplier: false)', () => {
|
|
2162
2190
|
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2163
2191
|
items: [
|
|
2164
2192
|
{
|
|
@@ -2172,7 +2200,7 @@ describe('Order actions', () => {
|
|
|
2172
2200
|
amount: 100,
|
|
2173
2201
|
type: Types.FIXED,
|
|
2174
2202
|
properties: {
|
|
2175
|
-
|
|
2203
|
+
isQuantityMultiplier: false,
|
|
2176
2204
|
},
|
|
2177
2205
|
}),
|
|
2178
2206
|
],
|
|
@@ -2620,4 +2648,462 @@ describe('Order actions', () => {
|
|
|
2620
2648
|
_actual: 4.65,
|
|
2621
2649
|
});
|
|
2622
2650
|
});
|
|
2651
|
+
|
|
2652
|
+
test('CU-86dvd3dbp Get calculated Order, multiple items and indirect modifiers #2 toNeareastMultiple (No Order Modifiers)', () => {
|
|
2653
|
+
const pricingService2 = usePricing({
|
|
2654
|
+
store: { _settings: { localization: { nearestMultiple: '0.5' } } },
|
|
2655
|
+
});
|
|
2656
|
+
|
|
2657
|
+
const item1 = {
|
|
2658
|
+
_id: 1,
|
|
2659
|
+
price: 15.99,
|
|
2660
|
+
quantity: 1,
|
|
2661
|
+
};
|
|
2662
|
+
const item2 = {
|
|
2663
|
+
_id: 2,
|
|
2664
|
+
price: 4.65,
|
|
2665
|
+
quantity: 1,
|
|
2666
|
+
};
|
|
2667
|
+
|
|
2668
|
+
const order = { items: [item1, item2] };
|
|
2669
|
+
const newOrder = pricingService2.order.calculate(order);
|
|
2670
|
+
expect(newOrder).toHaveProperty('total', 21);
|
|
2671
|
+
expect(newOrder).toHaveProperty('subTotal', 20.64);
|
|
2672
|
+
expect(newOrder).toHaveProperty('subTotals', {});
|
|
2673
|
+
expect(newOrder.items[0]).toHaveProperty('total', 16.35);
|
|
2674
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
2675
|
+
_included: 0,
|
|
2676
|
+
_xincluded: 0,
|
|
2677
|
+
_direct: 0,
|
|
2678
|
+
_xdirect: 0,
|
|
2679
|
+
_simple: 15.99,
|
|
2680
|
+
_actual: 15.99,
|
|
2681
|
+
});
|
|
2682
|
+
expect(newOrder.items[1]).toHaveProperty('total', 4.65);
|
|
2683
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
2684
|
+
_included: 0,
|
|
2685
|
+
_xincluded: 0,
|
|
2686
|
+
_direct: 0,
|
|
2687
|
+
_xdirect: 0,
|
|
2688
|
+
_simple: 4.65,
|
|
2689
|
+
_actual: 4.65,
|
|
2690
|
+
});
|
|
2691
|
+
});
|
|
2692
|
+
test('CU-861n7pum9 - Calculate order -> discountMod percentage isIgnoreQuanity=true qt=1', () => {
|
|
2693
|
+
const discountMod = {
|
|
2694
|
+
_id: 1,
|
|
2695
|
+
compute: {
|
|
2696
|
+
amount: 50,
|
|
2697
|
+
type: 'percentage',
|
|
2698
|
+
action: 'subtract',
|
|
2699
|
+
},
|
|
2700
|
+
name: `50% discount`,
|
|
2701
|
+
type: 'discount',
|
|
2702
|
+
properties: {
|
|
2703
|
+
isQuantityMultiplier: false,
|
|
2704
|
+
},
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
const item1 = {
|
|
2708
|
+
_id: 1,
|
|
2709
|
+
price: 10,
|
|
2710
|
+
quantity: 1,
|
|
2711
|
+
modifiers: [discountMod],
|
|
2712
|
+
};
|
|
2713
|
+
|
|
2714
|
+
const order = {
|
|
2715
|
+
items: [item1],
|
|
2716
|
+
};
|
|
2717
|
+
|
|
2718
|
+
const newOrder = pricingService.order.calculate(order);
|
|
2719
|
+
|
|
2720
|
+
expect(newOrder).toHaveProperty('total', 5);
|
|
2721
|
+
expect(newOrder).toHaveProperty('subTotal', 10);
|
|
2722
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
2723
|
+
discount: -5,
|
|
2724
|
+
});
|
|
2725
|
+
expect(newOrder.items[0]).toHaveProperty('total', 5);
|
|
2726
|
+
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2727
|
+
'amount',
|
|
2728
|
+
-5
|
|
2729
|
+
);
|
|
2730
|
+
});
|
|
2731
|
+
|
|
2732
|
+
test('CU-861n7pum9 - Calculate order -> discountMod percentage isIgnoreQuanity=true qt=2', () => {
|
|
2733
|
+
const discountMod = {
|
|
2734
|
+
_id: 1,
|
|
2735
|
+
compute: {
|
|
2736
|
+
amount: 50,
|
|
2737
|
+
type: 'percentage',
|
|
2738
|
+
action: 'subtract',
|
|
2739
|
+
},
|
|
2740
|
+
name: `50% discount`,
|
|
2741
|
+
type: 'discount',
|
|
2742
|
+
properties: {
|
|
2743
|
+
isQuantityMultiplier: false,
|
|
2744
|
+
},
|
|
2745
|
+
};
|
|
2746
|
+
|
|
2747
|
+
const item1 = {
|
|
2748
|
+
_id: 1,
|
|
2749
|
+
price: 10,
|
|
2750
|
+
quantity: 2,
|
|
2751
|
+
modifiers: [discountMod],
|
|
2752
|
+
};
|
|
2753
|
+
|
|
2754
|
+
const order = {
|
|
2755
|
+
items: [item1],
|
|
2756
|
+
};
|
|
2757
|
+
|
|
2758
|
+
const newOrder = pricingService.order.calculate(order);
|
|
2759
|
+
|
|
2760
|
+
expect(newOrder).toHaveProperty('total', 15);
|
|
2761
|
+
expect(newOrder).toHaveProperty('subTotal', 20);
|
|
2762
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
2763
|
+
discount: -5,
|
|
2764
|
+
});
|
|
2765
|
+
expect(newOrder.items[0]).toHaveProperty('total', 15);
|
|
2766
|
+
expect(newOrder.items[0].modifiers[0]).toHaveProperty('_computed', {
|
|
2767
|
+
amount: -5,
|
|
2768
|
+
description: '50% discount (-$5.00)',
|
|
2769
|
+
});
|
|
2770
|
+
});
|
|
2771
|
+
test('CU-861n7pum9 - Calculate order -> discountMod100Fixed qt=1', () => {
|
|
2772
|
+
const discountMod100Fixed = {
|
|
2773
|
+
_id: 1,
|
|
2774
|
+
compute: {
|
|
2775
|
+
amount: 100,
|
|
2776
|
+
type: 'fixed',
|
|
2777
|
+
action: 'subtract',
|
|
2778
|
+
},
|
|
2779
|
+
name: `100% discount`,
|
|
2780
|
+
type: 'discount',
|
|
2781
|
+
};
|
|
2782
|
+
|
|
2783
|
+
const item1 = {
|
|
2784
|
+
_id: 1,
|
|
2785
|
+
price: 10,
|
|
2786
|
+
quantity: 1,
|
|
2787
|
+
modifiers: [discountMod100Fixed],
|
|
2788
|
+
};
|
|
2789
|
+
|
|
2790
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
2791
|
+
|
|
2792
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2793
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
2794
|
+
_actual: 10,
|
|
2795
|
+
_direct: 0,
|
|
2796
|
+
_included: 0,
|
|
2797
|
+
_simple: 10,
|
|
2798
|
+
_xdirect: -10,
|
|
2799
|
+
_xincluded: -10,
|
|
2800
|
+
discount: -10,
|
|
2801
|
+
});
|
|
2802
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2803
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
2804
|
+
amount: -10,
|
|
2805
|
+
description: '100% discount (-$10.00)',
|
|
2806
|
+
});
|
|
2807
|
+
});
|
|
2808
|
+
|
|
2809
|
+
test('CU-861n7pum9 - Calculate order -> discountMod100Fixed and discountMod100Percentage qt=1', () => {
|
|
2810
|
+
const discountMod100Fixed = {
|
|
2811
|
+
_id: 1,
|
|
2812
|
+
compute: {
|
|
2813
|
+
amount: 100,
|
|
2814
|
+
type: 'fixed',
|
|
2815
|
+
action: 'subtract',
|
|
2816
|
+
},
|
|
2817
|
+
name: `100% discount`,
|
|
2818
|
+
type: 'discount',
|
|
2819
|
+
};
|
|
2820
|
+
|
|
2821
|
+
const item1 = {
|
|
2822
|
+
_id: 1,
|
|
2823
|
+
price: 10,
|
|
2824
|
+
quantity: 1,
|
|
2825
|
+
modifiers: [discountMod100Fixed, discountMod100Fixed],
|
|
2826
|
+
};
|
|
2827
|
+
|
|
2828
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
2829
|
+
|
|
2830
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2831
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
2832
|
+
_actual: 10,
|
|
2833
|
+
_direct: 0,
|
|
2834
|
+
_included: 0,
|
|
2835
|
+
_simple: 10,
|
|
2836
|
+
_xdirect: -10,
|
|
2837
|
+
_xincluded: -10,
|
|
2838
|
+
discount: -10,
|
|
2839
|
+
});
|
|
2840
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2841
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
2842
|
+
amount: -10,
|
|
2843
|
+
description: '100% discount (-$10.00)',
|
|
2844
|
+
});
|
|
2845
|
+
|
|
2846
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
2847
|
+
amount: -0,
|
|
2848
|
+
description: '100% discount',
|
|
2849
|
+
});
|
|
2850
|
+
});
|
|
2851
|
+
|
|
2852
|
+
test('CU-861n7pum9 - Calculate order -> discountMod100Fixed qt=2', () => {
|
|
2853
|
+
const discountMod100Fixed = {
|
|
2854
|
+
_id: 1,
|
|
2855
|
+
compute: {
|
|
2856
|
+
amount: 100,
|
|
2857
|
+
type: 'fixed',
|
|
2858
|
+
action: 'subtract',
|
|
2859
|
+
},
|
|
2860
|
+
name: `100 USD discount`,
|
|
2861
|
+
type: 'discount',
|
|
2862
|
+
};
|
|
2863
|
+
|
|
2864
|
+
const item1 = {
|
|
2865
|
+
_id: 1,
|
|
2866
|
+
price: 10,
|
|
2867
|
+
quantity: 2,
|
|
2868
|
+
modifiers: [discountMod100Fixed, discountMod100Fixed],
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
2872
|
+
|
|
2873
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2874
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
2875
|
+
_actual: 20,
|
|
2876
|
+
_direct: 0,
|
|
2877
|
+
_included: 0,
|
|
2878
|
+
_simple: 20,
|
|
2879
|
+
_xdirect: -20,
|
|
2880
|
+
_xincluded: -20,
|
|
2881
|
+
discount: -20,
|
|
2882
|
+
});
|
|
2883
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2884
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
2885
|
+
amount: -20,
|
|
2886
|
+
description: '100 USD discount (-$20.00)',
|
|
2887
|
+
});
|
|
2888
|
+
|
|
2889
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
2890
|
+
amount: -0,
|
|
2891
|
+
description: '100 USD discount',
|
|
2892
|
+
});
|
|
2893
|
+
});
|
|
2894
|
+
|
|
2895
|
+
test('CU-861n7pum9 - Calculate order -> discountMod100Percentage qt=1', () => {
|
|
2896
|
+
const discountMod100Percentage = {
|
|
2897
|
+
_id: 1,
|
|
2898
|
+
compute: {
|
|
2899
|
+
amount: 100,
|
|
2900
|
+
type: 'percentage',
|
|
2901
|
+
action: 'subtract',
|
|
2902
|
+
},
|
|
2903
|
+
name: `100% discount`,
|
|
2904
|
+
type: 'discount',
|
|
2905
|
+
properties: {
|
|
2906
|
+
isQuantityMultiplier: true,
|
|
2907
|
+
},
|
|
2908
|
+
};
|
|
2909
|
+
|
|
2910
|
+
const item1 = {
|
|
2911
|
+
_id: 1,
|
|
2912
|
+
price: 10,
|
|
2913
|
+
quantity: 2,
|
|
2914
|
+
modifiers: [discountMod100Percentage, discountMod100Percentage],
|
|
2915
|
+
};
|
|
2916
|
+
|
|
2917
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
2918
|
+
|
|
2919
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2920
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
2921
|
+
_actual: 20,
|
|
2922
|
+
_direct: 0,
|
|
2923
|
+
_included: 0,
|
|
2924
|
+
_simple: 20,
|
|
2925
|
+
_xdirect: -20,
|
|
2926
|
+
_xincluded: -20,
|
|
2927
|
+
discount: -20,
|
|
2928
|
+
});
|
|
2929
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2930
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
2931
|
+
amount: -20,
|
|
2932
|
+
description: '100% discount (-$20.00)',
|
|
2933
|
+
});
|
|
2934
|
+
|
|
2935
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
2936
|
+
amount: -0,
|
|
2937
|
+
description: '100% discount',
|
|
2938
|
+
});
|
|
2939
|
+
});
|
|
2940
|
+
|
|
2941
|
+
test('CU-861n7pum9 - Calculate order -> discountMod100Percentage discountMod100Fixed qt=2', () => {
|
|
2942
|
+
const discountMod100Percentage = {
|
|
2943
|
+
_id: 1,
|
|
2944
|
+
compute: {
|
|
2945
|
+
amount: 100,
|
|
2946
|
+
type: 'percentage',
|
|
2947
|
+
action: 'subtract',
|
|
2948
|
+
},
|
|
2949
|
+
name: `100% discount`,
|
|
2950
|
+
type: 'discount',
|
|
2951
|
+
properties: {
|
|
2952
|
+
isQuantityMultiplier: true,
|
|
2953
|
+
},
|
|
2954
|
+
};
|
|
2955
|
+
|
|
2956
|
+
const discountMod100Fixed = {
|
|
2957
|
+
_id: 1,
|
|
2958
|
+
compute: {
|
|
2959
|
+
amount: 100,
|
|
2960
|
+
type: 'fixed',
|
|
2961
|
+
action: 'subtract',
|
|
2962
|
+
},
|
|
2963
|
+
name: `100 USD discount`,
|
|
2964
|
+
type: 'discount',
|
|
2965
|
+
};
|
|
2966
|
+
|
|
2967
|
+
const item1 = {
|
|
2968
|
+
_id: 1,
|
|
2969
|
+
price: 10,
|
|
2970
|
+
quantity: 2,
|
|
2971
|
+
modifiers: [
|
|
2972
|
+
discountMod100Percentage,
|
|
2973
|
+
discountMod100Fixed,
|
|
2974
|
+
discountMod100Percentage,
|
|
2975
|
+
discountMod100Fixed,
|
|
2976
|
+
],
|
|
2977
|
+
};
|
|
2978
|
+
|
|
2979
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
2980
|
+
|
|
2981
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2982
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
2983
|
+
_actual: 20,
|
|
2984
|
+
_direct: 0,
|
|
2985
|
+
_included: 0,
|
|
2986
|
+
_simple: 20,
|
|
2987
|
+
_xdirect: -20,
|
|
2988
|
+
_xincluded: -20,
|
|
2989
|
+
discount: -20,
|
|
2990
|
+
});
|
|
2991
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
2992
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
2993
|
+
amount: -20,
|
|
2994
|
+
description: '100% discount (-$20.00)',
|
|
2995
|
+
});
|
|
2996
|
+
|
|
2997
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
2998
|
+
amount: -0,
|
|
2999
|
+
description: '100 USD discount',
|
|
3000
|
+
});
|
|
3001
|
+
});
|
|
3002
|
+
|
|
3003
|
+
test('CU-861n7pum9 - Calculate order -> discountMod60Percentage discountMod100Fixed, sort, qt=2', () => {
|
|
3004
|
+
const discountMod60Percentage = {
|
|
3005
|
+
_id: 1,
|
|
3006
|
+
compute: {
|
|
3007
|
+
amount: 60,
|
|
3008
|
+
type: 'percentage',
|
|
3009
|
+
action: 'subtract',
|
|
3010
|
+
},
|
|
3011
|
+
name: `60% discount`,
|
|
3012
|
+
type: 'discount',
|
|
3013
|
+
properties: {
|
|
3014
|
+
sort: 3,
|
|
3015
|
+
isQuantityMultiplier: true,
|
|
3016
|
+
},
|
|
3017
|
+
};
|
|
3018
|
+
|
|
3019
|
+
const discountMod100Fixed = {
|
|
3020
|
+
_id: 1,
|
|
3021
|
+
compute: {
|
|
3022
|
+
amount: 100,
|
|
3023
|
+
type: 'fixed',
|
|
3024
|
+
action: 'subtract',
|
|
3025
|
+
},
|
|
3026
|
+
name: `100 USD discount`,
|
|
3027
|
+
type: 'discount',
|
|
3028
|
+
properties: {
|
|
3029
|
+
sort: 4,
|
|
3030
|
+
},
|
|
3031
|
+
};
|
|
3032
|
+
|
|
3033
|
+
const item1 = {
|
|
3034
|
+
_id: 1,
|
|
3035
|
+
price: 10,
|
|
3036
|
+
quantity: 2,
|
|
3037
|
+
modifiers: [discountMod60Percentage, discountMod100Fixed],
|
|
3038
|
+
};
|
|
3039
|
+
|
|
3040
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
3041
|
+
|
|
3042
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
3043
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
3044
|
+
_actual: 20,
|
|
3045
|
+
_direct: 0,
|
|
3046
|
+
_included: 0,
|
|
3047
|
+
_simple: 20,
|
|
3048
|
+
_xdirect: -20,
|
|
3049
|
+
_xincluded: -20,
|
|
3050
|
+
discount: -20,
|
|
3051
|
+
});
|
|
3052
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
3053
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
3054
|
+
amount: -12,
|
|
3055
|
+
description: '60% discount (-$12.00)',
|
|
3056
|
+
});
|
|
3057
|
+
|
|
3058
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
3059
|
+
amount: -8,
|
|
3060
|
+
description: '100 USD discount (-$8.00)',
|
|
3061
|
+
});
|
|
3062
|
+
});
|
|
3063
|
+
|
|
3064
|
+
test('CU-861n7pum9 - Calculate order -> discountMod9Fixed , sort, qt=2', () => {
|
|
3065
|
+
const discountMod9Fixed = {
|
|
3066
|
+
_id: 1,
|
|
3067
|
+
compute: {
|
|
3068
|
+
amount: 12,
|
|
3069
|
+
type: 'fixed',
|
|
3070
|
+
action: 'subtract',
|
|
3071
|
+
},
|
|
3072
|
+
name: `12 USD discount`,
|
|
3073
|
+
type: 'discount',
|
|
3074
|
+
properties: {
|
|
3075
|
+
isQuantityMultiplier: true,
|
|
3076
|
+
},
|
|
3077
|
+
};
|
|
3078
|
+
|
|
3079
|
+
const item1 = {
|
|
3080
|
+
_id: 1,
|
|
3081
|
+
price: 10,
|
|
3082
|
+
quantity: 2,
|
|
3083
|
+
modifiers: [discountMod9Fixed, discountMod9Fixed],
|
|
3084
|
+
};
|
|
3085
|
+
|
|
3086
|
+
const calculatedItem = pricingService.item.calculate(item1);
|
|
3087
|
+
|
|
3088
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
3089
|
+
expect(calculatedItem).toHaveProperty('subTotals', {
|
|
3090
|
+
_actual: 20,
|
|
3091
|
+
_direct: 0,
|
|
3092
|
+
_included: 0,
|
|
3093
|
+
_simple: 20,
|
|
3094
|
+
_xdirect: -20,
|
|
3095
|
+
_xincluded: -20,
|
|
3096
|
+
discount: -20,
|
|
3097
|
+
});
|
|
3098
|
+
expect(calculatedItem).toHaveProperty('total', 0);
|
|
3099
|
+
expect(calculatedItem.modifiers[0]).toHaveProperty('_computed', {
|
|
3100
|
+
amount: -20,
|
|
3101
|
+
description: '12 USD discount (-$20.00)',
|
|
3102
|
+
});
|
|
3103
|
+
|
|
3104
|
+
expect(calculatedItem.modifiers[1]).toHaveProperty('_computed', {
|
|
3105
|
+
amount: -0,
|
|
3106
|
+
description: '12 USD discount',
|
|
3107
|
+
});
|
|
3108
|
+
});
|
|
2623
3109
|
});
|