@darkpos/pricing 1.0.52 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,7 +71,7 @@ describe('addIndirectModifier Function', () => {
71
71
  expect(result).toEqual({
72
72
  item1: {
73
73
  compute: { amount: 50 }, // Adjusted amount to fix the total distribution difference
74
- properties: { ignoreQuantity: true },
74
+ properties: { isQuantityMultiplier: false },
75
75
  },
76
76
  item2: { compute: { amount: 50 }, properties: {} },
77
77
  });
@@ -127,7 +127,7 @@ describe('addIndirectModifier Function', () => {
127
127
  item1: {
128
128
  compute: { amount: -35 },
129
129
  properties: {
130
- ignoreQuantity: true,
130
+ isQuantityMultiplier: false,
131
131
  },
132
132
  _computed: { amount: 15 },
133
133
  },
@@ -160,7 +160,7 @@ describe('addIndirectModifier Function', () => {
160
160
  item1: {
161
161
  compute: { amount: -30 },
162
162
  properties: {
163
- ignoreQuantity: true,
163
+ isQuantityMultiplier: false,
164
164
  },
165
165
  },
166
166
  item2: { compute: { amount: 50 }, properties: {} },
@@ -15,6 +15,9 @@ describe('Item actions', () => {
15
15
  type: 'discount',
16
16
  direct: false,
17
17
  included: false,
18
+ properties: {
19
+ isQuantityMultiplier: true,
20
+ },
18
21
  },
19
22
  {
20
23
  compute: {
@@ -26,6 +29,9 @@ describe('Item actions', () => {
26
29
  type: 'discount',
27
30
  direct: false,
28
31
  included: false,
32
+ properties: {
33
+ isQuantityMultiplier: true,
34
+ },
29
35
  },
30
36
  {
31
37
  compute: {
@@ -37,6 +43,9 @@ describe('Item actions', () => {
37
43
  type: 'discount',
38
44
  direct: false,
39
45
  included: false,
46
+ properties: {
47
+ isQuantityMultiplier: true,
48
+ },
40
49
  },
41
50
  ];
42
51
  const orderItem = { price: 30, quantity: 2, modifiers };
@@ -60,6 +69,9 @@ describe('Item actions', () => {
60
69
  name: 'modifier1',
61
70
  direct: true,
62
71
  included: false,
72
+ properties: {
73
+ isQuantityMultiplier: true,
74
+ },
63
75
  },
64
76
  {
65
77
  compute: {
@@ -71,6 +83,9 @@ describe('Item actions', () => {
71
83
  type: 'discount',
72
84
  direct: true,
73
85
  included: false,
86
+ properties: {
87
+ isQuantityMultiplier: true,
88
+ },
74
89
  },
75
90
  {
76
91
  compute: {
@@ -82,6 +97,9 @@ describe('Item actions', () => {
82
97
  type: 'tax',
83
98
  direct: true,
84
99
  included: false,
100
+ properties: {
101
+ isQuantityMultiplier: true,
102
+ },
85
103
  },
86
104
  ];
87
105
  const orderItem = { price: 30, quantity: 2, modifiers };
@@ -110,6 +128,9 @@ describe('Item actions', () => {
110
128
  type: 'discount',
111
129
  direct: true,
112
130
  included: true,
131
+ properties: {
132
+ isQuantityMultiplier: true,
133
+ },
113
134
  },
114
135
  {
115
136
  compute: {
@@ -121,6 +142,9 @@ describe('Item actions', () => {
121
142
  type: 'discount',
122
143
  direct: true,
123
144
  included: true,
145
+ properties: {
146
+ isQuantityMultiplier: true,
147
+ },
124
148
  },
125
149
  {
126
150
  compute: {
@@ -132,6 +156,9 @@ describe('Item actions', () => {
132
156
  type: 'upcharge',
133
157
  direct: true,
134
158
  included: true,
159
+ properties: {
160
+ isQuantityMultiplier: true,
161
+ },
135
162
  },
136
163
  ];
137
164
  const orderItem = { price: 30, quantity: 2, modifiers };
@@ -631,7 +658,7 @@ describe('Item actions', () => {
631
658
  expect(newItem).toHaveProperty('total', 70.5);
632
659
  expect(newItem).toHaveProperty('price', 13.5);
633
660
  expect(newItem.modifiers[0]).toHaveProperty('_computed', {
634
- amount: 10,
661
+ amount: 30,
635
662
  description: 'Override modamount fixed 10 ($30.00)',
636
663
  });
637
664
 
@@ -1672,7 +1672,7 @@ const addItemMock = {
1672
1672
  items: [],
1673
1673
  },
1674
1674
  sort: null,
1675
- ignoreQuantity: true,
1675
+ isQuantityMultiplier: false,
1676
1676
  },
1677
1677
  _computed: null,
1678
1678
  addModifiers: [],
@@ -1795,7 +1795,7 @@ const addItemMock = {
1795
1795
  },
1796
1796
  department: {},
1797
1797
  sort: null,
1798
- ignoreQuantity: false,
1798
+ isQuantityMultiplier: true,
1799
1799
  },
1800
1800
  _computed: null,
1801
1801
  addModifiers: [],
@@ -262,7 +262,7 @@
262
262
  },
263
263
  "properties": {
264
264
  "sort": 999,
265
- "ignoreQuantity": true
265
+ "isQuantityMultiplier": false
266
266
  },
267
267
  "_id": "63ade222dd19604ca368eb29",
268
268
  "modifierId": "63ade212dd19604ca368eb23",
@@ -96,7 +96,7 @@
96
96
  "default": false,
97
97
  "code": "",
98
98
  "properties": {
99
- "ignoreQuantity": true
99
+ "isQuantityMultiplier": false
100
100
  },
101
101
  "_computed": {
102
102
  "amount": -2.36,
@@ -149,7 +149,7 @@
149
149
  "default": false,
150
150
  "code": "",
151
151
  "properties": {
152
- "ignoreQuantity": true
152
+ "isQuantityMultiplier": false
153
153
  },
154
154
  "_computed": {
155
155
  "amount": 0.48,
@@ -98,7 +98,7 @@
98
98
  "default": false,
99
99
  "code": "",
100
100
  "properties": {
101
- "ignoreQuantity": true
101
+ "isQuantityMultiplier": false
102
102
  },
103
103
  "_computed": {
104
104
  "amount": -2.36,
@@ -1,38 +1,14 @@
1
- const _ = require('lodash');
2
- const utils = require('@darkpos/utils');
3
- const createIndirectModifierFunction = require('../../lib/modifier/createIndirectModifier');
1
+ const usePricing = require('../../index');
2
+
3
+ const pricingService = usePricing();
4
4
 
5
5
  describe('createIndirectModifier Function', () => {
6
6
  test('create indirect modifier with an undefined modifier compute', () => {
7
- const constants = {
8
- Modifier: {
9
- Compute: {
10
- Types: {
11
- PERCENTAGE: 'percentage',
12
- FIXED: 'fixed',
13
- },
14
- Actions: {
15
- SUBTRACT: 'subtract',
16
- },
17
- },
18
- },
19
- };
20
- const actions = {
21
- getProperty: (modifier, prop) => modifier[prop],
22
- create: modifier => modifier,
23
- };
24
- // const getComputeModField = jest.fn().mockReturnValue(null);
25
-
26
- const createIndirectModifier = createIndirectModifierFunction({
27
- _,
28
- utils,
29
- constants,
30
- actions,
31
- });
32
-
33
7
  const modifier = {
34
8
  type: 'credit',
35
- properties: {},
9
+ properties: {
10
+ isQuantityMultiplier: true,
11
+ },
36
12
  };
37
13
  const options = {
38
14
  orderTotal: 100,
@@ -40,9 +16,12 @@ describe('createIndirectModifier Function', () => {
40
16
  itemTotal: 50,
41
17
  };
42
18
 
43
- const result = createIndirectModifier(modifier, options);
19
+ const result = pricingService.modifier.createIndirectModifier(
20
+ modifier,
21
+ options
22
+ );
44
23
 
45
- expect(result).toEqual({
24
+ expect(result).toMatchObject({
46
25
  ...modifier,
47
26
  direct: false,
48
27
  compute: {
@@ -51,39 +30,14 @@ describe('createIndirectModifier Function', () => {
51
30
  action: 'subtract',
52
31
  },
53
32
  properties: {
54
- ignoreQuantity: false,
33
+ isQuantityMultiplier: true,
55
34
  },
56
35
  });
57
36
  });
58
37
  test('create indirect modifier with a null modifier compute', () => {
59
- const constants = {
60
- Modifier: {
61
- Compute: {
62
- Types: {
63
- PERCENTAGE: 'percentage',
64
- FIXED: 'fixed',
65
- },
66
- Actions: {
67
- SUBTRACT: 'subtract',
68
- },
69
- },
70
- },
71
- };
72
- const actions = {
73
- getProperty: (modifier, prop) => modifier[prop],
74
- create: modifier => modifier,
75
- };
76
-
77
- const createIndirectModifier = createIndirectModifierFunction({
78
- _,
79
- utils,
80
- constants,
81
- actions,
82
- });
83
-
84
38
  const modifier = {
85
39
  type: 'credit',
86
- properties: {},
40
+ properties: { isQuantityMultiplier: true },
87
41
  compute: null,
88
42
  };
89
43
  const options = {
@@ -92,9 +46,12 @@ describe('createIndirectModifier Function', () => {
92
46
  itemTotal: 50,
93
47
  };
94
48
 
95
- const result = createIndirectModifier(modifier, options);
49
+ const result = pricingService.modifier.createIndirectModifier(
50
+ modifier,
51
+ options
52
+ );
96
53
 
97
- expect(result).toEqual({
54
+ expect(result).toMatchObject({
98
55
  ...modifier,
99
56
  direct: false,
100
57
  compute: {
@@ -103,39 +60,14 @@ describe('createIndirectModifier Function', () => {
103
60
  action: 'subtract',
104
61
  },
105
62
  properties: {
106
- ignoreQuantity: false,
63
+ isQuantityMultiplier: true,
107
64
  },
108
65
  });
109
66
  });
110
67
  test('create indirect modifier regular modifier', () => {
111
- const constants = {
112
- Modifier: {
113
- Compute: {
114
- Types: {
115
- PERCENTAGE: 'percentage',
116
- FIXED: 'fixed',
117
- },
118
- Actions: {
119
- SUBTRACT: 'subtract',
120
- },
121
- },
122
- },
123
- };
124
- const actions = {
125
- getProperty: (modifier, prop) => modifier[prop],
126
- create: modifier => modifier,
127
- };
128
-
129
- const createIndirectModifier = createIndirectModifierFunction({
130
- _,
131
- utils,
132
- constants,
133
- actions,
134
- });
135
-
136
68
  const modifier = {
137
69
  type: 'credit',
138
- properties: {},
70
+ properties: { isQuantityMultiplier: true },
139
71
  compute: {
140
72
  type: 'fixed',
141
73
  action: 'add',
@@ -148,9 +80,12 @@ describe('createIndirectModifier Function', () => {
148
80
  itemTotal: 50,
149
81
  };
150
82
 
151
- const result = createIndirectModifier(modifier, options);
83
+ const result = pricingService.modifier.createIndirectModifier(
84
+ modifier,
85
+ options
86
+ );
152
87
 
153
- expect(result).toEqual({
88
+ expect(result).toMatchObject({
154
89
  ...modifier,
155
90
  direct: false,
156
91
  compute: {
@@ -159,7 +94,7 @@ describe('createIndirectModifier Function', () => {
159
94
  amount: 2.5,
160
95
  },
161
96
  properties: {
162
- ignoreQuantity: false,
97
+ isQuantityMultiplier: true,
163
98
  },
164
99
  });
165
100
  });
@@ -1485,7 +1485,7 @@ describe('hasModifier Function', () => {
1485
1485
  action: 'subtract',
1486
1486
  },
1487
1487
  properties: {
1488
- ignoreQuantity: false,
1488
+ isQuantityMultiplier: true,
1489
1489
  },
1490
1490
  _id: '67226d7fe779680a203df892',
1491
1491
  modifierId: '62cdbfd01ee1b4001932822e',
@@ -1531,7 +1531,7 @@ describe('hasModifier Function', () => {
1531
1531
  action: 'subtract',
1532
1532
  },
1533
1533
  properties: {
1534
- ignoreQuantity: false,
1534
+ isQuantityMultiplier: true,
1535
1535
  subscription: {},
1536
1536
  override: {},
1537
1537
  group: {
@@ -806,7 +806,7 @@ describe('Order actions', () => {
806
806
  default: false,
807
807
  code: 'L',
808
808
  properties: {
809
- ignoreQuantity: false,
809
+ isQuantityMultiplier: true,
810
810
  },
811
811
  _computed: {
812
812
  amount: 0,
@@ -848,7 +848,7 @@ describe('Order actions', () => {
848
848
  default: false,
849
849
  code: '',
850
850
  properties: {
851
- ignoreQuantity: false,
851
+ isQuantityMultiplier: true,
852
852
  group: {
853
853
  modifiers: [],
854
854
  items: [],