@darkpos/pricing 1.0.112 → 1.0.115

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.
@@ -8,1689 +8,1962 @@ const session = {
8
8
  const pricingService = usePricing(session);
9
9
 
10
10
  describe('Item actions', () => {
11
- test('Get calculated Item: included: false && direct: false', () => {
12
- const modifiers = [
13
- {
14
- _id: 1111,
15
- compute: {
16
- amount: 20,
17
- type: 'percentage',
18
- action: 'add',
19
- },
20
- name: 'modifier1',
21
- type: 'discount',
22
- direct: false,
23
- included: false,
24
- properties: {
25
- isQuantityMultiplier: true,
26
- },
27
- },
28
- {
29
- _id: 2222,
30
- compute: {
31
- amount: 20,
32
- type: 'percentage',
33
- action: 'subtract',
34
- },
35
- name: 'modifier2',
36
- type: 'discount',
37
- direct: false,
38
- included: false,
39
- properties: {
40
- isQuantityMultiplier: true,
41
- },
42
- },
43
- {
44
- _id: 3333,
45
- compute: {
46
- amount: 2,
47
- type: 'fixed',
48
- action: 'subtract',
49
- },
50
- name: 'modifier3',
51
- type: 'discount',
52
- direct: false,
53
- included: false,
54
- properties: {
55
- isQuantityMultiplier: true,
56
- },
57
- },
58
- ];
59
- const orderItem = { price: 30, quantity: 2, modifiers };
60
- const newItem = pricingService.item.calculate(orderItem);
61
- expect(newItem).toHaveProperty('total', 56);
62
- expect(newItem).toHaveProperty('subTotals', {
63
- discount: -4,
64
- _included: 0,
65
- _xincluded: -4,
66
- _direct: 0,
67
- _xdirect: -4,
68
- _simple: 60,
69
- _actual: 60,
70
- });
71
- });
72
- test('Get calculated Item: included: false && direct: true', () => {
73
- const modifiers = [
74
- {
75
- _id: '123213213',
76
- compute: { amount: 2, type: 'fixed', action: 'subtract' },
77
- type: 'discount',
78
- name: 'modifier1',
79
- direct: true,
80
- included: false,
81
- properties: {
82
- isQuantityMultiplier: true,
83
- },
84
- },
85
- {
86
- _id: '22222',
87
- compute: {
88
- amount: 20,
89
- type: 'percentage',
90
- action: 'subtract',
91
- },
92
- name: 'modifier2',
93
- type: 'discount',
94
- direct: true,
95
- included: false,
96
- properties: {
97
- isQuantityMultiplier: true,
98
- },
99
- },
100
- {
101
- _id: '3333',
102
- compute: {
103
- amount: 2,
104
- type: 'fixed',
105
- action: 'add',
106
- },
107
- name: 'modifier3',
108
- type: 'tax',
109
- direct: true,
110
- included: false,
111
- properties: {
112
- isQuantityMultiplier: true,
113
- },
114
- },
115
- ];
116
- const orderItem = { price: 30, quantity: 2, modifiers };
117
- const newItem = pricingService.item.calculate(orderItem);
118
- expect(newItem).toHaveProperty('total', 48);
119
- expect(newItem).toHaveProperty('subTotals', {
120
- discount: -16,
121
- tax: 4,
122
- _included: 0,
123
- _xincluded: -12,
124
- _direct: -12,
125
- _xdirect: 0,
126
- _simple: 60,
127
- _actual: 60,
128
- });
129
- });
130
- test('Get calculated Item: included: true && direct: true', () => {
131
- const modifiers = [
132
- {
133
- _id: '111111',
134
- compute: {
135
- amount: 2,
136
- type: 'fixed',
137
- action: 'subtract',
138
- },
139
- name: 'modifier1',
140
- type: 'discount',
141
- direct: true,
142
- included: true,
143
- properties: {
144
- isQuantityMultiplier: true,
145
- },
146
- },
147
- {
148
- _id: '222222',
149
-
150
- compute: {
151
- amount: 20,
152
- type: 'percentage',
153
- action: 'subtract',
154
- },
155
- name: 'modifier2',
156
- type: 'discount',
157
- direct: true,
158
- included: true,
159
- properties: {
160
- isQuantityMultiplier: true,
161
- },
162
- },
163
- {
164
- _id: '33333',
165
-
166
- compute: {
167
- amount: 2,
168
- type: 'fixed',
169
- action: 'add',
170
- },
171
- name: 'modifier3',
172
- type: 'upcharge',
173
- direct: true,
174
- included: true,
175
- properties: {
176
- isQuantityMultiplier: true,
177
- },
178
- },
179
- ];
180
- const orderItem = { price: 30, quantity: 2, modifiers };
181
- const newItem = pricingService.item.calculate(orderItem);
182
- expect(newItem).toHaveProperty('total', 48);
183
- expect(newItem).toHaveProperty('subTotals', {
184
- _included: -12,
185
- _xincluded: 0,
186
- _direct: -12,
187
- _xdirect: 0,
188
- _simple: 60,
189
- _actual: 48,
190
- });
191
- });
192
- test('Get calculated Item: included: true, sample 1', () => {
193
- const modifiers = [
194
- {
195
- compute: {
196
- amount: 2,
197
- type: 'fixed',
198
- action: 'add',
199
- },
200
- name: 'modifier1',
201
- type: 'upcharge',
202
- included: true,
203
- direct: true,
204
- },
205
- ];
206
- const orderItem = { price: 2, quantity: 1, modifiers };
207
- const newItem = pricingService.item.calculate(orderItem);
208
- expect(newItem).toHaveProperty('total', 4);
209
- expect(newItem).toHaveProperty('subTotals', {
210
- _included: 2,
211
- _xincluded: 0,
212
- _direct: 2,
213
- _xdirect: 0,
214
- _simple: 2,
215
- _actual: 4,
216
- });
217
- });
218
- test('Get calculated Item: included: true, sample 2', () => {
219
- const modifiers = [
220
- {
221
- compute: { amount: 2, type: 'fixed', action: 'add' },
222
- name: 'modifier1',
223
- type: 'upcharge',
224
- included: true,
225
- direct: true,
226
- properties: {
227
- sort: 1,
228
- },
229
- _id: '1255115',
230
- },
231
- {
232
- compute: {
233
- amount: 10,
234
- type: 'percentage',
235
- action: 'add',
236
- },
237
- name: 'modifier2',
238
- type: 'tax',
239
- properties: {
240
- sort: 2,
241
- },
242
- included: true,
243
- direct: true,
244
- _id: '2256659',
245
- },
246
- ];
247
- const orderItem = { price: 2, quantity: 1, modifiers };
248
- const newItem = pricingService.item.calculate(orderItem);
249
- expect(newItem).toHaveProperty('total', 4.4);
250
- expect(newItem).toHaveProperty('subTotals', {
251
- _included: 2.4,
252
- _xincluded: 0,
253
- _direct: 2.4,
254
- _xdirect: 0,
255
- _simple: 2,
256
- _actual: 4.4,
257
- });
258
- });
259
- test('Get calculated Item: included: true, sample 3', () => {
260
- const modifiers = [
261
- {
262
- _id: 12323,
263
- compute: {
264
- amount: 2,
265
- type: 'fixed',
266
- action: 'subtract',
267
- },
268
- name: 'modifier1',
269
- type: 'discount',
270
- properties: {
271
- sort: 1,
272
- },
273
- included: true,
274
- direct: true,
275
- },
276
- {
277
- _id: 5555,
278
- compute: {
279
- amount: 2,
280
- type: 'fixed',
281
- action: 'add',
282
- },
283
- name: 'modifier1',
284
- type: 'upcharge',
285
- included: true,
286
- direct: true,
287
- properties: {
288
- sort: 1,
289
- },
290
- },
291
- {
292
- _id: 77777,
293
- compute: {
294
- amount: 10,
295
- type: 'percentage',
296
- action: 'add',
297
- },
298
- name: 'modifier2',
299
- type: 'tax',
300
- properties: {
301
- sort: 2,
302
- },
303
- included: true,
304
- direct: true,
305
- },
306
- {
307
- _id: 8888,
308
- compute: {
309
- amount: 6,
310
- type: 'percentage',
311
- action: 'add',
312
- },
313
- name: 'modifier3',
314
- type: 'tax',
315
- properties: {
316
- sort: 2,
317
- },
318
- included: true,
319
- direct: true,
320
- },
321
- ];
322
- const orderItem = { price: 2, quantity: 1, modifiers };
323
- const newItem = pricingService.item.calculate(orderItem);
324
- expect(newItem).toHaveProperty('total', 2.32);
325
- expect(newItem).toHaveProperty('subTotals', {
326
- _xdirect: 0,
327
- _simple: 2,
328
- _actual: 2.32,
329
- _direct: 0.32,
330
- _included: 0.32,
331
- _xincluded: 0,
332
- });
333
- });
334
-
335
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true percentageDiscount16', () => {
336
- const percentageDiscount16 = {
337
- compute: {
338
- amount: 16,
339
- type: 'percentage',
340
- action: 'subtract',
341
- },
342
- properties: {
343
- extractCalculatedValue: true,
344
- },
345
- name: 'percentageDiscount16',
346
- type: 'discount',
347
- };
348
-
349
- const orderItem = {
350
- price: 116,
351
- quantity: 1,
352
- modifiers: [percentageDiscount16],
353
- };
354
- const newItem = pricingService.item.calculate(orderItem);
355
-
356
- expect(newItem).toHaveProperty('total', 116);
357
- expect(newItem).toHaveProperty('price', 116);
358
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
359
- amount: -22.095238095238095,
360
- description: 'percentageDiscount16 (-$22.10)',
361
- });
362
-
363
- expect(newItem).toHaveProperty('subTotals', {
364
- discount: -22.095238095238095,
365
- _included: 0,
366
- _xincluded: -22.095238095238095,
367
- _direct: 0,
368
- _xdirect: -22.095238095238095,
369
- _simple: 138.0952380952381,
370
- _actual: 138.0952380952381,
371
- });
372
- });
373
-
374
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true percentageFee16', () => {
375
- const percentageFee16 = {
376
- compute: {
377
- amount: 16,
378
- type: 'percentage',
379
- action: 'add',
380
- },
381
- properties: {
382
- extractCalculatedValue: true,
383
- },
384
- name: 'percentageFee16',
385
- type: 'tax',
386
- };
387
-
388
- const orderItem = { price: 116, quantity: 1, modifiers: [percentageFee16] };
389
- const newItem = pricingService.item.calculate(orderItem);
390
-
391
- expect(newItem).toHaveProperty('total', 116);
392
- expect(newItem).toHaveProperty('price', 116);
393
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
394
- amount: 16,
395
- description: 'percentageFee16 ($16.00)',
396
- });
397
-
398
- expect(newItem).toHaveProperty('subTotals', {
399
- tax: 16,
400
- _included: 0,
401
- _xincluded: 16,
402
- _direct: 0,
403
- _xdirect: 16,
404
- _simple: 100,
405
- _actual: 100,
406
- });
407
- });
408
-
409
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedDiscount16', () => {
410
- const fixedDiscount16 = {
411
- compute: {
412
- amount: 16,
413
- type: 'fixed',
414
- action: 'subtract',
415
- },
416
- properties: {
417
- extractCalculatedValue: true,
418
- },
419
- name: 'fixedDiscount16',
420
- type: 'discount',
421
- };
422
-
423
- const orderItem = {
424
- price: 116,
425
- quantity: 1,
426
- modifiers: [fixedDiscount16],
427
- };
428
- const newItem = pricingService.item.calculate(orderItem);
429
-
430
- expect(newItem).toHaveProperty('total', 116);
431
- expect(newItem).toHaveProperty('price', 116);
432
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
433
- amount: -16,
434
- description: 'fixedDiscount16 (-$16.00)',
435
- });
436
-
437
- expect(newItem).toHaveProperty('subTotals', {
438
- discount: -16,
439
- _included: 0,
440
- _xincluded: -16,
441
- _direct: 0,
442
- _xdirect: -16,
443
- _simple: 132,
444
- _actual: 132,
445
- });
446
- });
447
-
448
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16', () => {
449
- const fixedFee16 = {
450
- compute: {
451
- amount: 16,
452
- type: 'fixed',
453
- action: 'add',
454
- },
455
- properties: {
456
- extractCalculatedValue: true,
457
- },
458
- name: 'fixedFee16',
459
- type: 'tax',
460
- };
461
-
462
- const orderItem = {
463
- price: 116,
464
- quantity: 1,
465
- modifiers: [fixedFee16],
466
- };
467
- const newItem = pricingService.item.calculate(orderItem);
468
-
469
- expect(newItem).toHaveProperty('total', 116);
470
- expect(newItem).toHaveProperty('price', 116);
471
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
472
- amount: 16,
473
- description: 'fixedFee16 ($16.00)',
474
- });
475
-
476
- expect(newItem).toHaveProperty('subTotals', {
477
- tax: 16,
478
- _included: 0,
479
- _xincluded: 16,
480
- _direct: 0,
481
- _xdirect: 16,
482
- _simple: 100,
483
- _actual: 100,
484
- });
485
- });
486
-
487
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16 and other fixed fee of 10%', () => {
488
- const fixedFee16 = {
489
- compute: {
490
- amount: 16,
491
- type: 'fixed',
492
- action: 'add',
493
- },
494
- properties: {
495
- extractCalculatedValue: true,
496
- },
497
- name: 'fixedFee16',
498
- type: 'tax',
499
- modifierId: '11111',
500
- _id: '123',
501
- };
502
-
503
- const fixedFee10 = {
504
- compute: {
505
- amount: 10,
506
- type: 'fixed',
507
- action: 'add',
508
- },
509
- name: 'fixedFee10',
510
- type: 'tax',
511
- modifierId: '22222',
512
- _id: '234',
513
- };
514
-
515
- const orderItem = {
516
- price: 116,
517
- quantity: 1,
518
- modifiers: [fixedFee16, fixedFee10],
519
- };
520
- const newItem = pricingService.item.calculate(orderItem);
521
-
522
- expect(newItem).toHaveProperty('total', 126);
523
- expect(newItem).toHaveProperty('price', 116);
524
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
525
- amount: 16,
526
- description: 'fixedFee16 ($16.00)',
527
- });
528
-
529
- expect(newItem).toHaveProperty('subTotals', {
530
- tax: 26,
531
- _included: 0,
532
- _xincluded: 26,
533
- _direct: 0,
534
- _xdirect: 26,
535
- _simple: 100,
536
- _actual: 100,
537
- });
538
- });
539
-
540
- test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16 and other percentage fee of 10%', () => {
541
- const fixedFee16 = {
542
- compute: {
543
- amount: 16,
544
- type: 'fixed',
545
- action: 'add',
546
- },
547
- properties: {
548
- extractCalculatedValue: true,
549
- },
550
- name: 'fixedFee16',
551
- type: 'tax',
552
- _id: '123',
553
- modifierId: 1111,
554
- };
555
-
556
- const percentageFee10 = {
557
- compute: {
558
- amount: 10,
559
- type: 'percentage',
560
- action: 'add',
561
- },
562
- name: 'percentageFee10',
563
- type: 'tax',
564
- _id: '234',
565
- modifierId: 222,
566
- };
567
-
568
- const orderItem = {
569
- price: 116,
570
- quantity: 1,
571
- modifiers: [fixedFee16, percentageFee10],
572
- };
573
- const newItem = pricingService.item.calculate(orderItem);
574
-
575
- expect(newItem).toHaveProperty('total', 126);
576
- expect(newItem).toHaveProperty('price', 116);
577
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
578
- amount: 16,
579
- description: 'fixedFee16 ($16.00)',
580
- });
581
- expect(newItem.modifiers[1]).toHaveProperty('_computed', {
582
- amount: 10,
583
- description: 'percentageFee10 ($10.00)',
584
- });
585
-
586
- expect(newItem).toHaveProperty('subTotals', {
587
- tax: 26,
588
- _included: 0,
589
- _xincluded: 26,
590
- _direct: 0,
591
- _xdirect: 26,
592
- _simple: 100,
593
- _actual: 100,
594
- });
595
- });
596
- test('CU-86dvbn63z: Calculate item with quantity > 1 and modifierAmountFixed10', () => {
597
- const itemWithModifierAmountFixed10 = {
598
- name: "Men's 3pc Tuxedo",
599
- pieces: 3,
600
- total: 53.03,
601
- price: 13.5,
602
- quantity: 3,
603
- modifiers: [
604
- {
605
- _id: '675354ee39a47228afd1f1a4',
606
- attributes: ['override'],
607
- modifierId: '6751f7eeb60c71cefee138ee',
608
- name: 'Override modamount fixed 10',
609
- group: 'Upcharge',
610
- type: 'fee',
611
- tags: ['default', 'all'],
612
- direct: true,
613
- properties: {
614
- override: {
615
- type: 'fixed',
616
- field: 'amount',
617
- fixedValue: 10,
618
- multiplier: false,
619
- },
620
- },
621
- compute: { type: 'fixed', amount: 10, action: 'add' },
622
- },
623
- ],
624
- _id: '675354e939a47228afd1f199',
625
-
626
- itemId: '62cdbfd01ee1b400193281ee',
627
- };
628
- const newItem = pricingService.item.calculate(
629
- itemWithModifierAmountFixed10
630
- );
631
-
632
- expect(newItem).toHaveProperty('total', 50.5);
633
- expect(newItem).toHaveProperty('price', 13.5);
634
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
635
- amount: 10,
636
- description: 'Override modamount fixed 10 ($10.00)',
637
- });
638
-
639
- expect(newItem).toHaveProperty('subTotals', {
640
- fee: 10,
641
- _included: 0,
642
- _xincluded: 10,
643
- _direct: 10,
644
- _xdirect: 0,
645
- _simple: 40.5,
646
- _actual: 40.5,
647
- });
648
- });
649
-
650
- test('CU-86dvbn63z: Calculate item with quantity > 1 and modifierAmountFixed10 Multiplier', () => {
651
- const itemWithModifierAmountFixed10Multiplier = {
652
- name: "Men's 3pc Tuxedo",
653
- pieces: 3,
654
- total: 53.03,
655
- price: 13.5,
656
- quantity: 3,
657
- modifiers: [
658
- {
659
- _id: '675354ee39a47228afd1f1a4',
660
- attributes: ['override'],
661
- modifierId: '6751f7eeb60c71cefee138ee',
662
- name: 'Override modamount fixed 10',
663
- group: 'Upcharge',
664
- type: 'fee',
665
- tags: ['default', 'all'],
666
- direct: true,
667
- properties: {
668
- override: {
669
- type: 'fixed',
670
- field: 'amount',
671
- fixedValue: 10,
672
- multiplier: true,
673
- },
674
- },
675
- },
676
- ],
677
- _id: '675354e939a47228afd1f199',
678
-
679
- itemId: '62cdbfd01ee1b400193281ee',
680
- };
681
- const newItem = pricingService.item.calculate(
682
- itemWithModifierAmountFixed10Multiplier
683
- );
684
-
685
- expect(newItem).toHaveProperty('total', 70.5);
686
- expect(newItem).toHaveProperty('price', 13.5);
687
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
688
- amount: 30,
689
- description: 'Override modamount fixed 10 ($30.00)',
690
- });
691
-
692
- expect(newItem).toHaveProperty('subTotals', {
693
- fee: 30,
694
- _included: 0,
695
- _xincluded: 30,
696
- _direct: 30,
697
- _xdirect: 0,
698
- _simple: 40.5,
699
- _actual: 40.5,
700
- });
701
- });
702
-
703
- test('CU-86dvbn63z: Calculate item with quantity > 1 and quantity override modifier', () => {
704
- const quantityOverrideMod = {
705
- _id: '67535f3ab4c5ea63d2d7964b',
706
- attributes: ['override'],
707
- modifierId: '675359b5d08f91f558233f85',
708
- name: 'Override Item Quantity 5',
709
- group: 'Upcharge',
710
- type: 'tax',
711
- tags: ['default'],
712
- direct: true,
713
- properties: {
714
- subscription: {},
715
- override: { type: 'fixed', field: 'quantity', fixedValue: 5 },
716
- group: { items: [], modifiers: [] },
717
- department: {},
718
- sort: null,
719
- },
720
- compute: null,
721
- };
722
- const itemWithQuantityOverride5 = {
723
- name: "Men's 3pc Tuxedo",
724
- pieces: 3,
725
- total: 70.88,
726
- price: 13.5,
727
- quantity: 3,
728
- modifiers: [quantityOverrideMod],
729
- _id: '67535f34b4c5ea63d2d79640',
730
- itemId: '62cdbfd01ee1b400193281ee',
731
- menuRuleId: '65660855dfffaf2da26fb870',
732
- __typename: 'OrderItem',
733
- };
734
- let newItem = pricingService.item.calculate(itemWithQuantityOverride5);
735
-
736
- expect(newItem).toHaveProperty('total', 67.5);
737
- expect(newItem).toHaveProperty('price', 13.5);
738
- expect(newItem).toHaveProperty('quantity', 5);
739
-
740
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
741
- amount: 0,
742
- description: 'Override Item Quantity 5',
743
- });
744
-
745
- expect(newItem).toHaveProperty('subTotals', {
746
- _included: 0,
747
- _xincluded: 0,
748
- _direct: 0,
749
- _xdirect: 0,
750
- _simple: 67.5,
751
- _actual: 67.5,
752
- });
753
-
754
- newItem = pricingService.item.calculate(
755
- pricingService.item.removeModifiers({
756
- item: newItem,
757
- modifiers: [quantityOverrideMod],
758
- customer: undefined,
759
- order: { items: [newItem] },
760
- })
761
- );
762
- expect(newItem.price).toBe(13.5);
763
- expect(newItem.total).toBe(40.5);
764
- expect(newItem.quantity).toBe(3);
765
-
766
- expect(newItem.modifiers.length).toBe(0);
767
-
768
- expect(newItem).toHaveProperty('subTotals', {
769
- _included: 0,
770
- _xincluded: 0,
771
- _direct: 0,
772
- _xdirect: 0,
773
- _simple: 40.5,
774
- _actual: 40.5,
775
- });
776
- });
777
-
778
- test('CU-86dvbn63z: Calculate item with quantity > 1 and modifieritemPriceFixed10', () => {
779
- const itemWithModifierAmountFixed10 = {
780
- name: "Men's 3pc Tuxedo",
781
- pieces: 3,
782
- price: 10,
783
- quantity: 3,
784
- modifiers: [
785
- {
786
- _id: '675354ee39a47228afd1f1a4',
787
- attributes: ['override'],
788
- modifierId: '6751f7eeb60c71cefee138ee',
789
- name: 'Override item price fixed 10',
790
- group: 'Upcharge',
791
- type: 'fee',
792
- tags: ['default', 'all'],
793
- direct: true,
794
- properties: {
795
- override: {
796
- type: 'fixed',
797
- field: 'price',
798
- fixedValue: 10,
799
- multiplier: false,
800
- },
801
- },
802
- },
803
- ],
804
- _id: '675354e939a47228afd1f199',
805
-
806
- itemId: '62cdbfd01ee1b400193281ee',
807
- };
808
- const newItem = pricingService.item.calculate(
809
- itemWithModifierAmountFixed10
810
- );
811
-
812
- expect(newItem).toHaveProperty('total', 30);
813
- expect(newItem).toHaveProperty('price', 10);
814
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
815
- amount: 0,
816
- description: 'Override item price fixed 10 ($10.00/Unit)',
817
- });
818
-
819
- expect(newItem).toHaveProperty('subTotals', {
820
- _included: 0,
821
- _xincluded: 0,
822
- _direct: 0,
823
- _xdirect: 0,
824
- _simple: 30,
825
- _actual: 30,
826
- });
827
- });
828
-
829
- test('CU-86dvbn63z: Calculate item with quantity > 1 and modifieritemPriceFixed1 multiplier', () => {
830
- const item = {
831
- name: "Men's 3pc Tuxedo",
832
- pieces: 3,
833
- total: 141.75,
834
- price: 13.5,
835
- quantity: 1,
836
- modifiers: [
837
- {
838
- _id: '67536495bc57ccecf751a5dc',
839
- attributes: ['override'],
840
- modifierId: '6751e9c0b60c71cefee0c3cc',
841
- _parentId: null,
842
- locked: false,
843
- name: 'Override Item Price 10 USD Multiplier',
844
- group: 'Upcharge',
845
- type: 'fee',
846
- tags: ['default', 'all'],
847
-
848
- direct: true,
849
-
850
- properties: {
851
- override: {
852
- type: 'fixed',
853
- field: 'price',
854
- fixedValue: 10,
855
- multiplier: true,
856
- },
857
- },
858
- },
859
- ],
860
- _id: '675360d5bc57ccecf751a5b5',
861
- itemId: '62cdbfd01ee1b400193281ee',
862
- };
863
- const newItem = pricingService.item.calculate(item);
864
-
865
- expect(newItem).toHaveProperty('total', 135);
866
- expect(newItem).toHaveProperty('price', 135);
867
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
868
- amount: 0,
869
- description:
870
- 'Override Item Price 10 USD Multiplier (10 Unit @ $13.50/Unit)',
871
- });
872
-
873
- expect(newItem).toHaveProperty('subTotals', {
874
- _included: 0,
875
- _xincluded: 0,
876
- _direct: 0,
877
- _xdirect: 0,
878
- _simple: 135,
879
- _actual: 135,
880
- });
881
- });
882
-
883
- test('Remove Item', () => {
884
- const item1 = {
885
- _id: '1',
886
- };
887
- const item2 = {
888
- _id: '2',
889
- };
890
-
891
- const order = {
892
- items: [item1, item2],
893
- };
894
- const result = pricingService.order.removeItem({ order, item: item2 });
895
-
896
- expect(result.items).toMatchObject([{ _id: '1' }]);
897
- });
898
-
899
- test('Remove related Item', () => {
900
- const item1 = {
901
- _id: '1',
902
- itemId: 'a',
903
- };
904
- const item2 = {
905
- _id: '2',
906
- };
907
- const item3 = {
908
- _id: '3',
909
- properties: {
910
- relatedItem: true,
911
- parentId: item1._id,
912
- parentItemId: item1.itemId,
913
- },
914
- };
915
-
916
- const order = {
917
- items: [item1, item2, item3],
918
- };
919
- const result = pricingService.order.removeItem({ order, item: item3 });
920
-
921
- expect(result.items).toMatchObject([
922
- {
923
- _id: '1',
924
- },
925
- {
926
- _id: '2',
927
- },
928
- ]);
929
- });
930
-
931
- test('Remove parent Item having 1 related item', () => {
932
- const item1 = {
933
- _id: '1',
934
- itemId: 'a',
935
- };
936
- const item2 = {
937
- _id: '2',
938
- };
939
- const item3 = {
940
- _id: '3',
941
- properties: {
942
- relatedItem: true,
943
- parentId: item1._id,
944
- parentItemId: item1.itemId,
945
- },
946
- };
947
-
948
- const order = {
949
- items: [item1, item2, item3],
950
- };
951
- const result = pricingService.order.removeItem({ order, item: item1 });
952
-
953
- expect(result.items).toMatchObject([
954
- {
955
- _id: '2',
956
- },
957
- ]);
958
- });
959
-
960
- test('Remove parent Item, having more than 1 related item', () => {
961
- const item1 = {
962
- _id: '1',
963
- itemId: 'a',
964
- };
965
- const item2 = {
966
- _id: '2',
967
- };
968
- const item3 = {
969
- _id: '3',
970
- properties: {
971
- relatedItem: true,
972
- parentId: item1._id,
973
- parentItemId: item1.itemId,
974
- },
975
- };
976
- const item4 = {
977
- _id: '4',
978
- properties: {
979
- relatedItem: true,
980
- parentId: item1._id,
981
- parentItemId: item1.itemId,
982
- },
983
- };
984
-
985
- const order = {
986
- items: [item1, item2, item3, item4],
987
- };
988
- const result = pricingService.order.removeItem({ order, item: item1 });
989
-
990
- expect(result.items).toMatchObject([
991
- {
992
- _id: '2',
993
- },
994
- ]);
995
- });
996
-
997
- test('Remove related Item, having nested related items', () => {
998
- const item1 = {
999
- _id: '1',
1000
- itemId: 'a',
1001
- };
1002
- const item2 = {
1003
- _id: '2',
1004
- };
1005
- const item3 = {
1006
- _id: '3',
1007
- properties: {
1008
- relatedItem: true,
1009
- parentId: item1._id,
1010
- parentItemId: item1.itemId,
1011
- },
1012
- };
1013
- const item4 = {
1014
- _id: '4',
1015
- itemId: 'd',
1016
- properties: {
1017
- relatedItem: true,
1018
- parentId: item1._id,
1019
- parentItemId: item1.itemId,
1020
- },
1021
- };
1022
-
1023
- const nestedItem5 = {
1024
- _id: '5',
1025
- properties: {
1026
- relatedItem: true,
1027
- parentId: item4._id,
1028
- parentItemId: item4.itemId,
1029
- },
1030
- };
1031
-
1032
- const order = {
1033
- items: [item1, item2, item3, item4, nestedItem5],
1034
- };
1035
- const result = pricingService.order.removeItem({
1036
- order,
1037
- item: nestedItem5,
1038
- });
1039
-
1040
- expect(result.items).toMatchObject([item1, item2, item3, item4]);
1041
- });
1042
-
1043
- test('Remove related Item, having nested related items 2', () => {
1044
- const item1 = {
1045
- _id: '1',
1046
- itemId: 'a',
1047
- };
1048
- const item2 = {
1049
- _id: '2',
1050
- };
1051
- const item3 = {
1052
- _id: '3',
1053
- properties: {
1054
- relatedItem: true,
1055
- parentId: item1._id,
1056
- parentItemId: item1.itemId,
1057
- },
1058
- };
1059
- const item4 = {
1060
- _id: '4',
1061
- itemId: 'd',
1062
- properties: {
1063
- relatedItem: true,
1064
- parentId: item1._id,
1065
- parentItemId: item1.itemId,
1066
- },
1067
- };
1068
-
1069
- const nestedItem5 = {
1070
- _id: '5',
1071
- properties: {
1072
- relatedItem: true,
1073
- parentId: item4._id,
1074
- parentItemId: item4.itemId,
1075
- },
1076
- };
1077
-
1078
- const nestedItem6 = {
1079
- _id: '6',
1080
- properties: {
1081
- relatedItem: true,
1082
- parentId: item4._id,
1083
- parentItemId: item4.itemId,
1084
- },
1085
- };
1086
-
1087
- const order = {
1088
- items: [item1, item2, item3, item4, nestedItem5, nestedItem6],
1089
- };
1090
- const result = pricingService.order.removeItem({
1091
- order,
1092
- item: nestedItem5,
1093
- });
1094
-
1095
- expect(result.items).toMatchObject([
1096
- item1,
1097
- item2,
1098
- item3,
1099
- item4,
1100
- nestedItem6,
1101
- ]);
1102
- });
1103
-
1104
- test('Remove parent related Item, having nested related items', () => {
1105
- const item1 = {
1106
- _id: '1',
1107
- itemId: 'a',
1108
- };
1109
- const item2 = {
1110
- _id: '2',
1111
- };
1112
- const item3 = {
1113
- _id: '3',
1114
- properties: {
1115
- relatedItem: true,
1116
- parentId: item1._id,
1117
- parentItemId: item1.itemId,
1118
- },
1119
- };
1120
- const item4 = {
1121
- _id: '4',
1122
- itemId: 'd',
1123
- properties: {
1124
- relatedItem: true,
1125
- parentId: item1._id,
1126
- parentItemId: item1.itemId,
1127
- },
1128
- };
1129
-
1130
- const nestedItem5 = {
1131
- _id: '5',
1132
- properties: {
1133
- relatedItem: true,
1134
- parentId: item4._id,
1135
- parentItemId: item4.itemId,
1136
- },
1137
- };
1138
-
1139
- const nestedItem6 = {
1140
- _id: '6',
1141
- properties: {
1142
- relatedItem: true,
1143
- parentId: item4._id,
1144
- parentItemId: item4.itemId,
1145
- },
1146
- };
1147
-
1148
- const order = {
1149
- items: [item1, item2, item3, item4, nestedItem5, nestedItem6],
1150
- };
1151
- const result = pricingService.order.removeItem({ order, item: item1 });
1152
-
1153
- expect(result.items).toMatchObject([item2]);
1154
- });
1155
-
1156
- test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
1157
- const rawRelatedItem1 = {
1158
- name: 'the related item',
1159
- _id: '67e2cadd8dcf08ebcc5ef888',
1160
- };
1161
-
1162
- const rawRelatedItem2 = {
1163
- name: 'the 2nd related item',
1164
- _id: '67e2cadd8dcf08ebcc5ef88a',
1165
- };
1166
-
1167
- const groupMod = {
1168
- _id: '67e2cadd8dcf08ebcc5ef889',
1169
- name: 'General Repair Department',
1170
- attributes: ['group'],
1171
- modifierId: 'mod1',
1172
- properties: {
1173
- group: {
1174
- items: [],
1175
- },
1176
- },
1177
- };
1178
-
1179
- const parentItem = {
1180
- name: 'the parent item',
1181
- modifiers: [groupMod],
1182
- _id: '67e2cadd8dcf08ebcc5ef887',
1183
- __typename: 'OrderItem',
1184
- };
1185
-
1186
- const relatedItem1 = {
1187
- ...rawRelatedItem1,
1188
- properties: {
1189
- relatedItem: true,
1190
- parentId: parentItem._id,
1191
- includeParent: true,
1192
- addModifiers: [groupMod],
1193
- groupPath: ',67e2cadd8dcf08ebcc5ef889',
1194
- },
1195
- __typename: 'OrderItem',
1196
- };
1197
-
1198
- const relatedItem2 = {
1199
- ...rawRelatedItem2,
1200
- properties: {
1201
- relatedItem: true,
1202
- parentId: parentItem._id,
1203
- includeParent: true,
1204
- addModifiers: [groupMod],
1205
- groupPath: ',67e2cadd8dcf08ebcc5ef889',
1206
- },
1207
- __typename: 'OrderItem',
1208
- };
1209
- const order = {
1210
- items: [parentItem, relatedItem1, relatedItem2],
1211
- };
1212
-
1213
- const result = pricingService.order.removeItem({
1214
- order,
1215
- item: relatedItem2,
1216
- });
1217
-
1218
- expect(result.items.length).toBe(2);
1219
- expect(result.items[0].modifiers.length).toBe(1);
1220
- expect(result.items[0].modifiers[0].modifierId).toBe('mod1');
1221
-
1222
- const result2 = pricingService.order.removeItem({
1223
- order: result,
1224
- item: relatedItem1,
1225
- });
1226
-
1227
- expect(result2.items.length).toBe(1);
1228
- expect(result2.items[0].modifiers.length).toBe(0);
1229
- });
1230
-
1231
- test('Should not remove the group modifier if it still hasModifiers', () => {
1232
- const rawRelatedItem1 = {
1233
- name: 'the related item',
1234
- _id: '67e2cadd8dcf08ebcc5ef888',
1235
- };
1236
-
1237
- const rawRelatedItem2 = {
1238
- name: 'the 2nd related item',
1239
- _id: '67e2cadd8dcf08ebcc5ef88a',
1240
- };
1241
-
1242
- const rawRelatedMod1 = {
1243
- name: 'related modifier',
1244
- _id: '123',
1245
- modifierId: 'abc',
1246
- addModifiers: [
1247
- {
1248
- _id: '67e2cadd8dcf08ebcc5ef889',
1249
- name: 'General Repair Department',
1250
- attributes: ['group'],
1251
- modifierId: 'mod1',
1252
- properties: {
1253
- group: {
1254
- items: [],
1255
- },
1256
- },
1257
- },
1258
- ],
1259
- };
1260
-
1261
- const groupMod = {
1262
- _id: '67e2cadd8dcf08ebcc5ef889',
1263
- name: 'General Repair Department',
1264
- attributes: ['group'],
1265
- modifierId: 'mod1',
1266
- properties: {
1267
- group: {
1268
- items: [],
1269
- modifiers: [],
1270
- },
1271
- },
1272
- };
1273
-
1274
- const parentItem = {
1275
- name: 'the parent item',
1276
- modifiers: [groupMod, rawRelatedMod1],
1277
- _id: '67e2cadd8dcf08ebcc5ef887',
1278
- __typename: 'OrderItem',
1279
- };
1280
-
1281
- const relatedItem1 = {
1282
- ...rawRelatedItem1,
1283
- properties: {
1284
- relatedItem: true,
1285
- parentId: parentItem._id,
1286
- includeParent: true,
1287
- addModifiers: [groupMod],
1288
- groupPath: ',67e2cadd8dcf08ebcc5ef889',
1289
- },
1290
- __typename: 'OrderItem',
1291
- };
1292
-
1293
- const relatedItem2 = {
1294
- ...rawRelatedItem2,
1295
- properties: {
1296
- relatedItem: true,
1297
- parentId: parentItem._id,
1298
- includeParent: true,
1299
- addModifiers: [groupMod],
1300
- groupPath: ',67e2cadd8dcf08ebcc5ef889',
1301
- },
1302
- __typename: 'OrderItem',
1303
- };
1304
- const order = {
1305
- items: [parentItem, relatedItem1, relatedItem2],
1306
- };
1307
-
1308
- const newItem = pricingService.item.removeModifiers({
1309
- item: parentItem,
1310
- modifiers: [rawRelatedMod1],
1311
- originalItem: parentItem,
1312
- customer: undefined,
1313
- order,
1314
- });
1315
-
1316
- expect(newItem.modifiers.length).toBe(1);
1317
- expect(newItem.modifiers[0].name).toBe('General Repair Department');
1318
- });
1319
-
1320
- test('1- Item total should not be below 0, having price override modifiers', () => {
1321
- const order = {
1322
- _id: '685c2d2bd7f68fccd07af8c7',
1323
- tax: 0,
1324
- modifiers: [],
1325
- discount: 0,
1326
- total: -2.28,
1327
- fee: 0,
1328
- items: [
1329
- {
1330
- name: 'Pants',
1331
- description: null,
1332
- pieces: 1,
1333
- modifiersTotalAmount: 0,
1334
- total: -2.28,
1335
- totalPaid: 0,
1336
- price: 0,
1337
- quantity: 1,
1338
- notes: [],
1339
- modifiers: [
1340
- {
1341
- _id: '685c2d64d7f68fccd07af8cd',
1342
- attributes: ['override'],
1343
- modifierId: '67fea241af24e570c032b40d',
1344
- _parentId: null,
1345
- locked: false,
1346
- name: 'No Clean',
1347
- tags: ['default'],
1348
- order: 0,
1349
- included: false,
1350
- direct: true,
1351
- default: true,
1352
- code: null,
1353
- properties: {
1354
- override: {
1355
- field: 'price',
1356
- type: 'fixed',
1357
- multiplier: true,
1358
- fixedValue: 0,
1359
- },
1360
- group: null,
1361
- department: null,
1362
- url: null,
1363
- color: null,
1364
- label: {
1365
- backgroundColor: null,
1366
- align: null,
1367
- },
1368
- sort: null,
1369
- },
1370
- compute: null,
1371
- __typename: 'Modifier',
1372
- addModifiers: [],
1373
- delModifiers: [],
1374
- },
1375
- {
1376
- _id: '685c2d65d7f68fccd07af8ce',
1377
- attributes: [],
1378
- modifierId: '67fea241af24e570c032b324',
1379
- _parentId: null,
1380
- locked: false,
1381
- name: '30% Family Discount',
1382
- type: 'discount',
1383
- tags: ['default'],
1384
- order: 0,
1385
- included: false,
1386
- direct: true,
1387
- hidden: false,
1388
- print: true,
1389
- required: false,
1390
- recommended: false,
1391
- default: false,
1392
- code: null,
1393
- properties: {
1394
- group: null,
1395
- department: null,
1396
- url: null,
1397
- color: null,
1398
- label: {
1399
- backgroundColor: null,
1400
- align: null,
1401
- },
1402
- sort: null,
1403
- isQuantityMultiplier: true,
1404
- },
1405
- compute: {
1406
- type: 'percentage',
1407
- action: 'subtract',
1408
- amount: 30,
1409
- },
1410
- __typename: 'Modifier',
1411
- addModifiers: [],
1412
- delModifiers: [],
1413
- },
1414
- ],
1415
- weight: 0,
1416
- properties: {
1417
- overwrittenPrice: 7.59,
1418
- },
1419
- },
1420
- ],
1421
- customer: {
1422
- _id: '67feae8eeb5aa1e1848374b9',
1423
- tags: ['default'],
1424
- },
1425
- };
1426
-
1427
- const calculatedOrder = pricingService.order.calculate(order);
1428
-
1429
- expect(calculatedOrder.total).toBe(0);
1430
- expect(calculatedOrder.items[0].price).toBe(0);
1431
- expect(calculatedOrder.items[0].total).toBe(0);
1432
- expect(calculatedOrder.items[0].modifiers[0]._computed.description).toBe(
1433
- 'No Clean (0 Unit @ $0.00/Unit)'
1434
- );
1435
- expect(calculatedOrder.items[0].modifiers[1]._computed.description).toBe(
1436
- '30% Family Discount'
1437
- );
1438
- });
1439
-
1440
- test('2- Item total should not be below 0, having price override modifiers', () => {
1441
- const order = {
1442
- _id: '685c2d2bd7f68fccd07af8c7',
1443
- tax: 0,
1444
- modifiers: [],
1445
- discount: 0,
1446
- total: -2.28,
1447
- fee: 0,
1448
- items: [
1449
- {
1450
- name: 'Pants',
1451
- description: null,
1452
- pieces: 1,
1453
- modifiersTotalAmount: 0,
1454
- total: -2.28,
1455
- totalPaid: 0,
1456
- price: 0,
1457
- quantity: 1,
1458
- notes: [],
1459
- modifiers: [
1460
- {
1461
- _id: '685c2d65d7f68fccd07af8ce',
1462
- attributes: [],
1463
- modifierId: '67fea241af24e570c032b324',
1464
- _parentId: null,
1465
- locked: false,
1466
- name: '30% Family Discount',
1467
- type: 'discount',
1468
- tags: ['default'],
1469
- order: 0,
1470
- included: false,
1471
- direct: true,
1472
- hidden: false,
1473
- print: true,
1474
- required: false,
1475
- recommended: false,
1476
- default: false,
1477
- code: null,
1478
- properties: {
1479
- group: null,
1480
- department: null,
1481
- url: null,
1482
- color: null,
1483
- label: {
1484
- backgroundColor: null,
1485
- align: null,
1486
- },
1487
- sort: null,
1488
- isQuantityMultiplier: true,
1489
- },
1490
- compute: {
1491
- type: 'percentage',
1492
- action: 'subtract',
1493
- amount: 30,
1494
- },
1495
- __typename: 'Modifier',
1496
- addModifiers: [],
1497
- delModifiers: [],
1498
- },
1499
- {
1500
- _id: '685c2d64d7f68fccd07af8cd',
1501
- attributes: ['override'],
1502
- modifierId: '67fea241af24e570c032b40d',
1503
- _parentId: null,
1504
- locked: false,
1505
- name: 'No Clean',
1506
- tags: ['default'],
1507
- order: 0,
1508
- included: false,
1509
- direct: true,
1510
- default: true,
1511
- code: null,
1512
- properties: {
1513
- override: {
1514
- field: 'price',
1515
- type: 'fixed',
1516
- multiplier: true,
1517
- fixedValue: 0,
1518
- },
1519
- group: null,
1520
- department: null,
1521
- url: null,
1522
- color: null,
1523
- label: {
1524
- backgroundColor: null,
1525
- align: null,
1526
- },
1527
- sort: null,
1528
- },
1529
- compute: null,
1530
- __typename: 'Modifier',
1531
- addModifiers: [],
1532
- delModifiers: [],
1533
- },
1534
- ],
1535
- weight: 0,
1536
- properties: {
1537
- overwrittenPrice: 7.59,
1538
- },
1539
- },
1540
- ],
1541
- customer: {
1542
- _id: '67feae8eeb5aa1e1848374b9',
1543
- tags: ['default'],
1544
- },
1545
- };
1546
-
1547
- const calculatedOrder = pricingService.order.calculate(order);
1548
-
1549
- expect(calculatedOrder.total).toBe(0);
1550
- expect(calculatedOrder.items[0].price).toBe(0);
1551
- expect(calculatedOrder.items[0].total).toBe(0);
1552
-
1553
- expect(calculatedOrder.items[0].modifiers[0]._computed.description).toBe(
1554
- '30% Family Discount'
1555
- );
1556
- expect(calculatedOrder.items[0].modifiers[1]._computed.description).toBe(
1557
- 'No Clean (0 Unit @ $0.00/Unit)'
1558
- );
1559
- });
1560
-
1561
- test('Should not apply modifier value when extractCalculatedValue is true but modifier is invalid', () => {
1562
- const prepayDiscount50Percent = {
1563
- compute: {
1564
- amount: 50,
1565
- type: 'percentage',
1566
- action: 'subtract',
1567
- },
1568
- properties: {
1569
- extractCalculatedValue: true,
1570
- },
1571
- conditions: {
1572
- valid: null,
1573
- rules: [
1574
- {
1575
- key: 'payment',
1576
- value: 'prepay',
1577
- operand: '$in',
1578
- },
1579
- ],
1580
- },
1581
- name: 'percentageDiscount50',
1582
- type: 'discount',
1583
- };
1584
-
1585
- const orderItem = {
1586
- price: 7.59,
1587
- quantity: 1,
1588
- modifiers: [prepayDiscount50Percent],
1589
- };
1590
- const order = {
1591
- items: [orderItem],
1592
- };
1593
-
1594
- const calculatedOrder = pricingService.order.calculate(order);
1595
-
1596
- expect(calculatedOrder.total).toBe(7.59);
1597
- expect(calculatedOrder.items[0].price).toBe(7.59);
1598
- expect(calculatedOrder.items[0].total).toBe(7.59);
1599
- expect(calculatedOrder.items[0].modifiers.length).toBe(1);
1600
- expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1601
- amount: 0,
1602
- description: 'percentageDiscount50',
1603
- });
1604
- });
1605
-
1606
- test('Should apply modifier value when extractCalculatedValue is true and modifier is valid', () => {
1607
- const prepayDiscount50Percent = {
1608
- compute: {
1609
- amount: 50,
1610
- type: 'percentage',
1611
- action: 'subtract',
1612
- },
1613
- properties: {
1614
- extractCalculatedValue: true,
1615
- },
1616
- name: 'percentageDiscount50',
1617
- type: 'discount',
1618
- };
1619
-
1620
- const orderItem = {
1621
- price: 7.59,
1622
- quantity: 1,
1623
- modifiers: [prepayDiscount50Percent],
1624
- };
1625
- const order = {
1626
- items: [orderItem],
1627
- };
1628
-
1629
- const calculatedOrder = pricingService.order.calculate(order);
1630
-
1631
- expect(calculatedOrder.total).toBe(7.59);
1632
- expect(calculatedOrder.items[0].price).toBe(7.59);
1633
- expect(calculatedOrder.items[0].total).toBe(7.59);
1634
- expect(calculatedOrder.items[0].modifiers.length).toBe(1);
1635
- expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1636
- amount: -7.59,
1637
- description: 'percentageDiscount50 (-$7.59)',
1638
- });
1639
- });
1640
-
1641
- test('Should apply modifier value when extractCalculatedValue is true and modifier is valid (being also a payment modifier)', () => {
1642
- const prepayDiscount50Percent = {
1643
- compute: {
1644
- amount: 50,
1645
- type: 'percentage',
1646
- action: 'subtract',
1647
- },
1648
- properties: {
1649
- extractCalculatedValue: true,
1650
- },
1651
- conditions: {
1652
- valid: null,
1653
- rules: [
1654
- {
1655
- key: 'payment',
1656
- value: 'prepay',
1657
- operand: '$in',
1658
- },
1659
- ],
1660
- },
1661
- name: 'percentageDiscount50',
1662
- type: 'discount',
1663
- };
1664
-
1665
- const orderItem = {
1666
- price: 7.59,
1667
- quantity: 1,
1668
- modifiers: [prepayDiscount50Percent],
1669
- };
1670
- const order = {
1671
- items: [orderItem],
1672
- };
1673
-
1674
- const calculatedOrder = pricingService.order.calculate(order, {
1675
- isPrepay: true,
1676
- });
1677
-
1678
- expect(calculatedOrder.total).toBe(7.59);
1679
- expect(calculatedOrder.items[0].price).toBe(7.59);
1680
- expect(calculatedOrder.items[0].total).toBe(7.59);
1681
- expect(calculatedOrder.items[0].modifiers.length).toBe(2);
1682
-
1683
- expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1684
- amount: 0,
1685
- description: 'percentageDiscount50',
1686
- });
1687
- expect(calculatedOrder.items[0].modifiers[1]._computed).toMatchObject({
1688
- amount: -7.59,
1689
- description: '$7.59 discount (-$7.59)',
1690
- });
1691
- });
1692
-
1693
- test('Should use a price override modifier and quantity override modifier in combination accordingly', () => {
11
+ // test('Get calculated Item: included: false && direct: false', () => {
12
+ // const modifiers = [
13
+ // {
14
+ // _id: 1111,
15
+ // compute: {
16
+ // amount: 20,
17
+ // type: 'percentage',
18
+ // action: 'add',
19
+ // },
20
+ // name: 'modifier1',
21
+ // type: 'discount',
22
+ // direct: false,
23
+ // included: false,
24
+ // properties: {
25
+ // isQuantityMultiplier: true,
26
+ // },
27
+ // },
28
+ // {
29
+ // _id: 2222,
30
+ // compute: {
31
+ // amount: 20,
32
+ // type: 'percentage',
33
+ // action: 'subtract',
34
+ // },
35
+ // name: 'modifier2',
36
+ // type: 'discount',
37
+ // direct: false,
38
+ // included: false,
39
+ // properties: {
40
+ // isQuantityMultiplier: true,
41
+ // },
42
+ // },
43
+ // {
44
+ // _id: 3333,
45
+ // compute: {
46
+ // amount: 2,
47
+ // type: 'fixed',
48
+ // action: 'subtract',
49
+ // },
50
+ // name: 'modifier3',
51
+ // type: 'discount',
52
+ // direct: false,
53
+ // included: false,
54
+ // properties: {
55
+ // isQuantityMultiplier: true,
56
+ // },
57
+ // },
58
+ // ];
59
+ // const orderItem = { price: 30, quantity: 2, modifiers };
60
+ // const newItem = pricingService.item.calculate(orderItem);
61
+ // expect(newItem).toHaveProperty('total', 56);
62
+ // expect(newItem).toHaveProperty('subTotals', {
63
+ // discount: -4,
64
+ // _included: 0,
65
+ // _xincluded: -4,
66
+ // _direct: 0,
67
+ // _xdirect: -4,
68
+ // _simple: 60,
69
+ // _actual: 60,
70
+ // });
71
+ // });
72
+ // test('Get calculated Item: included: false && direct: true', () => {
73
+ // const modifiers = [
74
+ // {
75
+ // _id: '123213213',
76
+ // compute: { amount: 2, type: 'fixed', action: 'subtract' },
77
+ // type: 'discount',
78
+ // name: 'modifier1',
79
+ // direct: true,
80
+ // included: false,
81
+ // properties: {
82
+ // isQuantityMultiplier: true,
83
+ // },
84
+ // },
85
+ // {
86
+ // _id: '22222',
87
+ // compute: {
88
+ // amount: 20,
89
+ // type: 'percentage',
90
+ // action: 'subtract',
91
+ // },
92
+ // name: 'modifier2',
93
+ // type: 'discount',
94
+ // direct: true,
95
+ // included: false,
96
+ // properties: {
97
+ // isQuantityMultiplier: true,
98
+ // },
99
+ // },
100
+ // {
101
+ // _id: '3333',
102
+ // compute: {
103
+ // amount: 2,
104
+ // type: 'fixed',
105
+ // action: 'add',
106
+ // },
107
+ // name: 'modifier3',
108
+ // type: 'tax',
109
+ // direct: true,
110
+ // included: false,
111
+ // properties: {
112
+ // isQuantityMultiplier: true,
113
+ // },
114
+ // },
115
+ // ];
116
+ // const orderItem = { price: 30, quantity: 2, modifiers };
117
+ // const newItem = pricingService.item.calculate(orderItem);
118
+ // expect(newItem).toHaveProperty('total', 48);
119
+ // expect(newItem).toHaveProperty('subTotals', {
120
+ // discount: -16,
121
+ // tax: 4,
122
+ // _included: 0,
123
+ // _xincluded: -12,
124
+ // _direct: -12,
125
+ // _xdirect: 0,
126
+ // _simple: 60,
127
+ // _actual: 60,
128
+ // });
129
+ // });
130
+ // test('Get calculated Item: included: true && direct: true', () => {
131
+ // const modifiers = [
132
+ // {
133
+ // _id: '111111',
134
+ // compute: {
135
+ // amount: 2,
136
+ // type: 'fixed',
137
+ // action: 'subtract',
138
+ // },
139
+ // name: 'modifier1',
140
+ // type: 'discount',
141
+ // direct: true,
142
+ // included: true,
143
+ // properties: {
144
+ // isQuantityMultiplier: true,
145
+ // },
146
+ // },
147
+ // {
148
+ // _id: '222222',
149
+
150
+ // compute: {
151
+ // amount: 20,
152
+ // type: 'percentage',
153
+ // action: 'subtract',
154
+ // },
155
+ // name: 'modifier2',
156
+ // type: 'discount',
157
+ // direct: true,
158
+ // included: true,
159
+ // properties: {
160
+ // isQuantityMultiplier: true,
161
+ // },
162
+ // },
163
+ // {
164
+ // _id: '33333',
165
+
166
+ // compute: {
167
+ // amount: 2,
168
+ // type: 'fixed',
169
+ // action: 'add',
170
+ // },
171
+ // name: 'modifier3',
172
+ // type: 'upcharge',
173
+ // direct: true,
174
+ // included: true,
175
+ // properties: {
176
+ // isQuantityMultiplier: true,
177
+ // },
178
+ // },
179
+ // ];
180
+ // const orderItem = { price: 30, quantity: 2, modifiers };
181
+ // const newItem = pricingService.item.calculate(orderItem);
182
+ // expect(newItem).toHaveProperty('total', 48);
183
+ // expect(newItem).toHaveProperty('subTotals', {
184
+ // _included: -12,
185
+ // _xincluded: 0,
186
+ // _direct: -12,
187
+ // _xdirect: 0,
188
+ // _simple: 60,
189
+ // _actual: 48,
190
+ // });
191
+ // });
192
+ // test('Get calculated Item: included: true, sample 1', () => {
193
+ // const modifiers = [
194
+ // {
195
+ // compute: {
196
+ // amount: 2,
197
+ // type: 'fixed',
198
+ // action: 'add',
199
+ // },
200
+ // name: 'modifier1',
201
+ // type: 'upcharge',
202
+ // included: true,
203
+ // direct: true,
204
+ // },
205
+ // ];
206
+ // const orderItem = { price: 2, quantity: 1, modifiers };
207
+ // const newItem = pricingService.item.calculate(orderItem);
208
+ // expect(newItem).toHaveProperty('total', 4);
209
+ // expect(newItem).toHaveProperty('subTotals', {
210
+ // _included: 2,
211
+ // _xincluded: 0,
212
+ // _direct: 2,
213
+ // _xdirect: 0,
214
+ // _simple: 2,
215
+ // _actual: 4,
216
+ // });
217
+ // });
218
+ // test('Get calculated Item: included: true, sample 2', () => {
219
+ // const modifiers = [
220
+ // {
221
+ // compute: { amount: 2, type: 'fixed', action: 'add' },
222
+ // name: 'modifier1',
223
+ // type: 'upcharge',
224
+ // included: true,
225
+ // direct: true,
226
+ // properties: {
227
+ // sort: 1,
228
+ // },
229
+ // _id: '1255115',
230
+ // },
231
+ // {
232
+ // compute: {
233
+ // amount: 10,
234
+ // type: 'percentage',
235
+ // action: 'add',
236
+ // },
237
+ // name: 'modifier2',
238
+ // type: 'tax',
239
+ // properties: {
240
+ // sort: 2,
241
+ // },
242
+ // included: true,
243
+ // direct: true,
244
+ // _id: '2256659',
245
+ // },
246
+ // ];
247
+ // const orderItem = { price: 2, quantity: 1, modifiers };
248
+ // const newItem = pricingService.item.calculate(orderItem);
249
+ // expect(newItem).toHaveProperty('total', 4.4);
250
+ // expect(newItem).toHaveProperty('subTotals', {
251
+ // _included: 2.4,
252
+ // _xincluded: 0,
253
+ // _direct: 2.4,
254
+ // _xdirect: 0,
255
+ // _simple: 2,
256
+ // _actual: 4.4,
257
+ // });
258
+ // });
259
+ // test('Get calculated Item: included: true, sample 3', () => {
260
+ // const modifiers = [
261
+ // {
262
+ // _id: 12323,
263
+ // compute: {
264
+ // amount: 2,
265
+ // type: 'fixed',
266
+ // action: 'subtract',
267
+ // },
268
+ // name: 'modifier1',
269
+ // type: 'discount',
270
+ // properties: {
271
+ // sort: 1,
272
+ // },
273
+ // included: true,
274
+ // direct: true,
275
+ // },
276
+ // {
277
+ // _id: 5555,
278
+ // compute: {
279
+ // amount: 2,
280
+ // type: 'fixed',
281
+ // action: 'add',
282
+ // },
283
+ // name: 'modifier1',
284
+ // type: 'upcharge',
285
+ // included: true,
286
+ // direct: true,
287
+ // properties: {
288
+ // sort: 1,
289
+ // },
290
+ // },
291
+ // {
292
+ // _id: 77777,
293
+ // compute: {
294
+ // amount: 10,
295
+ // type: 'percentage',
296
+ // action: 'add',
297
+ // },
298
+ // name: 'modifier2',
299
+ // type: 'tax',
300
+ // properties: {
301
+ // sort: 2,
302
+ // },
303
+ // included: true,
304
+ // direct: true,
305
+ // },
306
+ // {
307
+ // _id: 8888,
308
+ // compute: {
309
+ // amount: 6,
310
+ // type: 'percentage',
311
+ // action: 'add',
312
+ // },
313
+ // name: 'modifier3',
314
+ // type: 'tax',
315
+ // properties: {
316
+ // sort: 2,
317
+ // },
318
+ // included: true,
319
+ // direct: true,
320
+ // },
321
+ // ];
322
+ // const orderItem = { price: 2, quantity: 1, modifiers };
323
+ // const newItem = pricingService.item.calculate(orderItem);
324
+ // expect(newItem).toHaveProperty('total', 2.32);
325
+ // expect(newItem).toHaveProperty('subTotals', {
326
+ // _xdirect: 0,
327
+ // _simple: 2,
328
+ // _actual: 2.32,
329
+ // _direct: 0.32,
330
+ // _included: 0.32,
331
+ // _xincluded: 0,
332
+ // });
333
+ // });
334
+
335
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true percentageDiscount16', () => {
336
+ // const percentageDiscount16 = {
337
+ // compute: {
338
+ // amount: 16,
339
+ // type: 'percentage',
340
+ // action: 'subtract',
341
+ // },
342
+ // properties: {
343
+ // extractCalculatedValue: true,
344
+ // },
345
+ // name: 'percentageDiscount16',
346
+ // type: 'discount',
347
+ // };
348
+
349
+ // const orderItem = {
350
+ // price: 116,
351
+ // quantity: 1,
352
+ // modifiers: [percentageDiscount16],
353
+ // };
354
+ // const newItem = pricingService.item.calculate(orderItem);
355
+
356
+ // expect(newItem).toHaveProperty('total', 116);
357
+ // expect(newItem).toHaveProperty('price', 116);
358
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
359
+ // amount: -22.095238095238095,
360
+ // description: 'percentageDiscount16 (-$22.10)',
361
+ // });
362
+
363
+ // expect(newItem).toHaveProperty('subTotals', {
364
+ // discount: -22.095238095238095,
365
+ // _included: 0,
366
+ // _xincluded: -22.095238095238095,
367
+ // _direct: 0,
368
+ // _xdirect: -22.095238095238095,
369
+ // _simple: 138.0952380952381,
370
+ // _actual: 138.0952380952381,
371
+ // });
372
+ // });
373
+
374
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true percentageFee16', () => {
375
+ // const percentageFee16 = {
376
+ // compute: {
377
+ // amount: 16,
378
+ // type: 'percentage',
379
+ // action: 'add',
380
+ // },
381
+ // properties: {
382
+ // extractCalculatedValue: true,
383
+ // },
384
+ // name: 'percentageFee16',
385
+ // type: 'tax',
386
+ // };
387
+
388
+ // const orderItem = { price: 116, quantity: 1, modifiers: [percentageFee16] };
389
+ // const newItem = pricingService.item.calculate(orderItem);
390
+
391
+ // expect(newItem).toHaveProperty('total', 116);
392
+ // expect(newItem).toHaveProperty('price', 116);
393
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
394
+ // amount: 16,
395
+ // description: 'percentageFee16 ($16.00)',
396
+ // });
397
+
398
+ // expect(newItem).toHaveProperty('subTotals', {
399
+ // tax: 16,
400
+ // _included: 0,
401
+ // _xincluded: 16,
402
+ // _direct: 0,
403
+ // _xdirect: 16,
404
+ // _simple: 100,
405
+ // _actual: 100,
406
+ // });
407
+ // });
408
+
409
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedDiscount16', () => {
410
+ // const fixedDiscount16 = {
411
+ // compute: {
412
+ // amount: 16,
413
+ // type: 'fixed',
414
+ // action: 'subtract',
415
+ // },
416
+ // properties: {
417
+ // extractCalculatedValue: true,
418
+ // },
419
+ // name: 'fixedDiscount16',
420
+ // type: 'discount',
421
+ // };
422
+
423
+ // const orderItem = {
424
+ // price: 116,
425
+ // quantity: 1,
426
+ // modifiers: [fixedDiscount16],
427
+ // };
428
+ // const newItem = pricingService.item.calculate(orderItem);
429
+
430
+ // expect(newItem).toHaveProperty('total', 116);
431
+ // expect(newItem).toHaveProperty('price', 116);
432
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
433
+ // amount: -16,
434
+ // description: 'fixedDiscount16 (-$16.00)',
435
+ // });
436
+
437
+ // expect(newItem).toHaveProperty('subTotals', {
438
+ // discount: -16,
439
+ // _included: 0,
440
+ // _xincluded: -16,
441
+ // _direct: 0,
442
+ // _xdirect: -16,
443
+ // _simple: 132,
444
+ // _actual: 132,
445
+ // });
446
+ // });
447
+
448
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16', () => {
449
+ // const fixedFee16 = {
450
+ // compute: {
451
+ // amount: 16,
452
+ // type: 'fixed',
453
+ // action: 'add',
454
+ // },
455
+ // properties: {
456
+ // extractCalculatedValue: true,
457
+ // },
458
+ // name: 'fixedFee16',
459
+ // type: 'tax',
460
+ // };
461
+
462
+ // const orderItem = {
463
+ // price: 116,
464
+ // quantity: 1,
465
+ // modifiers: [fixedFee16],
466
+ // };
467
+ // const newItem = pricingService.item.calculate(orderItem);
468
+
469
+ // expect(newItem).toHaveProperty('total', 116);
470
+ // expect(newItem).toHaveProperty('price', 116);
471
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
472
+ // amount: 16,
473
+ // description: 'fixedFee16 ($16.00)',
474
+ // });
475
+
476
+ // expect(newItem).toHaveProperty('subTotals', {
477
+ // tax: 16,
478
+ // _included: 0,
479
+ // _xincluded: 16,
480
+ // _direct: 0,
481
+ // _xdirect: 16,
482
+ // _simple: 100,
483
+ // _actual: 100,
484
+ // });
485
+ // });
486
+
487
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16 and other fixed fee of 10%', () => {
488
+ // const fixedFee16 = {
489
+ // compute: {
490
+ // amount: 16,
491
+ // type: 'fixed',
492
+ // action: 'add',
493
+ // },
494
+ // properties: {
495
+ // extractCalculatedValue: true,
496
+ // },
497
+ // name: 'fixedFee16',
498
+ // type: 'tax',
499
+ // modifierId: '11111',
500
+ // _id: '123',
501
+ // };
502
+
503
+ // const fixedFee10 = {
504
+ // compute: {
505
+ // amount: 10,
506
+ // type: 'fixed',
507
+ // action: 'add',
508
+ // },
509
+ // name: 'fixedFee10',
510
+ // type: 'tax',
511
+ // modifierId: '22222',
512
+ // _id: '234',
513
+ // };
514
+
515
+ // const orderItem = {
516
+ // price: 116,
517
+ // quantity: 1,
518
+ // modifiers: [fixedFee16, fixedFee10],
519
+ // };
520
+ // const newItem = pricingService.item.calculate(orderItem);
521
+
522
+ // expect(newItem).toHaveProperty('total', 126);
523
+ // expect(newItem).toHaveProperty('price', 116);
524
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
525
+ // amount: 16,
526
+ // description: 'fixedFee16 ($16.00)',
527
+ // });
528
+
529
+ // expect(newItem).toHaveProperty('subTotals', {
530
+ // tax: 26,
531
+ // _included: 0,
532
+ // _xincluded: 26,
533
+ // _direct: 0,
534
+ // _xdirect: 26,
535
+ // _simple: 100,
536
+ // _actual: 100,
537
+ // });
538
+ // });
539
+
540
+ // test('CU-86duwyvrr: Calculate item with modifier.extractCalculatedvalue=true fixedFee16 and other percentage fee of 10%', () => {
541
+ // const fixedFee16 = {
542
+ // compute: {
543
+ // amount: 16,
544
+ // type: 'fixed',
545
+ // action: 'add',
546
+ // },
547
+ // properties: {
548
+ // extractCalculatedValue: true,
549
+ // },
550
+ // name: 'fixedFee16',
551
+ // type: 'tax',
552
+ // _id: '123',
553
+ // modifierId: 1111,
554
+ // };
555
+
556
+ // const percentageFee10 = {
557
+ // compute: {
558
+ // amount: 10,
559
+ // type: 'percentage',
560
+ // action: 'add',
561
+ // },
562
+ // name: 'percentageFee10',
563
+ // type: 'tax',
564
+ // _id: '234',
565
+ // modifierId: 222,
566
+ // };
567
+
568
+ // const orderItem = {
569
+ // price: 116,
570
+ // quantity: 1,
571
+ // modifiers: [fixedFee16, percentageFee10],
572
+ // };
573
+ // const newItem = pricingService.item.calculate(orderItem);
574
+
575
+ // expect(newItem).toHaveProperty('total', 126);
576
+ // expect(newItem).toHaveProperty('price', 116);
577
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
578
+ // amount: 16,
579
+ // description: 'fixedFee16 ($16.00)',
580
+ // });
581
+ // expect(newItem.modifiers[1]).toHaveProperty('_computed', {
582
+ // amount: 10,
583
+ // description: 'percentageFee10 ($10.00)',
584
+ // });
585
+
586
+ // expect(newItem).toHaveProperty('subTotals', {
587
+ // tax: 26,
588
+ // _included: 0,
589
+ // _xincluded: 26,
590
+ // _direct: 0,
591
+ // _xdirect: 26,
592
+ // _simple: 100,
593
+ // _actual: 100,
594
+ // });
595
+ // });
596
+ // test('CU-86dvbn63z: Calculate item with quantity > 1 and modifierAmountFixed10', () => {
597
+ // const itemWithModifierAmountFixed10 = {
598
+ // name: "Men's 3pc Tuxedo",
599
+ // pieces: 3,
600
+ // total: 53.03,
601
+ // price: 13.5,
602
+ // quantity: 3,
603
+ // modifiers: [
604
+ // {
605
+ // _id: '675354ee39a47228afd1f1a4',
606
+ // attributes: ['override'],
607
+ // modifierId: '6751f7eeb60c71cefee138ee',
608
+ // name: 'Override modamount fixed 10',
609
+ // group: 'Upcharge',
610
+ // type: 'fee',
611
+ // tags: ['default', 'all'],
612
+ // direct: true,
613
+ // properties: {
614
+ // override: {
615
+ // type: 'fixed',
616
+ // field: 'amount',
617
+ // fixedValue: 10,
618
+ // multiplier: false,
619
+ // },
620
+ // },
621
+ // compute: { type: 'fixed', amount: 10, action: 'add' },
622
+ // },
623
+ // ],
624
+ // _id: '675354e939a47228afd1f199',
625
+
626
+ // itemId: '62cdbfd01ee1b400193281ee',
627
+ // };
628
+ // const newItem = pricingService.item.calculate(
629
+ // itemWithModifierAmountFixed10
630
+ // );
631
+
632
+ // expect(newItem).toHaveProperty('total', 50.5);
633
+ // expect(newItem).toHaveProperty('price', 13.5);
634
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
635
+ // amount: 10,
636
+ // description: 'Override modamount fixed 10 ($10.00)',
637
+ // });
638
+
639
+ // expect(newItem).toHaveProperty('subTotals', {
640
+ // fee: 10,
641
+ // _included: 0,
642
+ // _xincluded: 10,
643
+ // _direct: 10,
644
+ // _xdirect: 0,
645
+ // _simple: 40.5,
646
+ // _actual: 40.5,
647
+ // });
648
+ // });
649
+
650
+ // test('CU-86dvbn63z: Calculate item with quantity > 1 and modifierAmountFixed10 Multiplier', () => {
651
+ // const itemWithModifierAmountFixed10Multiplier = {
652
+ // name: "Men's 3pc Tuxedo",
653
+ // pieces: 3,
654
+ // total: 53.03,
655
+ // price: 13.5,
656
+ // quantity: 3,
657
+ // modifiers: [
658
+ // {
659
+ // _id: '675354ee39a47228afd1f1a4',
660
+ // attributes: ['override'],
661
+ // modifierId: '6751f7eeb60c71cefee138ee',
662
+ // name: 'Override modamount fixed 10',
663
+ // group: 'Upcharge',
664
+ // type: 'fee',
665
+ // tags: ['default', 'all'],
666
+ // direct: true,
667
+ // properties: {
668
+ // override: {
669
+ // type: 'fixed',
670
+ // field: 'amount',
671
+ // fixedValue: 10,
672
+ // multiplier: true,
673
+ // },
674
+ // },
675
+ // },
676
+ // ],
677
+ // _id: '675354e939a47228afd1f199',
678
+
679
+ // itemId: '62cdbfd01ee1b400193281ee',
680
+ // };
681
+ // const newItem = pricingService.item.calculate(
682
+ // itemWithModifierAmountFixed10Multiplier
683
+ // );
684
+
685
+ // expect(newItem).toHaveProperty('total', 70.5);
686
+ // expect(newItem).toHaveProperty('price', 13.5);
687
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
688
+ // amount: 30,
689
+ // description: 'Override modamount fixed 10 ($30.00)',
690
+ // });
691
+
692
+ // expect(newItem).toHaveProperty('subTotals', {
693
+ // fee: 30,
694
+ // _included: 0,
695
+ // _xincluded: 30,
696
+ // _direct: 30,
697
+ // _xdirect: 0,
698
+ // _simple: 40.5,
699
+ // _actual: 40.5,
700
+ // });
701
+ // });
702
+
703
+ // test('CU-86dvbn63z: Calculate item with quantity > 1 and quantity override modifier', () => {
704
+ // const quantityOverrideMod = {
705
+ // _id: '67535f3ab4c5ea63d2d7964b',
706
+ // attributes: ['override'],
707
+ // modifierId: '675359b5d08f91f558233f85',
708
+ // name: 'Override Item Quantity 5',
709
+ // group: 'Upcharge',
710
+ // type: 'tax',
711
+ // tags: ['default'],
712
+ // direct: true,
713
+ // properties: {
714
+ // subscription: {},
715
+ // override: { type: 'fixed', field: 'quantity', fixedValue: 5 },
716
+ // group: { items: [], modifiers: [] },
717
+ // department: {},
718
+ // sort: null,
719
+ // },
720
+ // compute: null,
721
+ // };
722
+ // const itemWithQuantityOverride5 = {
723
+ // name: "Men's 3pc Tuxedo",
724
+ // pieces: 3,
725
+ // total: 70.88,
726
+ // price: 13.5,
727
+ // quantity: 3,
728
+ // modifiers: [quantityOverrideMod],
729
+ // _id: '67535f34b4c5ea63d2d79640',
730
+ // itemId: '62cdbfd01ee1b400193281ee',
731
+ // menuRuleId: '65660855dfffaf2da26fb870',
732
+ // __typename: 'OrderItem',
733
+ // };
734
+ // let newItem = pricingService.item.calculate(itemWithQuantityOverride5);
735
+
736
+ // expect(newItem).toHaveProperty('total', 67.5);
737
+ // expect(newItem).toHaveProperty('price', 13.5);
738
+ // expect(newItem).toHaveProperty('quantity', 5);
739
+
740
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
741
+ // amount: 0,
742
+ // description: 'Override Item Quantity 5',
743
+ // });
744
+
745
+ // expect(newItem).toHaveProperty('subTotals', {
746
+ // _included: 0,
747
+ // _xincluded: 0,
748
+ // _direct: 0,
749
+ // _xdirect: 0,
750
+ // _simple: 67.5,
751
+ // _actual: 67.5,
752
+ // });
753
+
754
+ // newItem = pricingService.item.calculate(
755
+ // pricingService.item.removeModifiers({
756
+ // item: newItem,
757
+ // modifiers: [quantityOverrideMod],
758
+ // customer: undefined,
759
+ // order: { items: [newItem] },
760
+ // })
761
+ // );
762
+ // expect(newItem.price).toBe(13.5);
763
+ // expect(newItem.total).toBe(40.5);
764
+ // expect(newItem.quantity).toBe(3);
765
+
766
+ // expect(newItem.modifiers.length).toBe(0);
767
+
768
+ // expect(newItem).toHaveProperty('subTotals', {
769
+ // _included: 0,
770
+ // _xincluded: 0,
771
+ // _direct: 0,
772
+ // _xdirect: 0,
773
+ // _simple: 40.5,
774
+ // _actual: 40.5,
775
+ // });
776
+ // });
777
+
778
+ // test('CU-86dvbn63z: Calculate item with quantity > 1 and modifieritemPriceFixed10', () => {
779
+ // const itemWithModifierAmountFixed10 = {
780
+ // name: "Men's 3pc Tuxedo",
781
+ // pieces: 3,
782
+ // price: 10,
783
+ // quantity: 3,
784
+ // modifiers: [
785
+ // {
786
+ // _id: '675354ee39a47228afd1f1a4',
787
+ // attributes: ['override'],
788
+ // modifierId: '6751f7eeb60c71cefee138ee',
789
+ // name: 'Override item price fixed 10',
790
+ // group: 'Upcharge',
791
+ // type: 'fee',
792
+ // tags: ['default', 'all'],
793
+ // direct: true,
794
+ // properties: {
795
+ // override: {
796
+ // type: 'fixed',
797
+ // field: 'price',
798
+ // fixedValue: 10,
799
+ // multiplier: false,
800
+ // },
801
+ // },
802
+ // },
803
+ // ],
804
+ // _id: '675354e939a47228afd1f199',
805
+
806
+ // itemId: '62cdbfd01ee1b400193281ee',
807
+ // };
808
+ // const newItem = pricingService.item.calculate(
809
+ // itemWithModifierAmountFixed10
810
+ // );
811
+
812
+ // expect(newItem).toHaveProperty('total', 30);
813
+ // expect(newItem).toHaveProperty('price', 10);
814
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
815
+ // amount: 0,
816
+ // description: 'Override item price fixed 10 ($10.00/Unit)',
817
+ // });
818
+
819
+ // expect(newItem).toHaveProperty('subTotals', {
820
+ // _included: 0,
821
+ // _xincluded: 0,
822
+ // _direct: 0,
823
+ // _xdirect: 0,
824
+ // _simple: 30,
825
+ // _actual: 30,
826
+ // });
827
+ // });
828
+
829
+ // test('CU-86dvbn63z: Calculate item with quantity > 1 and modifieritemPriceFixed1 multiplier', () => {
830
+ // const item = {
831
+ // name: "Men's 3pc Tuxedo",
832
+ // pieces: 3,
833
+ // total: 141.75,
834
+ // price: 13.5,
835
+ // quantity: 1,
836
+ // modifiers: [
837
+ // {
838
+ // _id: '67536495bc57ccecf751a5dc',
839
+ // attributes: ['override'],
840
+ // modifierId: '6751e9c0b60c71cefee0c3cc',
841
+ // _parentId: null,
842
+ // locked: false,
843
+ // name: 'Override Item Price 10 USD Multiplier',
844
+ // group: 'Upcharge',
845
+ // type: 'fee',
846
+ // tags: ['default', 'all'],
847
+
848
+ // direct: true,
849
+
850
+ // properties: {
851
+ // override: {
852
+ // type: 'fixed',
853
+ // field: 'price',
854
+ // fixedValue: 10,
855
+ // multiplier: true,
856
+ // },
857
+ // },
858
+ // },
859
+ // ],
860
+ // _id: '675360d5bc57ccecf751a5b5',
861
+ // itemId: '62cdbfd01ee1b400193281ee',
862
+ // };
863
+ // const newItem = pricingService.item.calculate(item);
864
+
865
+ // expect(newItem).toHaveProperty('total', 135);
866
+ // expect(newItem).toHaveProperty('price', 135);
867
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
868
+ // amount: 0,
869
+ // description:
870
+ // 'Override Item Price 10 USD Multiplier (10 Unit @ $13.50/Unit)',
871
+ // });
872
+
873
+ // expect(newItem).toHaveProperty('subTotals', {
874
+ // _included: 0,
875
+ // _xincluded: 0,
876
+ // _direct: 0,
877
+ // _xdirect: 0,
878
+ // _simple: 135,
879
+ // _actual: 135,
880
+ // });
881
+ // });
882
+
883
+ // test('Remove Item', () => {
884
+ // const item1 = {
885
+ // _id: '1',
886
+ // };
887
+ // const item2 = {
888
+ // _id: '2',
889
+ // };
890
+
891
+ // const order = {
892
+ // items: [item1, item2],
893
+ // };
894
+ // const result = pricingService.order.removeItem({ order, item: item2 });
895
+
896
+ // expect(result.items).toMatchObject([{ _id: '1' }]);
897
+ // });
898
+
899
+ // test('Remove related Item', () => {
900
+ // const item1 = {
901
+ // _id: '1',
902
+ // itemId: 'a',
903
+ // };
904
+ // const item2 = {
905
+ // _id: '2',
906
+ // };
907
+ // const item3 = {
908
+ // _id: '3',
909
+ // properties: {
910
+ // relatedItem: true,
911
+ // parentId: item1._id,
912
+ // parentItemId: item1.itemId,
913
+ // },
914
+ // };
915
+
916
+ // const order = {
917
+ // items: [item1, item2, item3],
918
+ // };
919
+ // const result = pricingService.order.removeItem({ order, item: item3 });
920
+
921
+ // expect(result.items).toMatchObject([
922
+ // {
923
+ // _id: '1',
924
+ // },
925
+ // {
926
+ // _id: '2',
927
+ // },
928
+ // ]);
929
+ // });
930
+
931
+ // test('Remove parent Item having 1 related item', () => {
932
+ // const item1 = {
933
+ // _id: '1',
934
+ // itemId: 'a',
935
+ // };
936
+ // const item2 = {
937
+ // _id: '2',
938
+ // };
939
+ // const item3 = {
940
+ // _id: '3',
941
+ // properties: {
942
+ // relatedItem: true,
943
+ // parentId: item1._id,
944
+ // parentItemId: item1.itemId,
945
+ // },
946
+ // };
947
+
948
+ // const order = {
949
+ // items: [item1, item2, item3],
950
+ // };
951
+ // const result = pricingService.order.removeItem({ order, item: item1 });
952
+
953
+ // expect(result.items).toMatchObject([
954
+ // {
955
+ // _id: '2',
956
+ // },
957
+ // ]);
958
+ // });
959
+
960
+ // test('Remove parent Item, having more than 1 related item', () => {
961
+ // const item1 = {
962
+ // _id: '1',
963
+ // itemId: 'a',
964
+ // };
965
+ // const item2 = {
966
+ // _id: '2',
967
+ // };
968
+ // const item3 = {
969
+ // _id: '3',
970
+ // properties: {
971
+ // relatedItem: true,
972
+ // parentId: item1._id,
973
+ // parentItemId: item1.itemId,
974
+ // },
975
+ // };
976
+ // const item4 = {
977
+ // _id: '4',
978
+ // properties: {
979
+ // relatedItem: true,
980
+ // parentId: item1._id,
981
+ // parentItemId: item1.itemId,
982
+ // },
983
+ // };
984
+
985
+ // const order = {
986
+ // items: [item1, item2, item3, item4],
987
+ // };
988
+ // const result = pricingService.order.removeItem({ order, item: item1 });
989
+
990
+ // expect(result.items).toMatchObject([
991
+ // {
992
+ // _id: '2',
993
+ // },
994
+ // ]);
995
+ // });
996
+
997
+ // test('Remove related Item, having nested related items', () => {
998
+ // const item1 = {
999
+ // _id: '1',
1000
+ // itemId: 'a',
1001
+ // };
1002
+ // const item2 = {
1003
+ // _id: '2',
1004
+ // };
1005
+ // const item3 = {
1006
+ // _id: '3',
1007
+ // properties: {
1008
+ // relatedItem: true,
1009
+ // parentId: item1._id,
1010
+ // parentItemId: item1.itemId,
1011
+ // },
1012
+ // };
1013
+ // const item4 = {
1014
+ // _id: '4',
1015
+ // itemId: 'd',
1016
+ // properties: {
1017
+ // relatedItem: true,
1018
+ // parentId: item1._id,
1019
+ // parentItemId: item1.itemId,
1020
+ // },
1021
+ // };
1022
+
1023
+ // const nestedItem5 = {
1024
+ // _id: '5',
1025
+ // properties: {
1026
+ // relatedItem: true,
1027
+ // parentId: item4._id,
1028
+ // parentItemId: item4.itemId,
1029
+ // },
1030
+ // };
1031
+
1032
+ // const order = {
1033
+ // items: [item1, item2, item3, item4, nestedItem5],
1034
+ // };
1035
+ // const result = pricingService.order.removeItem({
1036
+ // order,
1037
+ // item: nestedItem5,
1038
+ // });
1039
+
1040
+ // expect(result.items).toMatchObject([item1, item2, item3, item4]);
1041
+ // });
1042
+
1043
+ // test('Remove related Item, having nested related items 2', () => {
1044
+ // const item1 = {
1045
+ // _id: '1',
1046
+ // itemId: 'a',
1047
+ // };
1048
+ // const item2 = {
1049
+ // _id: '2',
1050
+ // };
1051
+ // const item3 = {
1052
+ // _id: '3',
1053
+ // properties: {
1054
+ // relatedItem: true,
1055
+ // parentId: item1._id,
1056
+ // parentItemId: item1.itemId,
1057
+ // },
1058
+ // };
1059
+ // const item4 = {
1060
+ // _id: '4',
1061
+ // itemId: 'd',
1062
+ // properties: {
1063
+ // relatedItem: true,
1064
+ // parentId: item1._id,
1065
+ // parentItemId: item1.itemId,
1066
+ // },
1067
+ // };
1068
+
1069
+ // const nestedItem5 = {
1070
+ // _id: '5',
1071
+ // properties: {
1072
+ // relatedItem: true,
1073
+ // parentId: item4._id,
1074
+ // parentItemId: item4.itemId,
1075
+ // },
1076
+ // };
1077
+
1078
+ // const nestedItem6 = {
1079
+ // _id: '6',
1080
+ // properties: {
1081
+ // relatedItem: true,
1082
+ // parentId: item4._id,
1083
+ // parentItemId: item4.itemId,
1084
+ // },
1085
+ // };
1086
+
1087
+ // const order = {
1088
+ // items: [item1, item2, item3, item4, nestedItem5, nestedItem6],
1089
+ // };
1090
+ // const result = pricingService.order.removeItem({
1091
+ // order,
1092
+ // item: nestedItem5,
1093
+ // });
1094
+
1095
+ // expect(result.items).toMatchObject([
1096
+ // item1,
1097
+ // item2,
1098
+ // item3,
1099
+ // item4,
1100
+ // nestedItem6,
1101
+ // ]);
1102
+ // });
1103
+
1104
+ // test('Remove parent related Item, having nested related items', () => {
1105
+ // const item1 = {
1106
+ // _id: '1',
1107
+ // itemId: 'a',
1108
+ // };
1109
+ // const item2 = {
1110
+ // _id: '2',
1111
+ // };
1112
+ // const item3 = {
1113
+ // _id: '3',
1114
+ // properties: {
1115
+ // relatedItem: true,
1116
+ // parentId: item1._id,
1117
+ // parentItemId: item1.itemId,
1118
+ // },
1119
+ // };
1120
+ // const item4 = {
1121
+ // _id: '4',
1122
+ // itemId: 'd',
1123
+ // properties: {
1124
+ // relatedItem: true,
1125
+ // parentId: item1._id,
1126
+ // parentItemId: item1.itemId,
1127
+ // },
1128
+ // };
1129
+
1130
+ // const nestedItem5 = {
1131
+ // _id: '5',
1132
+ // properties: {
1133
+ // relatedItem: true,
1134
+ // parentId: item4._id,
1135
+ // parentItemId: item4.itemId,
1136
+ // },
1137
+ // };
1138
+
1139
+ // const nestedItem6 = {
1140
+ // _id: '6',
1141
+ // properties: {
1142
+ // relatedItem: true,
1143
+ // parentId: item4._id,
1144
+ // parentItemId: item4.itemId,
1145
+ // },
1146
+ // };
1147
+
1148
+ // const order = {
1149
+ // items: [item1, item2, item3, item4, nestedItem5, nestedItem6],
1150
+ // };
1151
+ // const result = pricingService.order.removeItem({ order, item: item1 });
1152
+
1153
+ // expect(result.items).toMatchObject([item2]);
1154
+ // });
1155
+
1156
+ // test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
1157
+ // const rawRelatedItem1 = {
1158
+ // name: 'the related item',
1159
+ // _id: '67e2cadd8dcf08ebcc5ef888',
1160
+ // };
1161
+
1162
+ // const rawRelatedItem2 = {
1163
+ // name: 'the 2nd related item',
1164
+ // _id: '67e2cadd8dcf08ebcc5ef88a',
1165
+ // };
1166
+
1167
+ // const groupMod = {
1168
+ // _id: '67e2cadd8dcf08ebcc5ef889',
1169
+ // name: 'General Repair Department',
1170
+ // attributes: ['group'],
1171
+ // modifierId: 'mod1',
1172
+ // properties: {
1173
+ // group: {
1174
+ // items: [],
1175
+ // },
1176
+ // },
1177
+ // };
1178
+
1179
+ // const parentItem = {
1180
+ // name: 'the parent item',
1181
+ // modifiers: [groupMod],
1182
+ // _id: '67e2cadd8dcf08ebcc5ef887',
1183
+ // __typename: 'OrderItem',
1184
+ // };
1185
+
1186
+ // const relatedItem1 = {
1187
+ // ...rawRelatedItem1,
1188
+ // properties: {
1189
+ // relatedItem: true,
1190
+ // parentId: parentItem._id,
1191
+ // includeParent: true,
1192
+ // addModifiers: [groupMod],
1193
+ // groupPath: ',67e2cadd8dcf08ebcc5ef889',
1194
+ // },
1195
+ // __typename: 'OrderItem',
1196
+ // };
1197
+
1198
+ // const relatedItem2 = {
1199
+ // ...rawRelatedItem2,
1200
+ // properties: {
1201
+ // relatedItem: true,
1202
+ // parentId: parentItem._id,
1203
+ // includeParent: true,
1204
+ // addModifiers: [groupMod],
1205
+ // groupPath: ',67e2cadd8dcf08ebcc5ef889',
1206
+ // },
1207
+ // __typename: 'OrderItem',
1208
+ // };
1209
+ // const order = {
1210
+ // items: [parentItem, relatedItem1, relatedItem2],
1211
+ // };
1212
+
1213
+ // const result = pricingService.order.removeItem({
1214
+ // order,
1215
+ // item: relatedItem2,
1216
+ // });
1217
+
1218
+ // expect(result.items.length).toBe(2);
1219
+ // expect(result.items[0].modifiers.length).toBe(1);
1220
+ // expect(result.items[0].modifiers[0].modifierId).toBe('mod1');
1221
+
1222
+ // const result2 = pricingService.order.removeItem({
1223
+ // order: result,
1224
+ // item: relatedItem1,
1225
+ // });
1226
+
1227
+ // expect(result2.items.length).toBe(1);
1228
+ // expect(result2.items[0].modifiers.length).toBe(0);
1229
+ // });
1230
+
1231
+ // test('Should not remove the group modifier if it still hasModifiers', () => {
1232
+ // const rawRelatedItem1 = {
1233
+ // name: 'the related item',
1234
+ // _id: '67e2cadd8dcf08ebcc5ef888',
1235
+ // };
1236
+
1237
+ // const rawRelatedItem2 = {
1238
+ // name: 'the 2nd related item',
1239
+ // _id: '67e2cadd8dcf08ebcc5ef88a',
1240
+ // };
1241
+
1242
+ // const rawRelatedMod1 = {
1243
+ // name: 'related modifier',
1244
+ // _id: '123',
1245
+ // modifierId: 'abc',
1246
+ // addModifiers: [
1247
+ // {
1248
+ // _id: '67e2cadd8dcf08ebcc5ef889',
1249
+ // name: 'General Repair Department',
1250
+ // attributes: ['group'],
1251
+ // modifierId: 'mod1',
1252
+ // properties: {
1253
+ // group: {
1254
+ // items: [],
1255
+ // },
1256
+ // },
1257
+ // },
1258
+ // ],
1259
+ // };
1260
+
1261
+ // const groupMod = {
1262
+ // _id: '67e2cadd8dcf08ebcc5ef889',
1263
+ // name: 'General Repair Department',
1264
+ // attributes: ['group'],
1265
+ // modifierId: 'mod1',
1266
+ // properties: {
1267
+ // group: {
1268
+ // items: [],
1269
+ // modifiers: [],
1270
+ // },
1271
+ // },
1272
+ // };
1273
+
1274
+ // const parentItem = {
1275
+ // name: 'the parent item',
1276
+ // modifiers: [groupMod, rawRelatedMod1],
1277
+ // _id: '67e2cadd8dcf08ebcc5ef887',
1278
+ // __typename: 'OrderItem',
1279
+ // };
1280
+
1281
+ // const relatedItem1 = {
1282
+ // ...rawRelatedItem1,
1283
+ // properties: {
1284
+ // relatedItem: true,
1285
+ // parentId: parentItem._id,
1286
+ // includeParent: true,
1287
+ // addModifiers: [groupMod],
1288
+ // groupPath: ',67e2cadd8dcf08ebcc5ef889',
1289
+ // },
1290
+ // __typename: 'OrderItem',
1291
+ // };
1292
+
1293
+ // const relatedItem2 = {
1294
+ // ...rawRelatedItem2,
1295
+ // properties: {
1296
+ // relatedItem: true,
1297
+ // parentId: parentItem._id,
1298
+ // includeParent: true,
1299
+ // addModifiers: [groupMod],
1300
+ // groupPath: ',67e2cadd8dcf08ebcc5ef889',
1301
+ // },
1302
+ // __typename: 'OrderItem',
1303
+ // };
1304
+ // const order = {
1305
+ // items: [parentItem, relatedItem1, relatedItem2],
1306
+ // };
1307
+
1308
+ // const newItem = pricingService.item.removeModifiers({
1309
+ // item: parentItem,
1310
+ // modifiers: [rawRelatedMod1],
1311
+ // originalItem: parentItem,
1312
+ // customer: undefined,
1313
+ // order,
1314
+ // });
1315
+
1316
+ // expect(newItem.modifiers.length).toBe(1);
1317
+ // expect(newItem.modifiers[0].name).toBe('General Repair Department');
1318
+ // });
1319
+
1320
+ // test('1- Item total should not be below 0, having price override modifiers', () => {
1321
+ // const order = {
1322
+ // _id: '685c2d2bd7f68fccd07af8c7',
1323
+ // tax: 0,
1324
+ // modifiers: [],
1325
+ // discount: 0,
1326
+ // total: -2.28,
1327
+ // fee: 0,
1328
+ // items: [
1329
+ // {
1330
+ // name: 'Pants',
1331
+ // description: null,
1332
+ // pieces: 1,
1333
+ // modifiersTotalAmount: 0,
1334
+ // total: -2.28,
1335
+ // totalPaid: 0,
1336
+ // price: 0,
1337
+ // quantity: 1,
1338
+ // notes: [],
1339
+ // modifiers: [
1340
+ // {
1341
+ // _id: '685c2d64d7f68fccd07af8cd',
1342
+ // attributes: ['override'],
1343
+ // modifierId: '67fea241af24e570c032b40d',
1344
+ // _parentId: null,
1345
+ // locked: false,
1346
+ // name: 'No Clean',
1347
+ // tags: ['default'],
1348
+ // order: 0,
1349
+ // included: false,
1350
+ // direct: true,
1351
+ // default: true,
1352
+ // code: null,
1353
+ // properties: {
1354
+ // override: {
1355
+ // field: 'price',
1356
+ // type: 'fixed',
1357
+ // multiplier: true,
1358
+ // fixedValue: 0,
1359
+ // },
1360
+ // group: null,
1361
+ // department: null,
1362
+ // url: null,
1363
+ // color: null,
1364
+ // label: {
1365
+ // backgroundColor: null,
1366
+ // align: null,
1367
+ // },
1368
+ // sort: null,
1369
+ // },
1370
+ // compute: null,
1371
+ // __typename: 'Modifier',
1372
+ // addModifiers: [],
1373
+ // delModifiers: [],
1374
+ // },
1375
+ // {
1376
+ // _id: '685c2d65d7f68fccd07af8ce',
1377
+ // attributes: [],
1378
+ // modifierId: '67fea241af24e570c032b324',
1379
+ // _parentId: null,
1380
+ // locked: false,
1381
+ // name: '30% Family Discount',
1382
+ // type: 'discount',
1383
+ // tags: ['default'],
1384
+ // order: 0,
1385
+ // included: false,
1386
+ // direct: true,
1387
+ // hidden: false,
1388
+ // print: true,
1389
+ // required: false,
1390
+ // recommended: false,
1391
+ // default: false,
1392
+ // code: null,
1393
+ // properties: {
1394
+ // group: null,
1395
+ // department: null,
1396
+ // url: null,
1397
+ // color: null,
1398
+ // label: {
1399
+ // backgroundColor: null,
1400
+ // align: null,
1401
+ // },
1402
+ // sort: null,
1403
+ // isQuantityMultiplier: true,
1404
+ // },
1405
+ // compute: {
1406
+ // type: 'percentage',
1407
+ // action: 'subtract',
1408
+ // amount: 30,
1409
+ // },
1410
+ // __typename: 'Modifier',
1411
+ // addModifiers: [],
1412
+ // delModifiers: [],
1413
+ // },
1414
+ // ],
1415
+ // weight: 0,
1416
+ // properties: {
1417
+ // overwrittenPrice: 7.59,
1418
+ // },
1419
+ // },
1420
+ // ],
1421
+ // customer: {
1422
+ // _id: '67feae8eeb5aa1e1848374b9',
1423
+ // tags: ['default'],
1424
+ // },
1425
+ // };
1426
+
1427
+ // const calculatedOrder = pricingService.order.calculate(order);
1428
+
1429
+ // expect(calculatedOrder.total).toBe(0);
1430
+ // expect(calculatedOrder.items[0].price).toBe(0);
1431
+ // expect(calculatedOrder.items[0].total).toBe(0);
1432
+ // expect(calculatedOrder.items[0].modifiers[0]._computed.description).toBe(
1433
+ // 'No Clean (0 Unit @ $0.00/Unit)'
1434
+ // );
1435
+ // expect(calculatedOrder.items[0].modifiers[1]._computed.description).toBe(
1436
+ // '30% Family Discount'
1437
+ // );
1438
+ // });
1439
+
1440
+ // test('2- Item total should not be below 0, having price override modifiers', () => {
1441
+ // const order = {
1442
+ // _id: '685c2d2bd7f68fccd07af8c7',
1443
+ // tax: 0,
1444
+ // modifiers: [],
1445
+ // discount: 0,
1446
+ // total: -2.28,
1447
+ // fee: 0,
1448
+ // items: [
1449
+ // {
1450
+ // name: 'Pants',
1451
+ // description: null,
1452
+ // pieces: 1,
1453
+ // modifiersTotalAmount: 0,
1454
+ // total: -2.28,
1455
+ // totalPaid: 0,
1456
+ // price: 0,
1457
+ // quantity: 1,
1458
+ // notes: [],
1459
+ // modifiers: [
1460
+ // {
1461
+ // _id: '685c2d65d7f68fccd07af8ce',
1462
+ // attributes: [],
1463
+ // modifierId: '67fea241af24e570c032b324',
1464
+ // _parentId: null,
1465
+ // locked: false,
1466
+ // name: '30% Family Discount',
1467
+ // type: 'discount',
1468
+ // tags: ['default'],
1469
+ // order: 0,
1470
+ // included: false,
1471
+ // direct: true,
1472
+ // hidden: false,
1473
+ // print: true,
1474
+ // required: false,
1475
+ // recommended: false,
1476
+ // default: false,
1477
+ // code: null,
1478
+ // properties: {
1479
+ // group: null,
1480
+ // department: null,
1481
+ // url: null,
1482
+ // color: null,
1483
+ // label: {
1484
+ // backgroundColor: null,
1485
+ // align: null,
1486
+ // },
1487
+ // sort: null,
1488
+ // isQuantityMultiplier: true,
1489
+ // },
1490
+ // compute: {
1491
+ // type: 'percentage',
1492
+ // action: 'subtract',
1493
+ // amount: 30,
1494
+ // },
1495
+ // __typename: 'Modifier',
1496
+ // addModifiers: [],
1497
+ // delModifiers: [],
1498
+ // },
1499
+ // {
1500
+ // _id: '685c2d64d7f68fccd07af8cd',
1501
+ // attributes: ['override'],
1502
+ // modifierId: '67fea241af24e570c032b40d',
1503
+ // _parentId: null,
1504
+ // locked: false,
1505
+ // name: 'No Clean',
1506
+ // tags: ['default'],
1507
+ // order: 0,
1508
+ // included: false,
1509
+ // direct: true,
1510
+ // default: true,
1511
+ // code: null,
1512
+ // properties: {
1513
+ // override: {
1514
+ // field: 'price',
1515
+ // type: 'fixed',
1516
+ // multiplier: true,
1517
+ // fixedValue: 0,
1518
+ // },
1519
+ // group: null,
1520
+ // department: null,
1521
+ // url: null,
1522
+ // color: null,
1523
+ // label: {
1524
+ // backgroundColor: null,
1525
+ // align: null,
1526
+ // },
1527
+ // sort: null,
1528
+ // },
1529
+ // compute: null,
1530
+ // __typename: 'Modifier',
1531
+ // addModifiers: [],
1532
+ // delModifiers: [],
1533
+ // },
1534
+ // ],
1535
+ // weight: 0,
1536
+ // properties: {
1537
+ // overwrittenPrice: 7.59,
1538
+ // },
1539
+ // },
1540
+ // ],
1541
+ // customer: {
1542
+ // _id: '67feae8eeb5aa1e1848374b9',
1543
+ // tags: ['default'],
1544
+ // },
1545
+ // };
1546
+
1547
+ // const calculatedOrder = pricingService.order.calculate(order);
1548
+
1549
+ // expect(calculatedOrder.total).toBe(0);
1550
+ // expect(calculatedOrder.items[0].price).toBe(0);
1551
+ // expect(calculatedOrder.items[0].total).toBe(0);
1552
+
1553
+ // expect(calculatedOrder.items[0].modifiers[0]._computed.description).toBe(
1554
+ // '30% Family Discount'
1555
+ // );
1556
+ // expect(calculatedOrder.items[0].modifiers[1]._computed.description).toBe(
1557
+ // 'No Clean (0 Unit @ $0.00/Unit)'
1558
+ // );
1559
+ // });
1560
+
1561
+ // test('Should not apply modifier value when extractCalculatedValue is true but modifier is invalid', () => {
1562
+ // const prepayDiscount50Percent = {
1563
+ // compute: {
1564
+ // amount: 50,
1565
+ // type: 'percentage',
1566
+ // action: 'subtract',
1567
+ // },
1568
+ // properties: {
1569
+ // extractCalculatedValue: true,
1570
+ // },
1571
+ // conditions: {
1572
+ // valid: null,
1573
+ // rules: [
1574
+ // {
1575
+ // key: 'payment',
1576
+ // value: 'prepay',
1577
+ // operand: '$in',
1578
+ // },
1579
+ // ],
1580
+ // },
1581
+ // name: 'percentageDiscount50',
1582
+ // type: 'discount',
1583
+ // };
1584
+
1585
+ // const orderItem = {
1586
+ // price: 7.59,
1587
+ // quantity: 1,
1588
+ // modifiers: [prepayDiscount50Percent],
1589
+ // };
1590
+ // const order = {
1591
+ // items: [orderItem],
1592
+ // };
1593
+
1594
+ // const calculatedOrder = pricingService.order.calculate(order);
1595
+
1596
+ // expect(calculatedOrder.total).toBe(7.59);
1597
+ // expect(calculatedOrder.items[0].price).toBe(7.59);
1598
+ // expect(calculatedOrder.items[0].total).toBe(7.59);
1599
+ // expect(calculatedOrder.items[0].modifiers.length).toBe(1);
1600
+ // expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1601
+ // amount: 0,
1602
+ // description: 'percentageDiscount50',
1603
+ // });
1604
+ // });
1605
+
1606
+ // test('Should apply modifier value when extractCalculatedValue is true and modifier is valid', () => {
1607
+ // const prepayDiscount50Percent = {
1608
+ // compute: {
1609
+ // amount: 50,
1610
+ // type: 'percentage',
1611
+ // action: 'subtract',
1612
+ // },
1613
+ // properties: {
1614
+ // extractCalculatedValue: true,
1615
+ // },
1616
+ // name: 'percentageDiscount50',
1617
+ // type: 'discount',
1618
+ // };
1619
+
1620
+ // const orderItem = {
1621
+ // price: 7.59,
1622
+ // quantity: 1,
1623
+ // modifiers: [prepayDiscount50Percent],
1624
+ // };
1625
+ // const order = {
1626
+ // items: [orderItem],
1627
+ // };
1628
+
1629
+ // const calculatedOrder = pricingService.order.calculate(order);
1630
+
1631
+ // expect(calculatedOrder.total).toBe(7.59);
1632
+ // expect(calculatedOrder.items[0].price).toBe(7.59);
1633
+ // expect(calculatedOrder.items[0].total).toBe(7.59);
1634
+ // expect(calculatedOrder.items[0].modifiers.length).toBe(1);
1635
+ // expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1636
+ // amount: -7.59,
1637
+ // description: 'percentageDiscount50 (-$7.59)',
1638
+ // });
1639
+ // });
1640
+
1641
+ // test('Should apply modifier value when extractCalculatedValue is true and modifier is valid (being also a payment modifier)', () => {
1642
+ // const prepayDiscount50Percent = {
1643
+ // compute: {
1644
+ // amount: 50,
1645
+ // type: 'percentage',
1646
+ // action: 'subtract',
1647
+ // },
1648
+ // properties: {
1649
+ // extractCalculatedValue: true,
1650
+ // },
1651
+ // conditions: {
1652
+ // valid: null,
1653
+ // rules: [
1654
+ // {
1655
+ // key: 'payment',
1656
+ // value: 'prepay',
1657
+ // operand: '$in',
1658
+ // },
1659
+ // ],
1660
+ // },
1661
+ // name: 'percentageDiscount50',
1662
+ // type: 'discount',
1663
+ // };
1664
+
1665
+ // const orderItem = {
1666
+ // price: 7.59,
1667
+ // quantity: 1,
1668
+ // modifiers: [prepayDiscount50Percent],
1669
+ // };
1670
+ // const order = {
1671
+ // items: [orderItem],
1672
+ // };
1673
+
1674
+ // const calculatedOrder = pricingService.order.calculate(order, {
1675
+ // isPrepay: true,
1676
+ // });
1677
+
1678
+ // expect(calculatedOrder.total).toBe(7.59);
1679
+ // expect(calculatedOrder.items[0].price).toBe(7.59);
1680
+ // expect(calculatedOrder.items[0].total).toBe(7.59);
1681
+ // expect(calculatedOrder.items[0].modifiers.length).toBe(2);
1682
+
1683
+ // expect(calculatedOrder.items[0].modifiers[0]._computed).toMatchObject({
1684
+ // amount: 0,
1685
+ // description: 'percentageDiscount50',
1686
+ // });
1687
+ // expect(calculatedOrder.items[0].modifiers[1]._computed).toMatchObject({
1688
+ // amount: -7.59,
1689
+ // description: '$7.59 discount (-$7.59)',
1690
+ // });
1691
+ // });
1692
+
1693
+ // test('Should use a price override modifier and quantity override modifier in combination accordingly', () => {
1694
+ // const overridePriceMod = {
1695
+ // _id: '675354ee39a47228afd1f1a4',
1696
+ // attributes: ['override'],
1697
+ // modifierId: '6751f7eeb60c71cefee138ee',
1698
+ // name: 'Override item price fixed 0',
1699
+ // tags: ['default', 'all'],
1700
+ // direct: true,
1701
+ // properties: {
1702
+ // override: {
1703
+ // type: 'fixed',
1704
+ // field: 'price',
1705
+ // fixedValue: 0,
1706
+ // multiplier: false,
1707
+ // },
1708
+ // },
1709
+ // };
1710
+ // const overrideQuantityMod = {
1711
+ // _id: '675354ee39a47228afd1f1a5',
1712
+ // attributes: ['override'],
1713
+ // modifierId: '6751f7eeb60c71cefee138ff',
1714
+ // name: 'Override item quantity fixed 20',
1715
+ // tags: ['default', 'all'],
1716
+ // direct: true,
1717
+ // properties: {
1718
+ // override: {
1719
+ // type: 'fixed',
1720
+ // field: 'quantity',
1721
+ // fixedValue: 20,
1722
+ // multiplier: false,
1723
+ // },
1724
+ // },
1725
+ // };
1726
+
1727
+ // const itemWithModifierAmountFixed10 = {
1728
+ // name: "Men's 3pc Tuxedo",
1729
+ // pieces: 1,
1730
+ // price: 10,
1731
+ // quantity: 1,
1732
+ // modifiers: [overridePriceMod, overrideQuantityMod],
1733
+ // _id: '675354e939a47228afd1f199',
1734
+ // itemId: '62cdbfd01ee1b400193281ee',
1735
+ // };
1736
+ // const newItem = pricingService.item.calculate(
1737
+ // itemWithModifierAmountFixed10
1738
+ // );
1739
+ // expect(newItem.price).toBe(0);
1740
+ // expect(newItem.total).toBe(0);
1741
+ // expect(newItem.quantity).toBe(20);
1742
+ // expect(newItem).toHaveProperty('price', 0);
1743
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1744
+ // amount: 0,
1745
+ // description: 'Override item price fixed 0 ($0.00/Unit)',
1746
+ // });
1747
+
1748
+ // expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1749
+ // amount: 0,
1750
+ // description: 'Override item quantity fixed 20',
1751
+ // });
1752
+
1753
+ // expect(newItem).toHaveProperty('subTotals', {
1754
+ // _included: 0,
1755
+ // _xincluded: 0,
1756
+ // _direct: 0,
1757
+ // _xdirect: 0,
1758
+ // _simple: 0,
1759
+ // _actual: 0,
1760
+ // });
1761
+ // });
1762
+
1763
+ // test('Should use a total override modifier and quantity override modifier in combination accordingly', () => {
1764
+ // const overrideTotalMod = {
1765
+ // _id: '675354ee39a47228afd1f1a4',
1766
+ // attributes: ['override'],
1767
+ // modifierId: '6751f7eeb60c71cefee138ee',
1768
+ // name: 'Override item total fixed 0',
1769
+ // tags: ['default', 'all'],
1770
+ // direct: true,
1771
+ // properties: {
1772
+ // override: {
1773
+ // type: 'fixed',
1774
+ // field: 'total',
1775
+ // fixedValue: 0,
1776
+ // multiplier: false,
1777
+ // },
1778
+ // sort: 2,
1779
+ // },
1780
+ // };
1781
+ // const overrideQuantityMod = {
1782
+ // _id: '675354ee39a47228afd1f1a5',
1783
+ // attributes: ['override'],
1784
+ // modifierId: '6751f7eeb60c71cefee138ff',
1785
+ // name: 'Override item quantity fixed 20',
1786
+ // tags: ['default', 'all'],
1787
+ // direct: true,
1788
+ // properties: {
1789
+ // override: {
1790
+ // type: 'fixed',
1791
+ // field: 'quantity',
1792
+ // fixedValue: 20,
1793
+ // multiplier: false,
1794
+ // },
1795
+ // sort: 1,
1796
+ // },
1797
+ // };
1798
+
1799
+ // const itemWithModifierAmountFixed10 = {
1800
+ // name: "Men's 3pc Tuxedo",
1801
+ // pieces: 1,
1802
+ // price: 10,
1803
+ // quantity: 1,
1804
+ // modifiers: [overrideTotalMod, overrideQuantityMod],
1805
+ // _id: '675354e939a47228afd1f199',
1806
+ // itemId: '62cdbfd01ee1b400193281ee',
1807
+ // };
1808
+ // const newItem = pricingService.item.calculate(
1809
+ // itemWithModifierAmountFixed10
1810
+ // );
1811
+ // expect(newItem.price).toBe(10);
1812
+ // expect(newItem.total).toBe(0);
1813
+ // expect(newItem.quantity).toBe(20);
1814
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1815
+ // amount: 0,
1816
+ // description: 'Override item quantity fixed 20',
1817
+ // });
1818
+
1819
+ // expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1820
+ // amount: -200,
1821
+ // description: 'Override item total fixed 0 (-$200.00)',
1822
+ // });
1823
+
1824
+ // expect(newItem).toHaveProperty('subTotals', {
1825
+ // _included: 0,
1826
+ // _xincluded: -200,
1827
+ // undefined: -200,
1828
+ // _direct: -200,
1829
+ // _xdirect: 0,
1830
+ // _simple: 200,
1831
+ // _actual: 200,
1832
+ // });
1833
+ // });
1834
+
1835
+ // test('Should calculate a price override modifier and a tax modifier properly', () => {
1836
+ // const overridePriceMod = {
1837
+ // _id: '675354ee39a47228afd1f1a4',
1838
+ // attributes: ['override'],
1839
+ // modifierId: '6751f7eeb60c71cefee138ee',
1840
+ // name: 'Override item price fixed 0',
1841
+ // tags: ['default', 'all'],
1842
+ // direct: true,
1843
+ // properties: {
1844
+ // override: {
1845
+ // type: 'fixed',
1846
+ // field: 'price',
1847
+ // fixedValue: 5,
1848
+ // multiplier: false,
1849
+ // },
1850
+ // },
1851
+ // };
1852
+
1853
+ // const percentageFee10 = {
1854
+ // compute: {
1855
+ // amount: 10,
1856
+ // type: 'percentage',
1857
+ // action: 'add',
1858
+ // },
1859
+ // name: 'percentageFee10',
1860
+ // type: 'tax',
1861
+ // _id: '234',
1862
+ // modifierId: 222,
1863
+ // };
1864
+
1865
+ // const itemWithModifierAmountFixed10 = {
1866
+ // name: "Men's 3pc Tuxedo",
1867
+ // pieces: 1,
1868
+ // price: 10,
1869
+ // quantity: 1,
1870
+ // modifiers: [overridePriceMod, percentageFee10],
1871
+ // _id: '675354e939a47228afd1f199',
1872
+ // itemId: '62cdbfd01ee1b400193281ee',
1873
+ // };
1874
+ // const newItem = pricingService.item.calculate(
1875
+ // itemWithModifierAmountFixed10
1876
+ // );
1877
+ // expect(newItem.price).toBe(5);
1878
+ // expect(newItem.total).toBe(5.5);
1879
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1880
+ // amount: 0,
1881
+ // description: 'Override item price fixed 0 ($5.00/Unit)',
1882
+ // });
1883
+
1884
+ // expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1885
+ // amount: 0.5,
1886
+ // description: 'percentageFee10 ($0.50)',
1887
+ // });
1888
+
1889
+ // expect(newItem).toHaveProperty('subTotals', {
1890
+ // _included: 0,
1891
+ // _xincluded: 0.5,
1892
+ // _direct: 0,
1893
+ // _xdirect: 0.5,
1894
+ // _simple: 5,
1895
+ // _actual: 5,
1896
+ // tax: 0.5,
1897
+ // });
1898
+ // });
1899
+
1900
+ // test('Should calculate a tax modifier and a price override modifier properly', () => {
1901
+ // const overridePriceMod = {
1902
+ // _id: '675354ee39a47228afd1f1a4',
1903
+ // attributes: ['override'],
1904
+ // modifierId: '6751f7eeb60c71cefee138ee',
1905
+ // name: 'Override item price fixed 0',
1906
+ // tags: ['default', 'all'],
1907
+ // direct: true,
1908
+ // properties: {
1909
+ // override: {
1910
+ // type: 'fixed',
1911
+ // field: 'price',
1912
+ // fixedValue: 5,
1913
+ // multiplier: false,
1914
+ // },
1915
+ // },
1916
+ // };
1917
+
1918
+ // const percentageFee10 = {
1919
+ // compute: {
1920
+ // amount: 10,
1921
+ // type: 'percentage',
1922
+ // action: 'add',
1923
+ // },
1924
+ // name: 'percentageFee10',
1925
+ // type: 'tax',
1926
+ // _id: '234',
1927
+ // modifierId: 222,
1928
+ // };
1929
+
1930
+ // const itemWithModifierAmountFixed10 = {
1931
+ // name: "Men's 3pc Tuxedo",
1932
+ // pieces: 1,
1933
+ // price: 10,
1934
+ // quantity: 1,
1935
+ // modifiers: [percentageFee10, overridePriceMod],
1936
+ // _id: '675354e939a47228afd1f199',
1937
+ // itemId: '62cdbfd01ee1b400193281ee',
1938
+ // };
1939
+ // const newItem = pricingService.item.calculate(
1940
+ // itemWithModifierAmountFixed10
1941
+ // );
1942
+ // expect(newItem.price).toBe(5);
1943
+ // expect(newItem.total).toBe(6);
1944
+
1945
+ // expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1946
+ // amount: 1,
1947
+ // description: 'percentageFee10 ($1.00)',
1948
+ // });
1949
+
1950
+ // expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1951
+ // amount: 0,
1952
+ // description: 'Override item price fixed 0 ($5.00/Unit)',
1953
+ // });
1954
+
1955
+ // expect(newItem).toHaveProperty('subTotals', {
1956
+ // _included: 0,
1957
+ // _xincluded: 1,
1958
+ // _direct: 0,
1959
+ // _xdirect: 1,
1960
+ // _simple: 5,
1961
+ // _actual: 5,
1962
+ // tax: 1,
1963
+ // });
1964
+ // });
1965
+
1966
+ test('Should mark modifers as not valid if quantity is 0, then after changing the quantity to > 0 it should mark modifier valid', () => {
1694
1967
  const overridePriceMod = {
1695
1968
  _id: '675354ee39a47228afd1f1a4',
1696
1969
  attributes: ['override'],
@@ -1702,23 +1975,7 @@ describe('Item actions', () => {
1702
1975
  override: {
1703
1976
  type: 'fixed',
1704
1977
  field: 'price',
1705
- fixedValue: 0,
1706
- multiplier: false,
1707
- },
1708
- },
1709
- };
1710
- const overrideQuantityMod = {
1711
- _id: '675354ee39a47228afd1f1a5',
1712
- attributes: ['override'],
1713
- modifierId: '6751f7eeb60c71cefee138ff',
1714
- name: 'Override item quantity fixed 20',
1715
- tags: ['default', 'all'],
1716
- direct: true,
1717
- properties: {
1718
- override: {
1719
- type: 'fixed',
1720
- field: 'quantity',
1721
- fixedValue: 20,
1978
+ fixedValue: 5,
1722
1979
  multiplier: false,
1723
1980
  },
1724
1981
  },
@@ -1728,27 +1985,20 @@ describe('Item actions', () => {
1728
1985
  name: "Men's 3pc Tuxedo",
1729
1986
  pieces: 1,
1730
1987
  price: 10,
1731
- quantity: 1,
1732
- modifiers: [overridePriceMod, overrideQuantityMod],
1988
+ quantity: 0,
1989
+ modifiers: [overridePriceMod],
1733
1990
  _id: '675354e939a47228afd1f199',
1734
1991
  itemId: '62cdbfd01ee1b400193281ee',
1735
1992
  };
1736
- const newItem = pricingService.item.calculate(
1737
- itemWithModifierAmountFixed10
1738
- );
1739
- expect(newItem.price).toBe(0);
1993
+ let newItem = pricingService.item.calculate(itemWithModifierAmountFixed10);
1994
+ expect(newItem.price).toBe(10);
1740
1995
  expect(newItem.total).toBe(0);
1741
- expect(newItem.quantity).toBe(20);
1742
- expect(newItem).toHaveProperty('price', 0);
1743
- expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1744
- amount: 0,
1745
- description: 'Override item price fixed 0 ($0.00/Unit)',
1746
- });
1747
1996
 
1748
- expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1997
+ expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1749
1998
  amount: 0,
1750
- description: 'Override item quantity fixed 20',
1999
+ description: 'Override item price fixed 0 ($5.00/Unit)',
1751
2000
  });
2001
+ expect(newItem.modifiers[0].conditions.valid).toBe(false);
1752
2002
 
1753
2003
  expect(newItem).toHaveProperty('subTotals', {
1754
2004
  _included: 0,
@@ -1758,77 +2008,24 @@ describe('Item actions', () => {
1758
2008
  _simple: 0,
1759
2009
  _actual: 0,
1760
2010
  });
1761
- });
1762
2011
 
1763
- test('Should use a total override modifier and quantity override modifier in combination accordingly', () => {
1764
- const overrideTotalMod = {
1765
- _id: '675354ee39a47228afd1f1a4',
1766
- attributes: ['override'],
1767
- modifierId: '6751f7eeb60c71cefee138ee',
1768
- name: 'Override item total fixed 0',
1769
- tags: ['default', 'all'],
1770
- direct: true,
1771
- properties: {
1772
- override: {
1773
- type: 'fixed',
1774
- field: 'total',
1775
- fixedValue: 0,
1776
- multiplier: false,
1777
- },
1778
- sort: 2,
1779
- },
1780
- };
1781
- const overrideQuantityMod = {
1782
- _id: '675354ee39a47228afd1f1a5',
1783
- attributes: ['override'],
1784
- modifierId: '6751f7eeb60c71cefee138ff',
1785
- name: 'Override item quantity fixed 20',
1786
- tags: ['default', 'all'],
1787
- direct: true,
1788
- properties: {
1789
- override: {
1790
- type: 'fixed',
1791
- field: 'quantity',
1792
- fixedValue: 20,
1793
- multiplier: false,
1794
- },
1795
- sort: 1,
1796
- },
1797
- };
2012
+ newItem = pricingService.item.calculate({ ...newItem, quantity: 1 });
2013
+ expect(newItem.price).toBe(5);
2014
+ expect(newItem.total).toBe(5);
1798
2015
 
1799
- const itemWithModifierAmountFixed10 = {
1800
- name: "Men's 3pc Tuxedo",
1801
- pieces: 1,
1802
- price: 10,
1803
- quantity: 1,
1804
- modifiers: [overrideTotalMod, overrideQuantityMod],
1805
- _id: '675354e939a47228afd1f199',
1806
- itemId: '62cdbfd01ee1b400193281ee',
1807
- };
1808
- const newItem = pricingService.item.calculate(
1809
- itemWithModifierAmountFixed10
1810
- );
1811
- expect(newItem.price).toBe(10);
1812
- expect(newItem.total).toBe(0);
1813
- expect(newItem.quantity).toBe(20);
1814
2016
  expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1815
2017
  amount: 0,
1816
- description: 'Override item quantity fixed 20',
1817
- });
1818
-
1819
- expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1820
- amount: -200,
1821
- description: 'Override item total fixed 0 (-$200.00)',
2018
+ description: 'Override item price fixed 0 ($5.00/Unit)',
1822
2019
  });
2020
+ expect(newItem.modifiers[0].conditions.valid).toBe(true);
1823
2021
 
1824
2022
  expect(newItem).toHaveProperty('subTotals', {
1825
2023
  _included: 0,
1826
- _xincluded: -200,
1827
- undefined: -200,
1828
- _direct: -200,
2024
+ _xincluded: 0,
2025
+ _direct: 0,
1829
2026
  _xdirect: 0,
1830
- _simple: 200,
1831
- _actual: 200,
2027
+ _simple: 5,
2028
+ _actual: 5,
1832
2029
  });
1833
2030
  });
1834
2031
  });