@darkpos/pricing 1.0.65 → 1.0.67

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.
@@ -146,4 +146,222 @@ describe('getModifierTags Function', () => {
146
146
  },
147
147
  ]);
148
148
  });
149
+
150
+ test('get group modifiers including Payment modifiers', () => {
151
+ const item = {
152
+ modifiers: [
153
+ {
154
+ _id: '67d9b80aefebb298f78a9045',
155
+ attributes: ['group'],
156
+ modifierId: '62cdbfd01ee1b4001932816a',
157
+ _parentId: null,
158
+ locked: null,
159
+ name: 'White',
160
+ sku: '',
161
+ description: 'Color: White',
162
+ group: 'Color',
163
+ type: null,
164
+ tags: ['default', 'all'],
165
+ order: null,
166
+ included: false,
167
+ direct: true,
168
+ hidden: false,
169
+ print: false,
170
+ required: true,
171
+ recommended: false,
172
+ default: false,
173
+ code: null,
174
+ properties: {
175
+ override: null,
176
+ group: {
177
+ displayType: 'card',
178
+ includeInGroup: true,
179
+ singleValue: true,
180
+ compact: true,
181
+ enableAutoPopup: false,
182
+ displayReplacePrompt: true,
183
+ promptMessage: '',
184
+ modifiers: [],
185
+ items: [],
186
+ values: ['RegularItem'],
187
+ manualModifiers: 'test1, asd,123',
188
+ },
189
+ sort: null,
190
+ label: {
191
+ text: 'White Label',
192
+ align: 'center',
193
+ backgroundColor: 'rgba(76,175,80,1)',
194
+ },
195
+ color: 'rgba(0,150,136,1)',
196
+ },
197
+ _computed: {
198
+ amount: 0,
199
+ description: 'White',
200
+ },
201
+ conditions: {
202
+ valid: true,
203
+ rules: [],
204
+ },
205
+ compute: null,
206
+ _createdAt: '2025-03-18T18:15:35.300Z',
207
+ _updatedAt: '2025-03-18T18:15:35.300Z',
208
+ __typename: 'Modifier',
209
+ addModifiers: [],
210
+ delModifiers: [],
211
+ },
212
+ {
213
+ _id: '67d9b810efebb298f78a9046',
214
+ attributes: [],
215
+ modifierId: '670d7f7e746d1ae0f847aba6',
216
+ _parentId: null,
217
+ locked: false,
218
+ name: 'CASH 20% DISCOUNT',
219
+ sku: '',
220
+ description: '',
221
+ group: 'Offers',
222
+ type: 'discount',
223
+ tags: ['default', 'all'],
224
+ order: null,
225
+ included: false,
226
+ direct: true,
227
+ hidden: false,
228
+ print: true,
229
+ required: false,
230
+ recommended: false,
231
+ default: false,
232
+ code: '',
233
+ properties: {
234
+ override: null,
235
+ sort: null,
236
+ },
237
+ _computed: {
238
+ amount: 0,
239
+ description: 'CASH 20% DISCOUNT',
240
+ },
241
+ conditions: {
242
+ valid: false,
243
+ rules: [
244
+ {
245
+ key: 'paymentMethods',
246
+ value: ['cash-cash'],
247
+ operand: '$in',
248
+ },
249
+ {
250
+ key: 'paymentTypes',
251
+ value: ['cash'],
252
+ operand: '$in',
253
+ },
254
+ ],
255
+ },
256
+ compute: {
257
+ type: 'percentage',
258
+ action: 'subtract',
259
+ amount: 20,
260
+ },
261
+ _createdAt: '2025-03-18T18:15:35.300Z',
262
+ _updatedAt: '2025-03-18T18:15:35.300Z',
263
+ __typename: 'Modifier',
264
+ addModifiers: [],
265
+ delModifiers: [],
266
+ },
267
+ {
268
+ name: 'CRC 5.10 discount',
269
+ sku: '',
270
+ description: '',
271
+ group: '',
272
+ type: 'discount',
273
+ attributes: [],
274
+ color: '',
275
+ backgroundColor: '',
276
+ icon: '',
277
+ url: '',
278
+ code: '',
279
+ tags: [],
280
+ order: 0,
281
+ included: false,
282
+ direct: true,
283
+ hidden: false,
284
+ required: false,
285
+ print: true,
286
+ delModifiers: [],
287
+ addModifiers: [],
288
+ conditions: null,
289
+ compute: {
290
+ action: 'subtract',
291
+ amount: 5.1,
292
+ type: 'fixed',
293
+ },
294
+ properties: {
295
+ override: null,
296
+ sort: null,
297
+ isCalculatedPaymentModifier: true,
298
+ },
299
+ _id: '67d9b8dee71fee48f592ce3a',
300
+ modifierId: '670d7f7e746d1ae0f847aba6',
301
+ __typename: 'Modifier',
302
+ _parentId: '67d9b810efebb298f78a9046',
303
+ _computed: {
304
+ amount: -5.1,
305
+ description: 'CRC 5.10 discount (-CRC 5.10)',
306
+ },
307
+ locked: false,
308
+ },
309
+ {
310
+ _id: '67d9b8470d733f348225eeac',
311
+ attributes: [],
312
+ modifierId: '670d7f7e746d1ae0f847aba6',
313
+ _parentId: '67d9b810efebb298f78a9046',
314
+ locked: true,
315
+ name: 'CRC 37.50 discount',
316
+ sku: '',
317
+ description: '',
318
+ group: '',
319
+ type: 'discount',
320
+ tags: [],
321
+ order: 0,
322
+ included: false,
323
+ direct: true,
324
+ hidden: false,
325
+ print: true,
326
+ required: false,
327
+ recommended: false,
328
+ default: false,
329
+ code: '',
330
+ properties: {
331
+ override: null,
332
+ sort: null,
333
+ isCalculatedPaymentModifier: true,
334
+ paymentId: '67d9b846837593e11861065d',
335
+ },
336
+ _computed: {
337
+ amount: -37.5,
338
+ description: 'CRC 37.50 discount (-CRC 37.50)',
339
+ },
340
+ conditions: {
341
+ valid: true,
342
+ },
343
+ compute: {
344
+ type: 'fixed',
345
+ action: 'subtract',
346
+ amount: 37.5,
347
+ },
348
+ _createdAt: '2025-03-18T18:15:35.300Z',
349
+ _updatedAt: '2025-03-18T18:15:35.300Z',
350
+ __typename: 'Modifier',
351
+ addModifiers: [],
352
+ delModifiers: [],
353
+ },
354
+ ],
355
+ };
356
+
357
+ const result = pricingServiceGroupModifiers.item.getModifierTags({ item });
358
+
359
+ expect(result).toHaveLength(2);
360
+ expect(result[0].label.replace(/\s/g, '')).toEqual(
361
+ '1CRC5.10discount(-CRC5.10)'
362
+ );
363
+ expect(result[1].label.replace(/\s/g, '')).toEqual(
364
+ '1CRC37.50discount(-CRC37.50)'
365
+ );
366
+ });
149
367
  });
@@ -1,10 +1,10 @@
1
- const getGroupedModifiersFunction = require('../../lib/modifier/getGroupedModifiers');
1
+ const usePricing = require('../../index');
2
2
 
3
- describe('getGroupedModifiers Function', () => {
4
- const getGroupedModifiers = getGroupedModifiersFunction();
3
+ const pricingService = usePricing();
5
4
 
5
+ describe('pricingService.modifier.getGroupedModifiers Function', () => {
6
6
  test('should return an empty array if no tags are provided', () => {
7
- const result = getGroupedModifiers([]);
7
+ const result = pricingService.modifier.getGroupedModifiers([]);
8
8
  expect(result).toEqual([]);
9
9
  });
10
10
 
@@ -15,7 +15,7 @@ describe('getGroupedModifiers Function', () => {
15
15
  { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
16
16
  ];
17
17
 
18
- const result = getGroupedModifiers(tags);
18
+ const result = pricingService.modifier.getGroupedModifiers(tags);
19
19
 
20
20
  expect(result).toEqual([
21
21
  { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
@@ -29,7 +29,7 @@ describe('getGroupedModifiers Function', () => {
29
29
  { label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
30
30
  ];
31
31
 
32
- const result = getGroupedModifiers(tags);
32
+ const result = pricingService.modifier.getGroupedModifiers(tags);
33
33
 
34
34
  expect(result).toEqual([
35
35
  { label: '1 Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
@@ -45,7 +45,7 @@ describe('getGroupedModifiers Function', () => {
45
45
 
46
46
  const originalTagsCopy = [...tags];
47
47
 
48
- getGroupedModifiers(tags);
48
+ pricingService.modifier.getGroupedModifiers(tags);
49
49
 
50
50
  expect(tags).toEqual(originalTagsCopy); // Ensure original array is not mutated
51
51
  });
@@ -56,7 +56,7 @@ describe('getGroupedModifiers Function', () => {
56
56
  { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
57
57
  ];
58
58
 
59
- const result = getGroupedModifiers(tags);
59
+ const result = pricingService.modifier.getGroupedModifiers(tags);
60
60
 
61
61
  expect(result).toEqual([
62
62
  { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },