@darkpos/pricing 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,7 +94,6 @@ describe('Order actions', () => {
94
94
  expect(newOrder).toHaveProperty('subTotals', {
95
95
  discount: -6,
96
96
  });
97
- // console.log(JSON.stringify(newOrder, 0, 2));
98
97
  });
99
98
  test('Get calculated Order, multiple items and indirect modifiers', () => {
100
99
  const item1 = {
@@ -125,23 +124,23 @@ describe('Order actions', () => {
125
124
  expect(newOrder).toHaveProperty('subTotals', {
126
125
  discount: -2,
127
126
  });
128
- expect(newOrder.items[0]).toHaveProperty('total', 58.28);
127
+ expect(newOrder.items[0]).toHaveProperty('total', 58.29);
129
128
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
130
- discount: -1.72,
129
+ discount: -1.71,
131
130
  _included: 0,
132
- _xincluded: -1.72,
131
+ _xincluded: -1.71,
133
132
  _direct: 0,
134
- _xdirect: -1.72,
133
+ _xdirect: -1.71,
135
134
  _simple: 60,
136
135
  _actual: 60,
137
136
  });
138
- expect(newOrder.items[1]).toHaveProperty('total', 9.72);
137
+ expect(newOrder.items[1]).toHaveProperty('total', 9.71);
139
138
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
140
- discount: -0.28,
139
+ discount: -0.29,
141
140
  _included: 0,
142
- _xincluded: -0.28,
141
+ _xincluded: -0.29,
143
142
  _direct: 0,
144
- _xdirect: -0.28,
143
+ _xdirect: -0.29,
145
144
  _simple: 10,
146
145
  _actual: 10,
147
146
  });
@@ -169,10 +168,10 @@ describe('Order actions', () => {
169
168
 
170
169
  const order = { items: [item1, item2], modifiers: [modifier1] };
171
170
  const newOrder = pricingService.order.calculate(order);
172
- expect(newOrder).toHaveProperty('total', 18.58);
171
+ expect(newOrder).toHaveProperty('total', 18.57);
173
172
  expect(newOrder).toHaveProperty('subTotal', 20.64);
174
173
  expect(newOrder).toHaveProperty('subTotals', {
175
- discount: -2.06,
174
+ discount: -2.07,
176
175
  });
177
176
  expect(newOrder.items[0]).toHaveProperty('total', 14.39);
178
177
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
@@ -184,13 +183,13 @@ describe('Order actions', () => {
184
183
  _simple: 15.99,
185
184
  _actual: 15.99,
186
185
  });
187
- expect(newOrder.items[1]).toHaveProperty('total', 4.19);
186
+ expect(newOrder.items[1]).toHaveProperty('total', 4.18);
188
187
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
189
- discount: -0.46,
188
+ discount: -0.47,
190
189
  _included: 0,
191
- _xincluded: -0.46,
190
+ _xincluded: -0.47,
192
191
  _direct: 0,
193
- _xdirect: -0.46,
192
+ _xdirect: -0.47,
194
193
  _simple: 4.65,
195
194
  _actual: 4.65,
196
195
  });
@@ -246,19 +245,1030 @@ describe('Order actions', () => {
246
245
  });
247
246
  });
248
247
 
248
+ test('Get calculated Order, multiple items and indirect modifiers with sort # 1', () => {
249
+ const item1 = {
250
+ _id: 1,
251
+ price: 3,
252
+ quantity: 1,
253
+ };
254
+ const item2 = {
255
+ _id: 2,
256
+ price: 3,
257
+ quantity: 1,
258
+ };
259
+ const item3 = {
260
+ _id: 3,
261
+ price: 4,
262
+ quantity: 1,
263
+ };
264
+ const modifier1 = {
265
+ _id: 1,
266
+ compute: {
267
+ amount: 10,
268
+ type: 'percentage',
269
+ action: 'subtract',
270
+ },
271
+ name: `10% Discount`,
272
+ type: 'discount',
273
+ };
274
+
275
+ const modifier2 = {
276
+ _id: 2,
277
+ name: `20% tax`,
278
+ type: 'tax',
279
+ compute: {
280
+ amount: 20,
281
+ type: 'percentage',
282
+ action: 'add',
283
+ },
284
+ };
285
+
286
+ const order = {
287
+ items: [item1, item2, item3],
288
+ modifiers: [modifier2, modifier1],
289
+ };
290
+ const newOrder = pricingService.order.calculate(order);
291
+ expect(newOrder).toHaveProperty('total', 11);
292
+ expect(newOrder).toHaveProperty('subTotal', 10);
293
+ expect(newOrder).toHaveProperty('subTotals', {
294
+ discount: -1,
295
+ tax: 2,
296
+ });
297
+ });
298
+
299
+ test('Get calculated Order, multiple items and indirect modifiers with sort # 2', () => {
300
+ const item1 = {
301
+ _id: 1,
302
+ price: 3,
303
+ quantity: 1,
304
+ };
305
+ const item2 = {
306
+ _id: 2,
307
+ price: 3,
308
+ quantity: 1,
309
+ };
310
+ const item3 = {
311
+ _id: 3,
312
+ price: 4,
313
+ quantity: 1,
314
+ };
315
+ const modifier1 = {
316
+ _id: 1,
317
+ compute: {
318
+ amount: 10,
319
+ type: 'percentage',
320
+ action: 'subtract',
321
+ },
322
+ name: `10% Discount`,
323
+ type: 'discount',
324
+ properties: {
325
+ sort: 1,
326
+ },
327
+ };
328
+
329
+ const modifier2 = {
330
+ _id: 2,
331
+ name: `20% tax`,
332
+ type: 'tax',
333
+ compute: {
334
+ amount: 20,
335
+ type: 'percentage',
336
+ action: 'add',
337
+ },
338
+ properties: {
339
+ sort: 2,
340
+ },
341
+ };
342
+
343
+ const order = {
344
+ items: [item1, item2, item3],
345
+ modifiers: [modifier2, modifier1],
346
+ };
347
+ const newOrder = pricingService.order.calculate(order);
348
+ expect(newOrder).toHaveProperty('total', 10.8);
349
+ expect(newOrder).toHaveProperty('subTotal', 10);
350
+ expect(newOrder).toHaveProperty('subTotals', {
351
+ discount: -1,
352
+ tax: 1.8,
353
+ });
354
+ });
355
+
356
+ test('Get calculated Order, multiple items and indirect modifiers with sort #3', () => {
357
+ const item1 = {
358
+ _id: 1,
359
+ price: 3,
360
+ quantity: 1,
361
+ };
362
+ const item2 = {
363
+ _id: 2,
364
+ price: 3,
365
+ quantity: 1,
366
+ };
367
+ const item3 = {
368
+ _id: 3,
369
+ price: 4,
370
+ quantity: 1,
371
+ };
372
+ const modifier1 = {
373
+ _id: 1,
374
+ compute: {
375
+ amount: 10,
376
+ type: 'percentage',
377
+ action: 'subtract',
378
+ },
379
+ name: `10% Discount`,
380
+ type: 'discount',
381
+ properties: {
382
+ sort: 2,
383
+ },
384
+ };
385
+
386
+ const modifier2 = {
387
+ _id: 2,
388
+ name: `20% tax`,
389
+ type: 'tax',
390
+ compute: {
391
+ amount: 20,
392
+ type: 'percentage',
393
+ action: 'add',
394
+ },
395
+ properties: {
396
+ sort: 1,
397
+ },
398
+ };
399
+
400
+ const order = {
401
+ items: [item1, item2, item3],
402
+ modifiers: [modifier1, modifier2],
403
+ };
404
+ const newOrder = pricingService.order.calculate(order);
405
+ expect(newOrder).toHaveProperty('total', 10.8);
406
+ expect(newOrder).toHaveProperty('subTotal', 10);
407
+ expect(newOrder).toHaveProperty('subTotals', {
408
+ discount: -1.2,
409
+ tax: 2,
410
+ });
411
+ });
412
+
413
+ test('Get calculated Order, multiple items and indirect modifiers with sort #4', () => {
414
+ const item1 = {
415
+ _id: 1,
416
+ price: 3,
417
+ quantity: 1,
418
+ };
419
+ const item2 = {
420
+ _id: 2,
421
+ price: 3,
422
+ quantity: 1,
423
+ };
424
+ const item3 = {
425
+ _id: 3,
426
+ price: 4,
427
+ quantity: 1,
428
+ };
429
+ const modifier1 = {
430
+ _id: 1,
431
+ compute: {
432
+ amount: 5,
433
+ type: 'fixed',
434
+ action: 'subtract',
435
+ },
436
+ name: `5$ Discount`,
437
+ type: 'discount',
438
+ properties: {
439
+ sort: 2,
440
+ },
441
+ };
442
+
443
+ const modifier2 = {
444
+ _id: 2,
445
+ name: `20% tax`,
446
+ type: 'tax',
447
+ compute: {
448
+ amount: 20,
449
+ type: 'percentage',
450
+ action: 'add',
451
+ },
452
+ };
453
+
454
+ const order = {
455
+ items: [item1, item2, item3],
456
+ modifiers: [modifier1, modifier2],
457
+ };
458
+ const newOrder = pricingService.order.calculate(order);
459
+ expect(newOrder).toHaveProperty('total', 7);
460
+ expect(newOrder).toHaveProperty('subTotal', 10);
461
+ expect(newOrder).toHaveProperty('subTotals', {
462
+ discount: -5,
463
+ tax: 2,
464
+ });
465
+ });
466
+
467
+ test('Get calculated Order, multiple items and indirect modifiers with sort #5', () => {
468
+ const item1 = {
469
+ _id: 1,
470
+ price: 3,
471
+ quantity: 1,
472
+ };
473
+ const item2 = {
474
+ _id: 2,
475
+ price: 3,
476
+ quantity: 1,
477
+ };
478
+ const item3 = {
479
+ _id: 3,
480
+ price: 4,
481
+ quantity: 1,
482
+ };
483
+ const modifier1 = {
484
+ _id: 1,
485
+ compute: {
486
+ amount: 5,
487
+ type: 'fixed',
488
+ action: 'subtract',
489
+ },
490
+ name: `5$ Discount`,
491
+ type: 'discount',
492
+ };
493
+
494
+ const modifier2 = {
495
+ _id: 2,
496
+ name: `20% tax`,
497
+ type: 'tax',
498
+ compute: {
499
+ amount: 20,
500
+ type: 'percentage',
501
+ action: 'add',
502
+ },
503
+ };
504
+
505
+ const order = {
506
+ items: [item1, item2, item3],
507
+ modifiers: [modifier1, modifier2],
508
+ };
509
+ const newOrder = pricingService.order.calculate(order);
510
+ expect(newOrder).toHaveProperty('total', 7);
511
+ expect(newOrder).toHaveProperty('subTotal', 10);
512
+ expect(newOrder).toHaveProperty('subTotals', {
513
+ discount: -5,
514
+ tax: 2,
515
+ });
516
+ });
517
+
518
+ test('Get calculated Order, multiple items and indirect modifiers with sort #6', () => {
519
+ const item1 = {
520
+ _id: 1,
521
+ price: 3,
522
+ quantity: 1,
523
+ };
524
+ const item2 = {
525
+ _id: 2,
526
+ price: 3,
527
+ quantity: 1,
528
+ };
529
+ const item3 = {
530
+ _id: 3,
531
+ price: 4,
532
+ quantity: 1,
533
+ };
534
+ const modifier1 = {
535
+ _id: 1,
536
+ compute: {
537
+ amount: 5,
538
+ type: 'percentage',
539
+ action: 'subtract',
540
+ },
541
+ name: `5% Discount`,
542
+ type: 'discount',
543
+ properties: {
544
+ sort: 2,
545
+ },
546
+ };
547
+
548
+ const modifier2 = {
549
+ _id: 2,
550
+ name: `20% tax`,
551
+ type: 'tax',
552
+ compute: {
553
+ amount: 20,
554
+ type: 'percentage',
555
+ action: 'add',
556
+ },
557
+ };
558
+
559
+ const order = {
560
+ items: [item1, item2, item3],
561
+ modifiers: [modifier1, modifier2],
562
+ };
563
+ const newOrder = pricingService.order.calculate(order);
564
+ expect(newOrder).toHaveProperty('total', 11.5);
565
+ expect(newOrder).toHaveProperty('subTotal', 10);
566
+ expect(newOrder).toHaveProperty('subTotals', {
567
+ discount: -0.5,
568
+ tax: 2,
569
+ });
570
+ });
571
+
572
+ test('Get calculated Order, multiple items and indirect modifiers with sort # 7', () => {
573
+ const item1 = {
574
+ _id: 1,
575
+ price: 3,
576
+ quantity: 1,
577
+ };
578
+ const item2 = {
579
+ _id: 2,
580
+ price: 3,
581
+ quantity: 1,
582
+ };
583
+ const item3 = {
584
+ _id: 3,
585
+ price: 4,
586
+ quantity: 1,
587
+ };
588
+ const modifier1 = {
589
+ _id: 1,
590
+ compute: {
591
+ amount: 10,
592
+ type: 'percentage',
593
+ action: 'subtract',
594
+ },
595
+ name: `10% Discount`,
596
+ type: 'discount',
597
+ properties: {
598
+ sort: 1,
599
+ },
600
+ };
601
+
602
+ const modifier2 = {
603
+ _id: 2,
604
+ name: `20% tax`,
605
+ type: 'tax',
606
+ compute: {
607
+ amount: 20,
608
+ type: 'percentage',
609
+ action: 'add',
610
+ },
611
+ properties: {
612
+ sort: 1,
613
+ },
614
+ };
615
+
616
+ const order = {
617
+ items: [item1, item2, item3],
618
+ modifiers: [modifier2, modifier1],
619
+ };
620
+ const newOrder = pricingService.order.calculate(order);
621
+ expect(newOrder).toHaveProperty('total', 11);
622
+ expect(newOrder).toHaveProperty('subTotal', 10);
623
+ expect(newOrder).toHaveProperty('subTotals', {
624
+ discount: -1,
625
+ tax: 2,
626
+ });
627
+ });
628
+
629
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 order tax (sort 99)', () => {
630
+ const item1 = {
631
+ _id: 1,
632
+ price: 44,
633
+ quantity: 2,
634
+ };
635
+ const item2 = {
636
+ _id: 2,
637
+ price: 14.95,
638
+ quantity: 1,
639
+ };
640
+ const item3 = {
641
+ _id: 3,
642
+ price: 2.15,
643
+ quantity: 3,
644
+ };
645
+ const discountMod = {
646
+ _id: 1,
647
+ compute: {
648
+ amount: 15,
649
+ type: 'percentage',
650
+ action: 'subtract',
651
+ },
652
+ name: `15% Discount`,
653
+ type: 'discount',
654
+ properties: {
655
+ sort: 1,
656
+ },
657
+ };
658
+ const taxMod = {
659
+ _id: 2,
660
+ name: `7.75% tax`,
661
+ type: 'tax',
662
+ compute: {
663
+ amount: 7.75,
664
+ type: 'percentage',
665
+ action: 'add',
666
+ },
667
+ properties: {
668
+ sort: 99,
669
+ },
670
+ };
671
+
672
+ const order = {
673
+ items: [item1, item2, item3],
674
+ modifiers: [discountMod, taxMod],
675
+ };
676
+
677
+ const newOrder = pricingService.order.calculate(order);
678
+
679
+ expect(newOrder).toHaveProperty('total', 100.2);
680
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
681
+ expect(newOrder).toHaveProperty('subTotals', {
682
+ discount: -16.41,
683
+ tax: 7.21,
684
+ });
685
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
686
+ expect(newOrder.items[1]).toHaveProperty('total', 13.7);
687
+ expect(newOrder.items[2]).toHaveProperty('total', 5.9);
688
+ expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
689
+ 'amount',
690
+ 13.2
691
+ );
692
+ expect(newOrder.items[0].modifiers[1].compute).toHaveProperty(
693
+ 'amount',
694
+ 5.8
695
+ );
696
+
697
+ expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
698
+ 'amount',
699
+ 2.24
700
+ );
701
+ expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
702
+ 'amount',
703
+ 0.99
704
+ );
705
+
706
+ expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
707
+ 'amount',
708
+ 0.97
709
+ );
710
+ expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
711
+ 'amount',
712
+ 0.42
713
+ );
714
+ });
715
+
716
+ test(`CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 item tax (sort 99)`, () => {
717
+ const taxMod = {
718
+ _id: 2,
719
+ name: `7.75% tax`,
720
+ type: 'tax',
721
+ compute: {
722
+ amount: 7.75,
723
+ type: 'percentage',
724
+ action: 'add',
725
+ },
726
+ properties: {
727
+ sort: 99,
728
+ },
729
+ };
730
+
731
+ const discountMod = {
732
+ _id: 1,
733
+ compute: {
734
+ amount: 15,
735
+ type: 'percentage',
736
+ action: 'subtract',
737
+ },
738
+ name: `15% Discount`,
739
+ type: 'discount',
740
+ properties: {
741
+ sort: 1,
742
+ },
743
+ };
744
+
745
+ const item1 = {
746
+ _id: 1,
747
+ price: 44,
748
+ quantity: 2,
749
+ modifiers: [taxMod],
750
+ };
751
+ const item2 = {
752
+ _id: 2,
753
+ price: 14.95,
754
+ quantity: 1,
755
+ modifiers: [taxMod],
756
+ };
757
+ const item3 = {
758
+ _id: 3,
759
+ price: 2.15,
760
+ quantity: 3,
761
+ modifiers: [taxMod],
762
+ };
763
+
764
+ const order = {
765
+ items: [item1, item2, item3],
766
+ modifiers: [discountMod],
767
+ };
768
+
769
+ const newOrder = pricingService.order.calculate(order);
770
+
771
+ expect(newOrder).toHaveProperty('total', 100.2);
772
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
773
+ expect(newOrder).toHaveProperty('subTotals', {
774
+ discount: -16.41,
775
+ tax: 7.21,
776
+ });
777
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
778
+ expect(newOrder.items[1]).toHaveProperty('total', 13.7);
779
+ expect(newOrder.items[2]).toHaveProperty('total', 5.9);
780
+ expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
781
+ 'amount',
782
+ 13.2
783
+ );
784
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
785
+ 'amount',
786
+ 5.797
787
+ );
788
+
789
+ expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
790
+ 'amount',
791
+ 2.24
792
+ );
793
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
794
+ 'amount',
795
+ 0.985025
796
+ );
797
+
798
+ expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
799
+ 'amount',
800
+ 0.97
801
+ );
802
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
803
+ 'amount',
804
+ 0.4247
805
+ );
806
+ });
807
+
808
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (sort 1), 1 item tax (sort 99)', () => {
809
+ const taxMod = {
810
+ _id: 2,
811
+ name: `7.75% tax`,
812
+ type: 'tax',
813
+ compute: {
814
+ amount: 7.75,
815
+ type: 'percentage',
816
+ action: 'add',
817
+ },
818
+ properties: {
819
+ sort: 99,
820
+ },
821
+ };
822
+
823
+ const discountMod = {
824
+ _id: 1,
825
+ compute: {
826
+ amount: 15,
827
+ type: 'percentage',
828
+ action: 'subtract',
829
+ },
830
+ name: `15% Discount`,
831
+ type: 'discount',
832
+ properties: {
833
+ sort: 1,
834
+ },
835
+ };
836
+
837
+ const item1 = {
838
+ _id: 1,
839
+ price: 44,
840
+ quantity: 2,
841
+ modifiers: [taxMod, discountMod],
842
+ };
843
+ const item2 = {
844
+ _id: 2,
845
+ price: 14.95,
846
+ quantity: 1,
847
+ modifiers: [taxMod, discountMod],
848
+ };
849
+ const item3 = {
850
+ _id: 3,
851
+ price: 2.15,
852
+ quantity: 3,
853
+ modifiers: [taxMod, discountMod],
854
+ };
855
+
856
+ const order = {
857
+ items: [item1, item2, item3],
858
+ modifiers: [],
859
+ };
860
+
861
+ const newOrder = pricingService.order.calculate(order);
862
+
863
+ expect(newOrder).toHaveProperty('total', 100.2);
864
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
865
+ expect(newOrder).toHaveProperty('subTotals', {
866
+ discount: -16.41,
867
+ tax: 7.21,
868
+ });
869
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
870
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
871
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
872
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
873
+ 'amount',
874
+ -13.2
875
+ );
876
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
877
+ 'amount',
878
+ 5.797
879
+ );
880
+
881
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
882
+ 'amount',
883
+ -2.2425
884
+ );
885
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
886
+ 'amount',
887
+ 0.98483125
888
+ );
889
+
890
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
891
+ 'amount',
892
+ -0.9675
893
+ );
894
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
895
+ 'amount',
896
+ 0.42489375
897
+ );
898
+ });
899
+
900
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (sort 1), 1 order tax (sort 99)', () => {
901
+ const taxMod = {
902
+ _id: 2,
903
+ name: `7.75% tax`,
904
+ type: 'tax',
905
+ compute: {
906
+ amount: 7.75,
907
+ type: 'percentage',
908
+ action: 'add',
909
+ },
910
+ properties: {
911
+ sort: 99,
912
+ },
913
+ };
914
+
915
+ const discountMod = {
916
+ _id: 1,
917
+ compute: {
918
+ amount: 15,
919
+ type: 'percentage',
920
+ action: 'subtract',
921
+ },
922
+ name: `15% Discount`,
923
+ type: 'discount',
924
+ properties: {
925
+ sort: 1,
926
+ },
927
+ };
928
+
929
+ const item1 = {
930
+ _id: 1,
931
+ price: 44,
932
+ quantity: 2,
933
+ modifiers: [discountMod],
934
+ };
935
+ const item2 = {
936
+ _id: 2,
937
+ price: 14.95,
938
+ quantity: 1,
939
+ modifiers: [discountMod],
940
+ };
941
+ const item3 = {
942
+ _id: 3,
943
+ price: 2.15,
944
+ quantity: 3,
945
+ modifiers: [discountMod],
946
+ };
947
+
948
+ const order = {
949
+ items: [item1, item2, item3],
950
+ modifiers: [taxMod],
951
+ };
952
+
953
+ const newOrder = pricingService.order.calculate(order);
954
+
955
+ expect(newOrder).toHaveProperty('total', 100.2);
956
+ expect(newOrder).toHaveProperty('subTotal', 109.4);
957
+ expect(newOrder).toHaveProperty('subTotals', {
958
+ discount: -16.41,
959
+ tax: 7.21,
960
+ });
961
+ expect(newOrder.items[0]).toHaveProperty('total', 80.6);
962
+ expect(newOrder.items[1]).toHaveProperty('total', 13.7);
963
+ expect(newOrder.items[2]).toHaveProperty('total', 5.9);
964
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
965
+ 'amount',
966
+ -13.2
967
+ );
968
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
969
+ 'amount',
970
+ 5.8
971
+ );
972
+
973
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
974
+ 'amount',
975
+ -2.2425
976
+ );
977
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
978
+ 'amount',
979
+ 0.99
980
+ );
981
+
982
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
983
+ 'amount',
984
+ -0.9675
985
+ );
986
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
987
+ 'amount',
988
+ 0.42
989
+ );
990
+ });
991
+
992
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount (ignoreQty), 1 order tax', () => {
993
+ const taxMod = {
994
+ _id: 2,
995
+ name: `7.75% tax`,
996
+ type: 'tax',
997
+ compute: {
998
+ amount: 7.75,
999
+ type: 'percentage',
1000
+ action: 'add',
1001
+ },
1002
+ };
1003
+
1004
+ const discountMod = {
1005
+ _id: 1,
1006
+ compute: {
1007
+ amount: 1,
1008
+ type: 'fixed',
1009
+ action: 'subtract',
1010
+ },
1011
+ name: `1 USD`,
1012
+ type: 'fixed',
1013
+ properties: {
1014
+ ignoreQuantity: true,
1015
+ },
1016
+ };
1017
+
1018
+ const item1 = {
1019
+ _id: 1,
1020
+ price: 1,
1021
+ quantity: 1,
1022
+ modifiers: [discountMod],
1023
+ };
1024
+ const item2 = {
1025
+ _id: 2,
1026
+ price: 1,
1027
+ quantity: 1,
1028
+ modifiers: [discountMod],
1029
+ };
1030
+ const item3 = {
1031
+ _id: 3,
1032
+ price: 0.5,
1033
+ quantity: 2,
1034
+ modifiers: [discountMod],
1035
+ };
1036
+
1037
+ const order = {
1038
+ items: [item1, item2, item3],
1039
+ modifiers: [taxMod],
1040
+ };
1041
+
1042
+ const newOrder = pricingService.order.calculate(order);
1043
+
1044
+ expect(newOrder).toHaveProperty('total', 0);
1045
+ expect(newOrder).toHaveProperty('subTotal', 3);
1046
+ expect(newOrder).toHaveProperty('subTotals', {
1047
+ fixed: -3,
1048
+ tax: 0,
1049
+ });
1050
+ expect(newOrder.items[0]).toHaveProperty('total', 0);
1051
+ expect(newOrder.items[1]).toHaveProperty('total', 0);
1052
+ expect(newOrder.items[2]).toHaveProperty('total', 0);
1053
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1054
+ 'amount',
1055
+ -1
1056
+ );
1057
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1058
+ 'amount',
1059
+ 0
1060
+ );
1061
+
1062
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1063
+ 'amount',
1064
+ -1
1065
+ );
1066
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1067
+ 'amount',
1068
+ 0
1069
+ );
1070
+
1071
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1072
+ 'amount',
1073
+ -1
1074
+ );
1075
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1076
+ 'amount',
1077
+ 0
1078
+ );
1079
+ });
1080
+
1081
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 order discount (sort 1), 1 order tax (sort 2)', () => {
1082
+ const taxMod = {
1083
+ _id: 2,
1084
+ name: `7.75% tax`,
1085
+ type: 'tax',
1086
+ compute: {
1087
+ amount: 7.75,
1088
+ type: 'percentage',
1089
+ action: 'add',
1090
+ },
1091
+ properties: {
1092
+ sort: 2,
1093
+ },
1094
+ };
1095
+
1096
+ const discountMod = {
1097
+ _id: 1,
1098
+ compute: {
1099
+ amount: 1,
1100
+ type: 'fixed',
1101
+ action: 'subtract',
1102
+ },
1103
+ name: `1 USD`,
1104
+ type: 'fixed',
1105
+ properties: {
1106
+ sort: 1,
1107
+ },
1108
+ };
1109
+
1110
+ const item1 = {
1111
+ _id: 1,
1112
+ price: 1,
1113
+ quantity: 1,
1114
+ modifiers: [],
1115
+ };
1116
+ const item2 = {
1117
+ _id: 2,
1118
+ price: 1,
1119
+ quantity: 1,
1120
+ modifiers: [],
1121
+ };
1122
+ const item3 = {
1123
+ _id: 3,
1124
+ price: 0.5,
1125
+ quantity: 2,
1126
+ modifiers: [],
1127
+ };
1128
+
1129
+ const order = {
1130
+ items: [item1, item2, item3],
1131
+ modifiers: [taxMod, discountMod],
1132
+ };
1133
+
1134
+ const newOrder = pricingService.order.calculate(order);
1135
+
1136
+ expect(newOrder).toHaveProperty('total', 2.15);
1137
+ expect(newOrder).toHaveProperty('subTotal', 3);
1138
+ expect(newOrder).toHaveProperty('subTotals', {
1139
+ fixed: -1,
1140
+ tax: 0.15,
1141
+ });
1142
+ expect(newOrder.items[0]).toHaveProperty('total', 0.72);
1143
+ expect(newOrder.items[1]).toHaveProperty('total', 0.72);
1144
+ expect(newOrder.items[2]).toHaveProperty('total', 0.71);
1145
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1146
+ 'amount',
1147
+ -0.33
1148
+ );
1149
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1150
+ 'amount',
1151
+ 0.05
1152
+ );
1153
+
1154
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1155
+ 'amount',
1156
+ -0.33
1157
+ );
1158
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1159
+ 'amount',
1160
+ 0.05
1161
+ );
1162
+
1163
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1164
+ 'amount',
1165
+ -0.17
1166
+ );
1167
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1168
+ 'amount',
1169
+ 0.05
1170
+ );
1171
+ });
1172
+
1173
+ test('CU-861n7pum9 - Get calculated Order, multiple items, 2 modifiers: 1 item discount, 1 order tax', () => {
1174
+ const taxMod = {
1175
+ _id: 2,
1176
+ name: `7.75% tax`,
1177
+ type: 'tax',
1178
+ compute: {
1179
+ amount: 7.75,
1180
+ type: 'percentage',
1181
+ action: 'add',
1182
+ },
1183
+ };
1184
+
1185
+ const discountMod = {
1186
+ _id: 1,
1187
+ compute: {
1188
+ amount: 1,
1189
+ type: 'fixed',
1190
+ action: 'subtract',
1191
+ },
1192
+ name: `1 USD`,
1193
+ type: 'fixed',
1194
+ };
1195
+
1196
+ const item1 = {
1197
+ _id: 1,
1198
+ price: 1,
1199
+ quantity: 1,
1200
+ modifiers: [discountMod],
1201
+ };
1202
+ const item2 = {
1203
+ _id: 2,
1204
+ price: 1,
1205
+ quantity: 1,
1206
+ modifiers: [discountMod],
1207
+ };
1208
+ const item3 = {
1209
+ _id: 3,
1210
+ price: 0.5,
1211
+ quantity: 2,
1212
+ modifiers: [discountMod],
1213
+ };
1214
+
1215
+ const order = {
1216
+ items: [item1, item2, item3],
1217
+ modifiers: [taxMod],
1218
+ };
1219
+
1220
+ const newOrder = pricingService.order.calculate(order);
1221
+
1222
+ expect(newOrder).toHaveProperty('total', 0);
1223
+ expect(newOrder).toHaveProperty('subTotal', 3);
1224
+ expect(newOrder).toHaveProperty('subTotals', {
1225
+ fixed: -3,
1226
+ tax: 0,
1227
+ });
1228
+ expect(newOrder.items[0]).toHaveProperty('total', 0);
1229
+ expect(newOrder.items[1]).toHaveProperty('total', 0);
1230
+ expect(newOrder.items[2]).toHaveProperty('total', 0);
1231
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1232
+ 'amount',
1233
+ -1
1234
+ );
1235
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1236
+ 'amount',
1237
+ 0
1238
+ );
1239
+
1240
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1241
+ 'amount',
1242
+ -1
1243
+ );
1244
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1245
+ 'amount',
1246
+ 0
1247
+ );
1248
+
1249
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1250
+ 'amount',
1251
+ -1
1252
+ );
1253
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1254
+ 'amount',
1255
+ 0
1256
+ );
1257
+ });
1258
+
249
1259
  test('CU-3und87h : Calculate order with 20 USD credit', () => {
250
1260
  const newOrder = pricingService.order.calculate(orderCredit);
251
1261
 
252
1262
  const [item1, item2, item3] = newOrder.items;
253
1263
  expect(newOrder).toHaveProperty('total', 12.5);
254
- expect(item1).toHaveProperty('total', 3.64);
255
- expect(item1.modifiers[1].compute).toHaveProperty('amount', 5.86);
1264
+ expect(item1).toHaveProperty('total', 3.66);
1265
+ expect(item1.modifiers[1].compute).toHaveProperty('amount', 5.84);
256
1266
 
257
- expect(item2).toHaveProperty('total', 5.39);
258
- expect(item2.modifiers[1].compute).toHaveProperty('amount', 8.61);
1267
+ expect(item2).toHaveProperty('total', 5.38);
1268
+ expect(item2.modifiers[1].compute).toHaveProperty('amount', 8.62);
259
1269
 
260
- expect(item3).toHaveProperty('total', 3.47);
261
- expect(item3.modifiers[1].compute).toHaveProperty('amount', 5.53);
1270
+ expect(item3).toHaveProperty('total', 3.46);
1271
+ expect(item3.modifiers[1].compute).toHaveProperty('amount', 5.54);
262
1272
  });
263
1273
 
264
1274
  test('Auto split a Parent Order', () => {
@@ -611,6 +1621,7 @@ describe('Order actions', () => {
611
1621
  modifiers: paymentModifiers,
612
1622
  order,
613
1623
  });
1624
+
614
1625
  const newOrder = pricingService.order.calculate(order);
615
1626
 
616
1627
  expect(newOrder).toHaveProperty('total', 36.45);
@@ -619,9 +1630,9 @@ describe('Order actions', () => {
619
1630
  discount: -10,
620
1631
  fee: 4,
621
1632
  });
622
- expect(newOrder.items[0]).toHaveProperty('total', 8.07);
623
- expect(newOrder.items[1]).toHaveProperty('total', 7.71);
624
- expect(newOrder.items[2]).toHaveProperty('total', 11.37);
1633
+ expect(newOrder.items[0]).toHaveProperty('total', 8.09);
1634
+ expect(newOrder.items[1]).toHaveProperty('total', 7.7);
1635
+ expect(newOrder.items[2]).toHaveProperty('total', 11.36);
625
1636
  expect(newOrder.items[3]).toHaveProperty('total', 9.3);
626
1637
  });
627
1638
  });