@darkpos/pricing 1.0.31 → 1.0.33

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 (31) hide show
  1. package/__TEST__/item/addIndirectModifier.test.js +192 -0
  2. package/__TEST__/modifier/calculate.test.js +35 -4
  3. package/__TEST__/modifier/createIndirectModifier.test.js +166 -0
  4. package/__TEST__/modifier/getFixedModifiersTotal.test.js +52 -0
  5. package/__TEST__/modifier/getSplittedModifiers.test.js +134 -0
  6. package/__TEST__/modifier/isComputedOverride.test.js +38 -0
  7. package/__TEST__/order/addItem.test.js +57 -53
  8. package/__TEST__/order/adjustFixedModifiersDifference.test.js +117 -0
  9. package/__TEST__/order/order.test.js +47 -0
  10. package/__TEST__/order/split.test.js +356 -0
  11. package/lib/item/addIndirectModifier.js +5 -2
  12. package/lib/item/calculate.js +5 -1
  13. package/lib/item/getItemsTotalQuantity.js +7 -0
  14. package/lib/item/getItemsTotalWeight.js +7 -0
  15. package/lib/item/getTotalPieces.js +1 -1
  16. package/lib/item/getTotalQuantity.js +5 -0
  17. package/lib/item/getTotalWeight.js +7 -0
  18. package/lib/item/index.js +8 -0
  19. package/lib/modifier/calculate.js +5 -2
  20. package/lib/modifier/createIndirectModifier.js +4 -3
  21. package/lib/modifier/getFixedModifiersTotal.js +5 -4
  22. package/lib/modifier/getSplittedModifiers.js +5 -7
  23. package/lib/modifier/index.js +0 -2
  24. package/lib/modifier/isComputedOverride.js +3 -2
  25. package/lib/modifier/utils.js +10 -0
  26. package/lib/order/addItemModifier.js +9 -4
  27. package/lib/order/addModifier.js +6 -4
  28. package/lib/order/adjustFixedModifiersDifference.js +10 -9
  29. package/lib/order/splitByDepartments.js +37 -7
  30. package/package.json +2 -2
  31. package/lib/modifier/includePiecesInQuantity.js +0 -10
@@ -10,7 +10,7 @@ const pricingService = usePricing(session);
10
10
 
11
11
  describe('addItem function', () => {
12
12
  test('should add a new item to an empty order', () => {
13
- const addItem = pricingService.order.addItem;
13
+ const { addItem } = pricingService.order;
14
14
 
15
15
  // Mock an empty order
16
16
  const order = {
@@ -44,7 +44,7 @@ describe('addItem function', () => {
44
44
  });
45
45
 
46
46
  test('should combine with an existing item if aggregation is enabled', () => {
47
- const addItem = pricingService.order.addItem;
47
+ const { addItem } = pricingService.order;
48
48
 
49
49
  // Mock order with one existing item
50
50
  const order = {
@@ -83,7 +83,7 @@ describe('addItem function', () => {
83
83
  });
84
84
 
85
85
  test('should add item with overridden quantity', () => {
86
- const addItem = pricingService.order.addItem;
86
+ const { addItem } = pricingService.order;
87
87
 
88
88
  // Mock order with one existing item
89
89
  const order = {
@@ -99,7 +99,7 @@ describe('addItem function', () => {
99
99
  };
100
100
 
101
101
  // Call the function with an overridden quantity
102
- const [updatedOrder, itemIndex, addedItem] = addItem({
102
+ const [updatedOrder, , addedItem] = addItem({
103
103
  order,
104
104
  item,
105
105
  itemIndex: -1, // Assuming no explicit index
@@ -114,7 +114,7 @@ describe('addItem function', () => {
114
114
  });
115
115
 
116
116
  test('should handle adding an item with modifiers', () => {
117
- const addItem = pricingService.order.addItem;
117
+ const { addItem } = pricingService.order;
118
118
 
119
119
  // Mock order with one existing item
120
120
  const order = {
@@ -128,70 +128,74 @@ describe('addItem function', () => {
128
128
  price: 150,
129
129
  modifiers: [
130
130
  {
131
- "_id": "66cdf18a1e48455e128a4f63",
132
- "modifierId": 'mod1',
133
- "_parentId": null,
134
- "name": null,
135
- "sku": null,
136
- "description": null,
137
- "group": null,
138
- "type": null,
139
- "attributes": [],
140
- "color": null,
141
- "backgroundColor": null,
142
- "icon": null,
143
- "url": null,
144
- "tags": [],
145
- "order": null,
146
- "included": false,
147
- "direct": true,
148
- "hidden": false,
149
- "required": false,
150
- "code": null,
151
- "properties": null,
152
- "_computed": null
131
+ _id: '66cdf18a1e48455e128a4f63',
132
+ modifierId: 'mod1',
133
+ _parentId: null,
134
+ name: null,
135
+ sku: null,
136
+ description: null,
137
+ group: null,
138
+ type: null,
139
+ attributes: [],
140
+ color: null,
141
+ backgroundColor: null,
142
+ icon: null,
143
+ url: null,
144
+ tags: [],
145
+ order: null,
146
+ included: false,
147
+ direct: true,
148
+ hidden: false,
149
+ required: false,
150
+ code: null,
151
+ properties: null,
152
+ _computed: null,
153
153
  },
154
154
  {
155
- "_id": "66cdf18a1e48455e128a4f64",
156
- "modifierId": 'mod2',
157
- "_parentId": null,
158
- "name": null,
159
- "sku": null,
160
- "description": null,
161
- "group": null,
162
- "type": null,
163
- "attributes": [],
164
- "color": null,
165
- "backgroundColor": null,
166
- "icon": null,
167
- "url": null,
168
- "tags": [],
169
- "order": null,
170
- "included": false,
171
- "direct": true,
172
- "hidden": false,
173
- "required": false,
174
- "code": null,
175
- "properties": null,
176
- "_computed": null
155
+ _id: '66cdf18a1e48455e128a4f64',
156
+ modifierId: 'mod2',
157
+ _parentId: null,
158
+ name: null,
159
+ sku: null,
160
+ description: null,
161
+ group: null,
162
+ type: null,
163
+ attributes: [],
164
+ color: null,
165
+ backgroundColor: null,
166
+ icon: null,
167
+ url: null,
168
+ tags: [],
169
+ order: null,
170
+ included: false,
171
+ direct: true,
172
+ hidden: false,
173
+ required: false,
174
+ code: null,
175
+ properties: null,
176
+ _computed: null,
177
177
  },
178
178
  ],
179
179
  };
180
180
 
181
181
  // Call the function
182
- const [updatedOrder, itemIndex, addedItem] = addItem({
182
+ const [updatedOrder] = addItem({
183
183
  order,
184
184
  item,
185
185
  itemIndex: -1, // Assuming no explicit index
186
186
  cache: addItemObj.cache, // Assuming some cache object
187
187
  overridenQuantity: -1, // No overridden quantity
188
188
  });
189
-
189
+
190
190
  // Assertions
191
191
  expect(updatedOrder.items).toHaveLength(1); // Should have one item
192
192
  expect(updatedOrder.items[0].modifiers).toHaveLength(2); // Item should have two modifiers
193
- expect(updatedOrder.items[0].modifiers[0].modifierId).toBe('66cdf18a1e48455e128a4f63'); // Check first modifier
194
- expect(updatedOrder.items[0].modifiers[1].modifierId).toBe('66cdf18a1e48455e128a4f64'); // Check second modifier
193
+ expect(updatedOrder.items[0].modifiers[0].modifierId).toBe(
194
+ '66cdf18a1e48455e128a4f63'
195
+ ); // Check first modifier
196
+ expect(updatedOrder.items[0].modifiers[1].modifierId).toBe(
197
+ '66cdf18a1e48455e128a4f64'
198
+ ); // Check second modifier
195
199
  expect(updatedOrder.items[0].modifiers).toHaveLength(2); // Added item should have modifiers
196
200
  });
197
201
  });
@@ -0,0 +1,117 @@
1
+ const adjustFixedModifiersDifferenceFunction = require('../../lib/order/adjustFixedModifiersDifference');
2
+
3
+ describe('adjustFixedModifiersDifference Function', () => {
4
+ const math = {
5
+ add: jest.fn(),
6
+ };
7
+ const _ = {
8
+ get: jest.fn(),
9
+ };
10
+ const actions = {
11
+ isOpen: jest.fn(),
12
+ calculate: jest.fn(),
13
+ };
14
+
15
+ const modifierActions = {
16
+ hasFixedModifier: jest.fn(),
17
+ };
18
+
19
+ const getComputeModField = jest.fn();
20
+
21
+ const adjustFixedModifiersDifference = adjustFixedModifiersDifferenceFunction(
22
+ {
23
+ utils: { math },
24
+ actions,
25
+ modifierActions,
26
+ _,
27
+ }
28
+ );
29
+
30
+ beforeEach(() => {
31
+ jest.clearAllMocks();
32
+ });
33
+
34
+ test('should adjust the fixed modifier for a suitable subOrder', () => {
35
+ const subOrders = [
36
+ { id: 'subOrder1', total: 100, modifiers: [] },
37
+ {
38
+ id: 'subOrder2',
39
+ total: 200,
40
+ modifiers: [{ compute: { type: 'fixed', amount: 50 } }],
41
+ },
42
+ ];
43
+ const difference = 20;
44
+
45
+ modifierActions.hasFixedModifier
46
+ .mockReturnValueOnce(false)
47
+ .mockReturnValueOnce(true);
48
+ actions.isOpen.mockReturnValueOnce(true);
49
+ getComputeModField.mockReturnValueOnce({ compute: { amount: 50 } });
50
+ math.add.mockReturnValueOnce(70);
51
+ actions.calculate.mockReturnValueOnce({
52
+ id: 'subOrder2',
53
+ total: 200,
54
+ modifiers: [{ compute: { type: 'fixed', amount: 70 } }],
55
+ });
56
+ _.get.mockReturnValueOnce(50);
57
+
58
+ const result = adjustFixedModifiersDifference({ subOrders, difference });
59
+
60
+ expect(result).toEqual([
61
+ { id: 'subOrder1', total: 100, modifiers: [] },
62
+ {
63
+ id: 'subOrder2',
64
+ total: 200,
65
+ modifiers: [{ compute: { type: 'fixed', amount: 70 } }],
66
+ },
67
+ ]);
68
+
69
+ expect(math.add).toHaveBeenCalledWith(50, difference);
70
+ });
71
+
72
+ test('should not adjust if no suitable subOrder is found', () => {
73
+ const subOrders = [
74
+ {
75
+ id: 'subOrder1',
76
+ total: 100,
77
+ modifiers: [{ compute: { type: 'fixed', amount: 50 } }],
78
+ },
79
+ { id: 'subOrder2', total: 50, modifiers: [] },
80
+ ];
81
+ const difference = 200;
82
+
83
+ modifierActions.hasFixedModifier
84
+ .mockReturnValueOnce(true)
85
+ .mockReturnValueOnce(false);
86
+ actions.isOpen.mockReturnValueOnce(true).mockReturnValueOnce(true);
87
+
88
+ const result = adjustFixedModifiersDifference({ subOrders, difference });
89
+
90
+ expect(result).toEqual(subOrders);
91
+ expect(math.add).not.toHaveBeenCalled();
92
+ expect(actions.calculate).not.toHaveBeenCalled();
93
+ });
94
+
95
+ test('should not adjust if no suitable subOrder is found and compute is null', () => {
96
+ const subOrders = [
97
+ {
98
+ id: 'subOrder1',
99
+ total: 100,
100
+ modifiers: [{ compute: null }],
101
+ },
102
+ { id: 'subOrder2', total: 50, modifiers: [] },
103
+ ];
104
+ const difference = 200;
105
+
106
+ modifierActions.hasFixedModifier
107
+ .mockReturnValueOnce(true)
108
+ .mockReturnValueOnce(false);
109
+ actions.isOpen.mockReturnValueOnce(true).mockReturnValueOnce(true);
110
+
111
+ const result = adjustFixedModifiersDifference({ subOrders, difference });
112
+
113
+ expect(result).toEqual(subOrders);
114
+ expect(math.add).not.toHaveBeenCalled();
115
+ expect(actions.calculate).not.toHaveBeenCalled();
116
+ });
117
+ });
@@ -2240,4 +2240,51 @@ describe('Order actions', () => {
2240
2240
 
2241
2241
  expect(newOrderFixedModifier).toHaveProperty('total', 120);
2242
2242
  });
2243
+
2244
+ test('Get calculated Order, multiple items and indirect modifiers and null compute', () => {
2245
+ const item1 = {
2246
+ _id: 1,
2247
+ price: 30,
2248
+ quantity: 2,
2249
+ };
2250
+ const item2 = {
2251
+ _id: 2,
2252
+ price: 10,
2253
+ quantity: 1,
2254
+ };
2255
+ const modifier1 = {
2256
+ compute: null,
2257
+ name: 'modifier1',
2258
+ type: 'discount',
2259
+ };
2260
+
2261
+ const order = { items: [item1, item2], modifiers: [modifier1] };
2262
+
2263
+ const newOrder = pricingService.order.calculate(order);
2264
+ expect(newOrder).toHaveProperty('total', 70);
2265
+ expect(newOrder).toHaveProperty('subTotal', 70);
2266
+ expect(newOrder).toHaveProperty('subTotals', {
2267
+ discount: 0,
2268
+ });
2269
+ expect(newOrder.items[0]).toHaveProperty('total', 60);
2270
+ expect(newOrder.items[0]).toHaveProperty('subTotals', {
2271
+ discount: 0,
2272
+ _included: 0,
2273
+ _xincluded: 0,
2274
+ _direct: 0,
2275
+ _xdirect: 0,
2276
+ _simple: 60,
2277
+ _actual: 60,
2278
+ });
2279
+ expect(newOrder.items[1]).toHaveProperty('total', 10);
2280
+ expect(newOrder.items[1]).toHaveProperty('subTotals', {
2281
+ discount: 0,
2282
+ _included: 0,
2283
+ _xincluded: 0,
2284
+ _direct: 0,
2285
+ _xdirect: 0,
2286
+ _simple: 10,
2287
+ _actual: 10,
2288
+ });
2289
+ });
2243
2290
  });
@@ -0,0 +1,356 @@
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
+ const dryCleaningModNoAutoSplit = {
11
+ name: 'Dry Cleaning',
12
+ attributes: ['department'],
13
+ code: 'D',
14
+ _id: '66d89d9b4f04f9eb99666483',
15
+ };
16
+
17
+ const laundryModNoAutoSplit = {
18
+ name: 'Laundry',
19
+ attributes: ['department'],
20
+ code: 'L',
21
+ _id: '66d89d9b4f04f9eb99666487',
22
+ };
23
+
24
+ const tailorinModNoAutoSplit = {
25
+ name: 'Tailoring',
26
+ attributes: ['department'],
27
+ code: 'T',
28
+ _id: '66d89d9b4f04f9eb99666484',
29
+ };
30
+
31
+ describe('Auto Split', () => {
32
+ test('Auto split only by department', () => {
33
+ const { autoSplit } = pricingService.order;
34
+
35
+ // Mock item to compare
36
+ const item1 = {
37
+ _id: '123',
38
+ itemId: '234',
39
+ modifiers: [laundryModNoAutoSplit],
40
+ };
41
+
42
+ const item2 = {
43
+ _id: '123',
44
+ itemId: '234',
45
+ modifiers: [dryCleaningModNoAutoSplit],
46
+ };
47
+
48
+ const item3 = {
49
+ _id: '567',
50
+ itemId: '567',
51
+ modifiers: [tailorinModNoAutoSplit],
52
+ quantity: 1000,
53
+ pieces: 2,
54
+ };
55
+
56
+ const item4 = {
57
+ _id: '444',
58
+ itemId: '444',
59
+ quantity: 1000,
60
+ modifiers: [tailorinModNoAutoSplit],
61
+ pieces: 2,
62
+ };
63
+
64
+ const subOrders = autoSplit({
65
+ parentOrder: {
66
+ items: [item1, item2, item3, item4],
67
+ status: {},
68
+ modifiers: [],
69
+ displayId: 1,
70
+ },
71
+ });
72
+
73
+ expect(subOrders.length).toEqual(3);
74
+ });
75
+
76
+ test('Auto split by department and Items Quantity', () => {
77
+ const { autoSplit } = pricingService.order;
78
+
79
+ const laundryModMaxItemsQuantity4 = {
80
+ ...laundryModNoAutoSplit,
81
+ properties: {
82
+ department: { autoSplit: true, maxItems: 2, splitUnit: 'quantity' },
83
+ },
84
+ };
85
+
86
+ // Mock item to compare
87
+ const item1 = {
88
+ _id: '123',
89
+ itemId: '234',
90
+ modifiers: [laundryModMaxItemsQuantity4],
91
+ quantity: 5,
92
+ pieces: 4,
93
+ };
94
+
95
+ const item2 = {
96
+ _id: '123',
97
+ itemId: '234',
98
+ modifiers: [laundryModMaxItemsQuantity4],
99
+ quantity: 5,
100
+ pieces: 4,
101
+ };
102
+
103
+ const item3 = {
104
+ _id: '567',
105
+ itemId: '567',
106
+ modifiers: [dryCleaningModNoAutoSplit],
107
+ quantity: 1000,
108
+ pieces: 2,
109
+ };
110
+
111
+ const item4 = {
112
+ _id: '444',
113
+ itemId: '444',
114
+ quantity: 1000,
115
+ modifiers: [tailorinModNoAutoSplit],
116
+ pieces: 2,
117
+ };
118
+
119
+ const subOrders = autoSplit({
120
+ parentOrder: {
121
+ items: [item1, item2, item3, item4],
122
+ status: {},
123
+ modifiers: [],
124
+ displayId: 1,
125
+ },
126
+ });
127
+
128
+ expect(subOrders.length).toEqual(7);
129
+ });
130
+
131
+ test('Auto split by department and Items Pieces', () => {
132
+ const { autoSplit } = pricingService.order;
133
+
134
+ const laundryModMaxItemsQuantity4 = {
135
+ ...laundryModNoAutoSplit,
136
+ properties: {
137
+ department: { autoSplit: true, maxItems: 2, splitUnit: 'pieces' },
138
+ },
139
+ };
140
+
141
+ // Mock item to compare
142
+ const item1 = {
143
+ _id: '123',
144
+ itemId: '234',
145
+ modifiers: [laundryModMaxItemsQuantity4],
146
+ quantity: 5,
147
+ pieces: 2,
148
+ };
149
+
150
+ const item2 = {
151
+ _id: '123',
152
+ itemId: '234',
153
+ modifiers: [laundryModMaxItemsQuantity4],
154
+ quantity: 5,
155
+ pieces: 2,
156
+ };
157
+
158
+ const item3 = {
159
+ _id: '567',
160
+ itemId: '567',
161
+ modifiers: [dryCleaningModNoAutoSplit],
162
+ quantity: 1000,
163
+ pieces: 2,
164
+ };
165
+
166
+ const item4 = {
167
+ _id: '444',
168
+ itemId: '444',
169
+ quantity: 1000,
170
+ modifiers: [tailorinModNoAutoSplit],
171
+ pieces: 2,
172
+ };
173
+
174
+ const subOrders = autoSplit({
175
+ parentOrder: {
176
+ items: [item1, item2, item3, item4],
177
+ status: {},
178
+ modifiers: [],
179
+ displayId: 1,
180
+ },
181
+ });
182
+
183
+ expect(subOrders.length).toEqual(12);
184
+ });
185
+
186
+ test('Auto split by department and Items Pieces 2', () => {
187
+ const { autoSplit } = pricingService.order;
188
+
189
+ const laundryModMaxItemsQuantity4 = {
190
+ ...laundryModNoAutoSplit,
191
+ properties: {
192
+ department: { autoSplit: true, maxItems: 6, splitUnit: 'pieces' },
193
+ },
194
+ };
195
+
196
+ const item1 = {
197
+ _id: '123',
198
+ itemId: '234',
199
+ modifiers: [laundryModMaxItemsQuantity4],
200
+ quantity: 10,
201
+ pieces: 2,
202
+ };
203
+
204
+ const subOrders = autoSplit({
205
+ parentOrder: {
206
+ items: [item1],
207
+ status: {},
208
+ modifiers: [],
209
+ displayId: 1,
210
+ },
211
+ });
212
+
213
+ expect(subOrders.length).toEqual(4);
214
+ expect(subOrders[0].items[0].quantity).toEqual(3);
215
+ expect(subOrders[1].items[0].quantity).toEqual(3);
216
+ expect(subOrders[2].items[0].quantity).toEqual(3);
217
+ expect(subOrders[3].items[0].quantity).toEqual(1);
218
+ });
219
+
220
+ test('Auto split by department and Items Pieces 3', () => {
221
+ const { autoSplit } = pricingService.order;
222
+
223
+ const laundryModMaxItemsQuantity4 = {
224
+ ...laundryModNoAutoSplit,
225
+ properties: {
226
+ department: { autoSplit: true, maxItems: 6, splitUnit: 'pieces' },
227
+ },
228
+ };
229
+
230
+ const item1 = {
231
+ _id: '123',
232
+ itemId: '234',
233
+ modifiers: [laundryModMaxItemsQuantity4],
234
+ quantity: 10,
235
+ pieces: 2,
236
+ };
237
+
238
+ const item2 = {
239
+ _id: '123',
240
+ itemId: '234',
241
+ modifiers: [tailorinModNoAutoSplit],
242
+ quantity: 5,
243
+ pieces: 2,
244
+ };
245
+
246
+ const item3 = {
247
+ _id: '567',
248
+ itemId: '567',
249
+ modifiers: [dryCleaningModNoAutoSplit],
250
+ quantity: 1000,
251
+ pieces: 2,
252
+ };
253
+
254
+ const subOrders = autoSplit({
255
+ parentOrder: {
256
+ items: [item1, item2, item3],
257
+ status: {},
258
+ modifiers: [],
259
+ displayId: 1,
260
+ },
261
+ });
262
+
263
+ expect(subOrders.length).toEqual(6);
264
+ expect(subOrders[0].items[0].quantity).toEqual(3);
265
+ expect(subOrders[1].items[0].quantity).toEqual(3);
266
+ expect(subOrders[2].items[0].quantity).toEqual(3);
267
+ expect(subOrders[3].items[0].quantity).toEqual(1);
268
+ expect(subOrders[4].items[0].quantity).toEqual(5);
269
+ expect(subOrders[5].items[0].quantity).toEqual(1000);
270
+ });
271
+
272
+ test('Auto split by department and Items Weight', () => {
273
+ const { autoSplit } = pricingService.order;
274
+
275
+ const laundryModMaxItems = {
276
+ ...laundryModNoAutoSplit,
277
+ properties: {
278
+ department: {
279
+ autoSplit: true,
280
+ maxItems: 100,
281
+ splitUnit: 'weight',
282
+ },
283
+ },
284
+ };
285
+
286
+ const item1 = {
287
+ _id: '123',
288
+ itemId: '234',
289
+ modifiers: [laundryModMaxItems],
290
+ quantity: 10,
291
+ pieces: 2,
292
+ weight: 30,
293
+ };
294
+
295
+ const subOrders = autoSplit({
296
+ parentOrder: {
297
+ items: [item1],
298
+ status: {},
299
+ modifiers: [],
300
+ displayId: 1,
301
+ },
302
+ });
303
+
304
+ expect(subOrders.length).toEqual(4);
305
+ expect(subOrders[0].items[0].quantity).toEqual(3);
306
+ expect(subOrders[1].items[0].quantity).toEqual(3);
307
+ expect(subOrders[2].items[0].quantity).toEqual(3);
308
+ expect(subOrders[3].items[0].quantity).toEqual(1);
309
+ });
310
+
311
+ test('Auto split by department and Items Weight 2', () => {
312
+ const { autoSplit } = pricingService.order;
313
+
314
+ const laundryModMaxItems = {
315
+ ...laundryModNoAutoSplit,
316
+ properties: {
317
+ department: {
318
+ autoSplit: true,
319
+ maxItems: 25,
320
+ splitUnit: 'weight',
321
+ },
322
+ },
323
+ };
324
+
325
+ const item1 = {
326
+ _id: '123',
327
+ itemId: '234',
328
+ modifiers: [laundryModMaxItems],
329
+ quantity: 1,
330
+ pieces: 2,
331
+ weight: 25,
332
+ };
333
+
334
+ const item2 = {
335
+ _id: '322',
336
+ itemId: '4555',
337
+ modifiers: [laundryModMaxItems],
338
+ quantity: 1,
339
+ pieces: 2,
340
+ weight: 25,
341
+ };
342
+
343
+ const subOrders = autoSplit({
344
+ parentOrder: {
345
+ items: [item1, item2],
346
+ status: {},
347
+ modifiers: [],
348
+ displayId: 1,
349
+ },
350
+ });
351
+
352
+ expect(subOrders.length).toEqual(2);
353
+ expect(subOrders[0].items[0].quantity).toEqual(1);
354
+ expect(subOrders[1].items[0].quantity).toEqual(1);
355
+ });
356
+ });
@@ -1,4 +1,5 @@
1
- module.exports = ({ utils, modifierActions }) => {
1
+ module.exports = ({ utils, modifierActions, _ }) => {
2
+ const { getComputeModField } = require('../modifier/utils');
2
3
  const { math } = utils;
3
4
 
4
5
  return function addIndirectModifier({ orderTotal, items, modifier }) {
@@ -25,7 +26,9 @@ module.exports = ({ utils, modifierActions }) => {
25
26
  );
26
27
  }, 0);
27
28
 
28
- if (modifier.compute.type === 'percentage' && modifier.type !== 'credit')
29
+ const modifierType = _.get(modifier, 'modifier.type', '');
30
+ const computeField = getComputeModField(modifier);
31
+ if (computeField.type === 'percentage' && modifierType !== 'credit')
29
32
  return itemsModifiers;
30
33
 
31
34
  if (math.abs(totalDistributed) !== math.abs(orderModifierTotal)) {