@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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
const mockStores = require('../mocks/stores');
|
|
3
|
+
|
|
4
|
+
const session = {
|
|
5
|
+
store: mockStores[0],
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const pricingService = usePricing(session);
|
|
9
|
+
|
|
10
|
+
describe('manualSplit', () => {
|
|
11
|
+
test('should split item by quantity between suborders', () => {
|
|
12
|
+
const currentOrder = { items: [{ _id: 'item1', quantity: 2 }] };
|
|
13
|
+
const subOrders = [
|
|
14
|
+
{ items: [{ _id: 'item1', quantity: 2 }] },
|
|
15
|
+
{ items: [] },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const result = pricingService.order.manualSplit(
|
|
19
|
+
{ orderIndex: 0, itemIndex: 0 },
|
|
20
|
+
1,
|
|
21
|
+
currentOrder,
|
|
22
|
+
subOrders,
|
|
23
|
+
'item1',
|
|
24
|
+
true
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(result[0].items[0].quantity).toBe(1); // Decreases quantity in original order
|
|
28
|
+
expect(result[1].items[0].quantity).toBe(1); // Adds quantity to destination
|
|
29
|
+
});
|
|
30
|
+
test('should remove item if quantity becomes zero', () => {
|
|
31
|
+
const currentOrder = { items: [{ _id: 'item1', quantity: 1 }] };
|
|
32
|
+
const subOrders = [
|
|
33
|
+
{ items: [{ _id: 'item1', quantity: 1 }] },
|
|
34
|
+
{ items: [] },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const result = pricingService.order.manualSplit(
|
|
38
|
+
{ orderIndex: 0, itemIndex: 0 },
|
|
39
|
+
1,
|
|
40
|
+
currentOrder,
|
|
41
|
+
subOrders,
|
|
42
|
+
'item1',
|
|
43
|
+
true
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(result[0].items.length).toBe(0); // Removes item from original order
|
|
47
|
+
expect(result[1].items[0].quantity).toBe(1); // Adds to destination
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('should call manualSplitByQuantity if splitQuantity is true', () => {
|
|
51
|
+
const currentOrder = { items: [{ _id: 'item1', quantity: 2 }] };
|
|
52
|
+
const subOrders = [
|
|
53
|
+
{ items: [{ _id: 'item1', quantity: 2 }] },
|
|
54
|
+
{ items: [] },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const result = pricingService.order.manualSplit(
|
|
58
|
+
{ orderIndex: 0, itemIndex: 0 },
|
|
59
|
+
1,
|
|
60
|
+
currentOrder,
|
|
61
|
+
subOrders,
|
|
62
|
+
'item1',
|
|
63
|
+
true
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(result[0].items[0].quantity).toBe(1); // Split by quantity
|
|
67
|
+
expect(result[1].items[0].quantity).toBe(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should move item to destination subOrder if splitQuantity is false', () => {
|
|
71
|
+
const currentOrder = { items: [{ _id: 'item1', quantity: 2 }] };
|
|
72
|
+
const subOrders = [
|
|
73
|
+
{ items: [{ _id: 'item1', quantity: 2 }] },
|
|
74
|
+
{ items: [] },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const result = pricingService.order.manualSplit(
|
|
78
|
+
{ orderIndex: 0, itemIndex: 0 },
|
|
79
|
+
1,
|
|
80
|
+
currentOrder,
|
|
81
|
+
subOrders,
|
|
82
|
+
'item1',
|
|
83
|
+
false
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(result[0].items.length).toBe(0); // Removes item from original suborder
|
|
87
|
+
expect(result[1].items[0]._id).toBe('item1'); // Moves item to destination
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should return subOrders unchanged if indices are invalid', () => {
|
|
91
|
+
const subOrders = [{ items: [] }, { items: [] }];
|
|
92
|
+
|
|
93
|
+
const result = pricingService.order.manualSplit(
|
|
94
|
+
{ orderIndex: null, itemIndex: null },
|
|
95
|
+
1,
|
|
96
|
+
{},
|
|
97
|
+
subOrders,
|
|
98
|
+
'item1',
|
|
99
|
+
false
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(result).toEqual(subOrders); // No change
|
|
103
|
+
});
|
|
104
|
+
});
|