@managesome/eposmatic-toolkit 0.2.769 → 0.2.770
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.
- package/lib/helpers/utils/receipt-engine.js +14 -2
- package/lib/tests/classic-specials-quantity.test.js +7 -4
- package/lib/tests/no-choice-modifier-selection.test.d.ts +1 -0
- package/lib/tests/no-choice-modifier-selection.test.js +142 -0
- package/lib/tests/receipt-engine.test.js +76 -0
- package/package.json +1 -1
|
@@ -360,7 +360,13 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
|
|
|
360
360
|
for (let j = 0; j < modifierOptions.length; j++) {
|
|
361
361
|
const option = modifierOptions[j];
|
|
362
362
|
const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
|
|
363
|
-
|
|
363
|
+
// The option name can collapse into the modifier name (identical
|
|
364
|
+
// modifier/option names, e.g. a deal pizza). In that case the
|
|
365
|
+
// modifier name carries the whole line, so it must be kept even
|
|
366
|
+
// when hide_modifier_name is on - otherwise the line prints blank.
|
|
367
|
+
// Checked on the stripped name: emojis are removed from printed text anyway.
|
|
368
|
+
const isMergedWithModifierName = (0, emoji_strip_1.default)(option.name).trim().length === 0;
|
|
369
|
+
const optionDescription = hide_modifier_name && !isMergedWithModifierName
|
|
364
370
|
? `${space}${optionQuantity}`
|
|
365
371
|
: `${space}${optionQuantity}${modifierName} `;
|
|
366
372
|
options.push({
|
|
@@ -381,7 +387,13 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
|
|
|
381
387
|
const option = modifier.options[j];
|
|
382
388
|
const optionName = (0, common_1.sentenceCase)(getItemModifierOptionTitle(modifierName, option.name));
|
|
383
389
|
const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
|
|
384
|
-
|
|
390
|
+
// The option name can collapse into the modifier name (identical
|
|
391
|
+
// modifier/option names, e.g. a deal pizza). In that case the
|
|
392
|
+
// modifier name carries the whole line, so it must be kept even
|
|
393
|
+
// when hide_modifier_name is on - otherwise the line prints blank.
|
|
394
|
+
// Checked on the stripped name: emojis are removed from printed text anyway.
|
|
395
|
+
const isMergedWithModifierName = (0, emoji_strip_1.default)(optionName).trim().length === 0;
|
|
396
|
+
const optionDescription = hide_modifier_name && !isMergedWithModifierName
|
|
385
397
|
? `${space}${optionQuantity}`
|
|
386
398
|
: `${space}${optionQuantity}${modifierName} `;
|
|
387
399
|
options.push({
|
|
@@ -8,10 +8,13 @@ const specials_helpers_1 = require("../helpers/utils/specials-helpers");
|
|
|
8
8
|
//
|
|
9
9
|
// The modern flow lets a cashier pick the same item several times in a group
|
|
10
10
|
// (merged into one option with a summed quantity). The classic drawer must
|
|
11
|
-
// support the same selection semantics
|
|
12
|
-
//
|
|
13
|
-
// -
|
|
14
|
-
// -
|
|
11
|
+
// support the same selection semantics, with the group's field shape DERIVED
|
|
12
|
+
// per group by `convertSpecialToItem`:
|
|
13
|
+
// - quantity 1 → radio rows (one pick; ticking another replaces it),
|
|
14
|
+
// - quantity > 1 → stepper rows with the exact total enforced by the
|
|
15
|
+
// AGGREGATES (any mix, repeats allowed),
|
|
16
|
+
// - a single-item group is selected in ONE click at the full quantity (and
|
|
17
|
+
// auto-selected when the drawer opens, mirroring the modern auto-fill),
|
|
15
18
|
// - stored lines with repeated options (merged quantity, free/paid split)
|
|
16
19
|
// EDIT losslessly — occurrences aggregate into the one engine option.
|
|
17
20
|
// ============================================================================
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const order_engine_1 = require("../helpers/utils/order-engine");
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// No-choice modifier trees: "the user has nothing to pick".
|
|
7
|
+
//
|
|
8
|
+
// Used by POS to skip the options drawer entirely — when every usable level is
|
|
9
|
+
// a single REQUIRED modifier with a single usable option, adding the item
|
|
10
|
+
// direct-to-cart with the chain applied produces EXACTLY what the drawer would
|
|
11
|
+
// have produced by hand.
|
|
12
|
+
// ============================================================================
|
|
13
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
14
|
+
function makeOption(id, overrides = {}) {
|
|
15
|
+
return {
|
|
16
|
+
_id: id,
|
|
17
|
+
ref: id,
|
|
18
|
+
name: id,
|
|
19
|
+
active: true,
|
|
20
|
+
sold_out: [],
|
|
21
|
+
sort_id: 1,
|
|
22
|
+
excluded_platforms: [],
|
|
23
|
+
price: null,
|
|
24
|
+
modifiers: null,
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function makeModifier(id, overrides = {}) {
|
|
29
|
+
return {
|
|
30
|
+
_id: id,
|
|
31
|
+
ref: id,
|
|
32
|
+
name: id,
|
|
33
|
+
description: '',
|
|
34
|
+
active: true,
|
|
35
|
+
sold_out: [],
|
|
36
|
+
sort_id: 1,
|
|
37
|
+
options: [],
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
describe('getNoChoiceModifierSelection', () => {
|
|
42
|
+
it('reports an item without modifiers as plain', () => {
|
|
43
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(null, PLATFORM)).toEqual({ kind: 'plain' });
|
|
44
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)([], PLATFORM)).toEqual({ kind: 'plain' });
|
|
45
|
+
});
|
|
46
|
+
it('reports an item whose modifiers are all unusable as plain', () => {
|
|
47
|
+
const modifiers = [makeModifier('mod-off', { active: false, options: [makeOption('a')] })];
|
|
48
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)).toEqual({ kind: 'plain' });
|
|
49
|
+
});
|
|
50
|
+
it('finds a single required modifier with a single option', () => {
|
|
51
|
+
const modifiers = [
|
|
52
|
+
makeModifier('mod-1', { min_num_options: 1, max_num_options: 1, options: [makeOption('opt-a')] }),
|
|
53
|
+
];
|
|
54
|
+
const selection = (0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM);
|
|
55
|
+
expect(selection?.kind).toBe('no-choice');
|
|
56
|
+
if (selection?.kind !== 'no-choice')
|
|
57
|
+
throw new Error('expected no-choice selection');
|
|
58
|
+
expect(selection.selectionPath).toBe('mod-1_opt-a');
|
|
59
|
+
expect(selection.selectedOptions.map((option) => option._id)).toEqual(['opt-a']);
|
|
60
|
+
});
|
|
61
|
+
it('treats a required quantity group (aggregates) with one option as no-choice', () => {
|
|
62
|
+
const modifiers = [
|
|
63
|
+
makeModifier('mod-1', {
|
|
64
|
+
min_aggregate_options_quantity: 2,
|
|
65
|
+
max_aggregate_options_quantity: 2,
|
|
66
|
+
min_option_choice_quantity: 2,
|
|
67
|
+
max_option_choice_quantity: 2,
|
|
68
|
+
options: [makeOption('opt-a')],
|
|
69
|
+
}),
|
|
70
|
+
];
|
|
71
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)?.kind).toBe('no-choice');
|
|
72
|
+
});
|
|
73
|
+
it('walks a fully forced nested chain and builds the full path', () => {
|
|
74
|
+
const nestedModifier = makeModifier('mod-2', {
|
|
75
|
+
min_num_options: 1,
|
|
76
|
+
max_num_options: 1,
|
|
77
|
+
options: [makeOption('opt-b')],
|
|
78
|
+
});
|
|
79
|
+
const option = makeOption('opt-a', { modifiers: [nestedModifier] });
|
|
80
|
+
const modifiers = [
|
|
81
|
+
makeModifier('mod-1', { min_num_options: 1, max_num_options: 1, options: [option] }),
|
|
82
|
+
];
|
|
83
|
+
const selection = (0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM);
|
|
84
|
+
expect(selection?.kind).toBe('no-choice');
|
|
85
|
+
if (selection?.kind !== 'no-choice')
|
|
86
|
+
throw new Error('expected no-choice selection');
|
|
87
|
+
expect(selection.selectionPath).toBe('mod-1_opt-a_mod-2_opt-b');
|
|
88
|
+
expect(selection.selectedOptions.map((selected) => selected._id)).toEqual(['opt-a', 'opt-b']);
|
|
89
|
+
});
|
|
90
|
+
it('returns null when a level is optional (the user can skip it)', () => {
|
|
91
|
+
const modifiers = [makeModifier('mod-1', { options: [makeOption('opt-a')] })];
|
|
92
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
it('returns null when a level offers more than one usable option', () => {
|
|
95
|
+
const modifiers = [
|
|
96
|
+
makeModifier('mod-1', {
|
|
97
|
+
min_num_options: 1,
|
|
98
|
+
max_num_options: 1,
|
|
99
|
+
options: [makeOption('opt-a'), makeOption('opt-b')],
|
|
100
|
+
}),
|
|
101
|
+
];
|
|
102
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
it('ignores options the platform cannot use when counting choices', () => {
|
|
105
|
+
const modifiers = [
|
|
106
|
+
makeModifier('mod-1', {
|
|
107
|
+
min_num_options: 1,
|
|
108
|
+
max_num_options: 1,
|
|
109
|
+
options: [
|
|
110
|
+
makeOption('opt-a'),
|
|
111
|
+
makeOption('opt-b', { excluded_platforms: [PLATFORM] }),
|
|
112
|
+
],
|
|
113
|
+
}),
|
|
114
|
+
];
|
|
115
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)?.kind).toBe('no-choice');
|
|
116
|
+
});
|
|
117
|
+
it('returns null when a nested level offers a choice', () => {
|
|
118
|
+
const nestedModifier = makeModifier('mod-2', {
|
|
119
|
+
min_num_options: 1,
|
|
120
|
+
max_num_options: 1,
|
|
121
|
+
options: [makeOption('opt-b'), makeOption('opt-c')],
|
|
122
|
+
});
|
|
123
|
+
const option = makeOption('opt-a', { modifiers: [nestedModifier] });
|
|
124
|
+
const modifiers = [
|
|
125
|
+
makeModifier('mod-1', { min_num_options: 1, max_num_options: 1, options: [option] }),
|
|
126
|
+
];
|
|
127
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)).toBeNull();
|
|
128
|
+
});
|
|
129
|
+
it('returns null when two usable modifier groups exist', () => {
|
|
130
|
+
const modifiers = [
|
|
131
|
+
makeModifier('mod-1', { min_num_options: 1, max_num_options: 1, options: [makeOption('a')] }),
|
|
132
|
+
makeModifier('mod-2', { min_num_options: 1, max_num_options: 1, options: [makeOption('b')] }),
|
|
133
|
+
];
|
|
134
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, PLATFORM)).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
it('returns plain when no platform is provided', () => {
|
|
137
|
+
const modifiers = [
|
|
138
|
+
makeModifier('mod-1', { min_num_options: 1, max_num_options: 1, options: [makeOption('a')] }),
|
|
139
|
+
];
|
|
140
|
+
expect((0, order_engine_1.getNoChoiceModifierSelection)(modifiers, undefined)).toEqual({ kind: 'plain' });
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -252,3 +252,79 @@ describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
|
|
|
252
252
|
expect(bevCategory.items).toHaveLength(0);
|
|
253
253
|
});
|
|
254
254
|
});
|
|
255
|
+
// =========================><=========================
|
|
256
|
+
describe('getReceiptItemModifiers - hide_modifier_name', () => {
|
|
257
|
+
it('merges an option name into the modifier name when they are the same', () => {
|
|
258
|
+
const options = [];
|
|
259
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
260
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
261
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
|
|
262
|
+
]),
|
|
263
|
+
], options, false, '', false);
|
|
264
|
+
expect(options).toHaveLength(1);
|
|
265
|
+
expect(options[0].left).toBe(' TIKKA PIZZA ');
|
|
266
|
+
expect(options[0].option_name).toBe('');
|
|
267
|
+
});
|
|
268
|
+
it('keeps the modifier name when the option name collapsed into it and hide_modifier_name is on', () => {
|
|
269
|
+
const options = [];
|
|
270
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
271
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
272
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
|
|
273
|
+
]),
|
|
274
|
+
], options, false, '', true);
|
|
275
|
+
expect(options).toHaveLength(1);
|
|
276
|
+
expect(options[0].left).toBe(' TIKKA PIZZA ');
|
|
277
|
+
expect(options[0].option_name).toBe('');
|
|
278
|
+
});
|
|
279
|
+
it('keeps the collapsed modifier name and quantity when hide_modifier_name is on', () => {
|
|
280
|
+
const options = [];
|
|
281
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
282
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
283
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza', { quantity: 2 }),
|
|
284
|
+
]),
|
|
285
|
+
], options, false, '', true);
|
|
286
|
+
expect(options).toHaveLength(1);
|
|
287
|
+
expect(options[0].left).toBe(' 2x TIKKA PIZZA ');
|
|
288
|
+
expect(options[0].option_name).toBe('');
|
|
289
|
+
});
|
|
290
|
+
it('still hides the modifier name when the option name is different', () => {
|
|
291
|
+
const options = [];
|
|
292
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-size', 'modref-size', 'SIZE', [makeOption('opt-large', 'size-large', 'Large')])], options, false, '', true);
|
|
293
|
+
expect(options).toHaveLength(1);
|
|
294
|
+
expect(options[0].left).toBe(' ');
|
|
295
|
+
expect(options[0].option_name).toBe('Large');
|
|
296
|
+
});
|
|
297
|
+
it('keeps the collapsed modifier name in separate-lines mode too', () => {
|
|
298
|
+
const options = [];
|
|
299
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
300
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
301
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
|
|
302
|
+
]),
|
|
303
|
+
], options, true, '', true);
|
|
304
|
+
expect(options).toHaveLength(1);
|
|
305
|
+
expect(options[0].left).toBe(' TIKKA PIZZA ');
|
|
306
|
+
expect(options[0].option_name).toBe('');
|
|
307
|
+
});
|
|
308
|
+
it('keeps the modifier name when only emojis remain in the option name', () => {
|
|
309
|
+
const options = [];
|
|
310
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
311
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
312
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza 🍕'),
|
|
313
|
+
]),
|
|
314
|
+
], options, false, '', true);
|
|
315
|
+
expect(options).toHaveLength(1);
|
|
316
|
+
expect(options[0].left).toBe(' TIKKA PIZZA ');
|
|
317
|
+
expect(options[0].option_name).toBe('');
|
|
318
|
+
});
|
|
319
|
+
it('keeps the modifier name when only emojis remain in separate-lines mode too', () => {
|
|
320
|
+
const options = [];
|
|
321
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
322
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
323
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza 🍕'),
|
|
324
|
+
]),
|
|
325
|
+
], options, true, '', true);
|
|
326
|
+
expect(options).toHaveLength(1);
|
|
327
|
+
expect(options[0].left).toBe(' TIKKA PIZZA ');
|
|
328
|
+
expect(options[0].option_name).toBe('');
|
|
329
|
+
});
|
|
330
|
+
});
|