@managesome/eposmatic-toolkit 0.2.768 → 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/order-engine.js +43 -4
- package/lib/helpers/utils/receipt-engine.js +14 -2
- package/lib/helpers/utils/specials-helpers.js +54 -2
- package/lib/tests/classic-specials-quantity.test.d.ts +1 -0
- package/lib/tests/classic-specials-quantity.test.js +322 -0
- package/lib/tests/engine-scope-item-vs-setup.test.d.ts +1 -0
- package/lib/tests/engine-scope-item-vs-setup.test.js +193 -0
- 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/lib/tests/specials-halfhalf-pricing.test.js +10 -2
- package/package.json +1 -1
|
@@ -686,7 +686,7 @@ function applySegmentPriceFloor(orderEngineItem, floorPrice) {
|
|
|
686
686
|
modifiers: raiseOptionPriceInModifiers(orderEngineItem.modifiers, target._id, delta),
|
|
687
687
|
});
|
|
688
688
|
}
|
|
689
|
-
function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderItemModifiers, platform, tenantId, excludeRefs, zeroPriceRefs, loyaltyRefs, voucherRefs, keepOptionalModifiersAtBottom, soldoutModifiers, depth = 0, priceReferences, parentPath, }) {
|
|
689
|
+
function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderItemModifiers, platform, tenantId, excludeRefs, zeroPriceRefs, loyaltyRefs, voucherRefs, keepOptionalModifiersAtBottom, soldoutModifiers, depth = 0, priceReferences, parentPath, isSetupSelection = false, }) {
|
|
690
690
|
function getSortedModifiers(modifiers = []) {
|
|
691
691
|
const sortedModifiers = modifiers.sort((a, b) => a.sort_id - b.sort_id);
|
|
692
692
|
return sortedModifiers;
|
|
@@ -739,8 +739,30 @@ function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderI
|
|
|
739
739
|
const option = sortedOptions[j];
|
|
740
740
|
if (excludeRefs != null && excludeRefs.includes(option.ref))
|
|
741
741
|
continue;
|
|
742
|
-
// Default values would be used in case of new order
|
|
743
|
-
|
|
742
|
+
// Default values would be used in case of new order. SETUP order items
|
|
743
|
+
// (specials / half-half) may hold the SAME option several times — a
|
|
744
|
+
// repeated pick merged into a quantity, the free/paid split of a
|
|
745
|
+
// partially free special group, or legacy per-slot options — so their
|
|
746
|
+
// occurrences AGGREGATE into the single engine option: the classic
|
|
747
|
+
// edit must not lose units nor flag a "missing selection" for repeated
|
|
748
|
+
// picks (a mixed free/paid set cannot be represented by one option, so
|
|
749
|
+
// any paid occurrence keeps it paid). Regular ITEM conversions keep the
|
|
750
|
+
// original single-match lookup (`find` + destructuring defaults).
|
|
751
|
+
const matchedOptions = isSetupSelection && orderItemModifier != null
|
|
752
|
+
? orderItemModifier.options.filter((orderOption) => orderOption._id === option._id)
|
|
753
|
+
: [];
|
|
754
|
+
const matchedOption = isSetupSelection
|
|
755
|
+
? matchedOptions[0]
|
|
756
|
+
: orderItemModifier?.options.find((orderOption) => orderOption._id === option._id);
|
|
757
|
+
const { modifiers: orderItemOptionModifiers, is_free: matchedIsFree = false, price = (0, platform_catalog_1.getPriceEnum)(option.price, platform), quantity: matchedQuantity = modifier.min_option_choice_quantity || 1, _id, } = matchedOption ?? {};
|
|
758
|
+
const quantity = isSetupSelection
|
|
759
|
+
? matchedOptions.reduce((total, orderOption) => total + (orderOption.quantity || 1), 0) ||
|
|
760
|
+
modifier.min_option_choice_quantity ||
|
|
761
|
+
1
|
|
762
|
+
: matchedQuantity;
|
|
763
|
+
const is_free = isSetupSelection
|
|
764
|
+
? matchedOptions.length > 0 && matchedOptions.every((orderOption) => orderOption.is_free)
|
|
765
|
+
: matchedIsFree;
|
|
744
766
|
let qty = quantity;
|
|
745
767
|
const isSoldout = option.sold_out.includes(tenantId) || soldoutModifiers?.includes(option.ref);
|
|
746
768
|
let isDefaultOption = false;
|
|
@@ -773,6 +795,7 @@ function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderI
|
|
|
773
795
|
depth: depth + 1,
|
|
774
796
|
priceReferences,
|
|
775
797
|
parentPath: `${modifierPath}_${option._id}`,
|
|
798
|
+
isSetupSelection,
|
|
776
799
|
});
|
|
777
800
|
// If zeroPriceRefs is present then we set the price to 0
|
|
778
801
|
const isZeroPriced = zeroPriceRefs != null && (zeroPriceRefs.includes(option.ref) || zeroPriceRefs.includes(modifier.ref));
|
|
@@ -806,7 +829,9 @@ function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderI
|
|
|
806
829
|
}
|
|
807
830
|
orderEngineSingleModifier.options.push(orderEngineSingleOption);
|
|
808
831
|
}
|
|
809
|
-
if (!orderItemModifier) {
|
|
832
|
+
if (!isSetupSelection && !orderItemModifier) {
|
|
833
|
+
// Regular items: ORIGINAL position — free marking runs BEFORE the
|
|
834
|
+
// lone-option auto-select (pre-existing behavior, untouched).
|
|
810
835
|
const options = makeSpaceForFreeOptions(orderEngineSingleModifier.options, modifier.num_free_options);
|
|
811
836
|
orderEngineSingleModifier.options = options;
|
|
812
837
|
}
|
|
@@ -828,6 +853,15 @@ function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderI
|
|
|
828
853
|
totalDefaultOptions = 1;
|
|
829
854
|
}
|
|
830
855
|
}
|
|
856
|
+
if (isSetupSelection && !orderItemModifier) {
|
|
857
|
+
// SETUP order items: free marking runs AFTER the lone-option
|
|
858
|
+
// auto-select so the auto-selected option takes part in
|
|
859
|
+
// `num_free_options` too — otherwise a special whose single option
|
|
860
|
+
// covers the free budget would charge for it when submitted without
|
|
861
|
+
// any further interaction.
|
|
862
|
+
const options = makeSpaceForFreeOptions(orderEngineSingleModifier.options, modifier.num_free_options);
|
|
863
|
+
orderEngineSingleModifier.options = options;
|
|
864
|
+
}
|
|
831
865
|
orderEngineSingleModifier.default = totalDefaultOptions > 0;
|
|
832
866
|
orderEngineModifiers.push(orderEngineSingleModifier);
|
|
833
867
|
}
|
|
@@ -983,6 +1017,10 @@ function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenant
|
|
|
983
1017
|
// Definition prices of every option, keyed by option path — the immutable
|
|
984
1018
|
// baseline the UI re-bases from before every price normalization.
|
|
985
1019
|
const originalPriceReferences = {};
|
|
1020
|
+
// Setup (specials / half-half) order items slide the setup-only engine
|
|
1021
|
+
// rules (duplicate-occurrence aggregation + free-after-auto-select);
|
|
1022
|
+
// regular ITEM conversions keep the original path.
|
|
1023
|
+
const isSetupSelection = orderItemType === constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL || orderItemType === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF;
|
|
986
1024
|
const orderEngineModifiers = convertCatalogItemModifierToOrderEngineItemModifier({
|
|
987
1025
|
modifiers: item.modifiers,
|
|
988
1026
|
orderItemModifiers: orderItem?.modifiers,
|
|
@@ -996,6 +1034,7 @@ function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenant
|
|
|
996
1034
|
soldoutModifiers,
|
|
997
1035
|
priceReferences: originalPriceReferences,
|
|
998
1036
|
parentPath: '',
|
|
1037
|
+
isSetupSelection,
|
|
999
1038
|
});
|
|
1000
1039
|
let itemPrice = item.price;
|
|
1001
1040
|
let discount_amount = item.discount_amount;
|
|
@@ -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({
|
|
@@ -639,6 +639,59 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
639
639
|
// (cannot be completed) — the whole conversion fails.
|
|
640
640
|
if (options.length === 0)
|
|
641
641
|
return null;
|
|
642
|
+
// ── Selection shape — DERIVED from how the drawer + engine consume
|
|
643
|
+
// these fields, not set generically ─────────────────────────────────
|
|
644
|
+
//
|
|
645
|
+
// Engine/UI switches on the fields (order-engine + drawer components):
|
|
646
|
+
// - `max_num_options === 1` → RADIO rows (tick one, no steppers)
|
|
647
|
+
// - `*_option_choice_quantity` set → stepper rows; a click seeds the
|
|
648
|
+
// row at `min_option_choice_quantity`; stepping below it deselects;
|
|
649
|
+
// a lone required option is AUTO-SELECTED on open at that quantity
|
|
650
|
+
// - `min/max_aggregate_options_quantity` → the UNIT total validation,
|
|
651
|
+
// click bounce and drawer caps enforce against (sum of option
|
|
652
|
+
// quantities — repeats included)
|
|
653
|
+
//
|
|
654
|
+
// A modifier special is "pick any mix of this group's items totalling
|
|
655
|
+
// `quantity` units". That leaves exactly two shapes:
|
|
656
|
+
// - quantity 1 → a single pick, no units involved: the engine-native
|
|
657
|
+
// RADIO shape (same config half-half segments use) — ticking a row
|
|
658
|
+
// selects it, ticking another switches, and the required flag keeps
|
|
659
|
+
// the pick from being deselected.
|
|
660
|
+
// - quantity > 1 → ticks cannot express units nor repeats, so the group
|
|
661
|
+
// must render as stepper rows with the AGGREGATES pinning the exact
|
|
662
|
+
// total (min = max = quantity): under-selection errors, exceeding
|
|
663
|
+
// bounces, and each row can repeat the same item. `min_num_options`
|
|
664
|
+
// stays 1 (never null) so the group is declared REQUIRED for every
|
|
665
|
+
// consumer that reads it directly (`min_num_options ?? ... ?? 0`) —
|
|
666
|
+
// the AGGREGATES remain the enforcement, and `max_num_options` stays
|
|
667
|
+
// null so the radio switch (`max_num_options === 1`) never trips on a
|
|
668
|
+
// multi-unit group. The click quantity differs by necessity:
|
|
669
|
+
// · multi-item group → a click adds ONE unit (the cashier
|
|
670
|
+
// distributes the rest with the steppers),
|
|
671
|
+
// · single-item group → there is no choice to make, so a click
|
|
672
|
+
// selects the FULL quantity in one go, and the engine's
|
|
673
|
+
// lone-required-option auto-select seeds it with the same amount
|
|
674
|
+
// the moment the drawer opens — identical outcome to the modern
|
|
675
|
+
// flow's slot auto-fill.
|
|
676
|
+
const groupQuantity = Math.max(1, modifierSpecial.quantity || 1);
|
|
677
|
+
const isSingleOptionGroup = options.length === 1;
|
|
678
|
+
const selectionShape = groupQuantity === 1
|
|
679
|
+
? {
|
|
680
|
+
min_num_options: 1,
|
|
681
|
+
max_num_options: 1,
|
|
682
|
+
min_option_choice_quantity: null,
|
|
683
|
+
max_option_choice_quantity: null,
|
|
684
|
+
min_aggregate_options_quantity: null,
|
|
685
|
+
max_aggregate_options_quantity: null,
|
|
686
|
+
}
|
|
687
|
+
: {
|
|
688
|
+
min_num_options: 1,
|
|
689
|
+
max_num_options: null,
|
|
690
|
+
min_option_choice_quantity: isSingleOptionGroup ? groupQuantity : 1,
|
|
691
|
+
max_option_choice_quantity: groupQuantity,
|
|
692
|
+
min_aggregate_options_quantity: groupQuantity,
|
|
693
|
+
max_aggregate_options_quantity: groupQuantity,
|
|
694
|
+
};
|
|
642
695
|
modifiers.push({
|
|
643
696
|
// `_id` is the real modifier-special `_id` (like a catalog modifier id);
|
|
644
697
|
// `ref` points to the same source modifier-special.
|
|
@@ -649,8 +702,7 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
649
702
|
active: true,
|
|
650
703
|
sold_out: [],
|
|
651
704
|
sort_id: modifierSpecial.sort_id,
|
|
652
|
-
|
|
653
|
-
max_num_options: modifierSpecial.quantity,
|
|
705
|
+
...selectionShape,
|
|
654
706
|
num_free_options: modifierSpecial.num_free_items > 0 ? modifierSpecial.num_free_items : null,
|
|
655
707
|
options,
|
|
656
708
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
const specials_helpers_1 = require("../helpers/utils/specials-helpers");
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Classic preview (`pos_enable_classic_specials_preview`) quantity parity.
|
|
8
|
+
//
|
|
9
|
+
// The modern flow lets a cashier pick the same item several times in a group
|
|
10
|
+
// (merged into one option with a summed quantity). The classic drawer must
|
|
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),
|
|
18
|
+
// - stored lines with repeated options (merged quantity, free/paid split)
|
|
19
|
+
// EDIT losslessly — occurrences aggregate into the one engine option.
|
|
20
|
+
// ============================================================================
|
|
21
|
+
const TENANT_ID = 'tenant-1';
|
|
22
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
23
|
+
function makeItem(id, price, overrides = {}) {
|
|
24
|
+
return {
|
|
25
|
+
_id: id,
|
|
26
|
+
brand_id: 'brand-1',
|
|
27
|
+
tenants: [TENANT_ID],
|
|
28
|
+
category_id: 'pizza-cat',
|
|
29
|
+
included_platforms: [PLATFORM],
|
|
30
|
+
name: `Item ${id}`,
|
|
31
|
+
active: true,
|
|
32
|
+
sold_out: [],
|
|
33
|
+
sort_id: 1,
|
|
34
|
+
image_url: '',
|
|
35
|
+
price: { BASE_PRICE: price },
|
|
36
|
+
discount_amount: null,
|
|
37
|
+
is_discount_percentage: false,
|
|
38
|
+
tax_rate: null,
|
|
39
|
+
keywords: [],
|
|
40
|
+
caveats: [],
|
|
41
|
+
dietary_preferences: [],
|
|
42
|
+
hide_name: false,
|
|
43
|
+
description: '',
|
|
44
|
+
ingredients: null,
|
|
45
|
+
is_featured: false,
|
|
46
|
+
featured_sort_id: 0,
|
|
47
|
+
item_special_hours: null,
|
|
48
|
+
display_price: null,
|
|
49
|
+
show_starting_from: false,
|
|
50
|
+
createdAt: new Date('2024-01-01'),
|
|
51
|
+
updatedAt: new Date('2024-01-02'),
|
|
52
|
+
modifiers: null,
|
|
53
|
+
...overrides,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const itemsMap = {
|
|
57
|
+
donut: makeItem('donut', 300),
|
|
58
|
+
pizzaA: makeItem('pizzaA', 400),
|
|
59
|
+
pizzaB: makeItem('pizzaB', 450),
|
|
60
|
+
};
|
|
61
|
+
function makeGroup({ quantity = 2, num_free_items = 0, items = ['donut'], } = {}) {
|
|
62
|
+
return {
|
|
63
|
+
_id: 'mod-donut',
|
|
64
|
+
name: 'Donuts',
|
|
65
|
+
sort_id: 1,
|
|
66
|
+
quantity,
|
|
67
|
+
num_free_items,
|
|
68
|
+
excluded_refs: [],
|
|
69
|
+
exclusive_refs: [],
|
|
70
|
+
omit_items_schedule: false,
|
|
71
|
+
items: items.map((item_id, index) => ({ item_id, sort_id: index + 1, upsell_price: null })),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function makeSpecial(overrides = {}) {
|
|
75
|
+
return {
|
|
76
|
+
_id: 'special-1',
|
|
77
|
+
brand_id: 'brand-1',
|
|
78
|
+
tenants: [TENANT_ID],
|
|
79
|
+
category_id: 'combo-cat',
|
|
80
|
+
included_platforms: [PLATFORM],
|
|
81
|
+
name: '2 Donut Deal',
|
|
82
|
+
description: '',
|
|
83
|
+
active: true,
|
|
84
|
+
sold_out: [],
|
|
85
|
+
sort_id: 1,
|
|
86
|
+
image_url: '',
|
|
87
|
+
price: { BASE_PRICE: 500 },
|
|
88
|
+
discount_amount: null,
|
|
89
|
+
is_discount_percentage: false,
|
|
90
|
+
display_price: null,
|
|
91
|
+
show_starting_from: false,
|
|
92
|
+
item_special_hours: null,
|
|
93
|
+
modifier_specials: [makeGroup()],
|
|
94
|
+
createdAt: new Date('2024-01-01'),
|
|
95
|
+
updatedAt: new Date('2024-01-02'),
|
|
96
|
+
...overrides,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function makeWorkableSpecial(group) {
|
|
100
|
+
return {
|
|
101
|
+
_id: 'special-1',
|
|
102
|
+
name: '2 Donut Deal',
|
|
103
|
+
description: '',
|
|
104
|
+
sold_out: [],
|
|
105
|
+
image_url: '',
|
|
106
|
+
category_id: 'combo-cat',
|
|
107
|
+
price: { BASE_PRICE: 500 },
|
|
108
|
+
discount_amount: null,
|
|
109
|
+
is_discount_percentage: false,
|
|
110
|
+
display_price: null,
|
|
111
|
+
show_starting_from: false,
|
|
112
|
+
modifier_specials: [
|
|
113
|
+
{
|
|
114
|
+
_id: group._id,
|
|
115
|
+
name: group.name,
|
|
116
|
+
quantity: group.quantity,
|
|
117
|
+
num_free_items: group.num_free_items,
|
|
118
|
+
items: [],
|
|
119
|
+
exclusive_refs: [],
|
|
120
|
+
excluded_refs: [],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function makeSlotItem(item_id, price) {
|
|
126
|
+
return {
|
|
127
|
+
_id: `slot-${item_id}`,
|
|
128
|
+
item_id,
|
|
129
|
+
menu_id: 'menu-1',
|
|
130
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
131
|
+
name: `Item ${item_id}`,
|
|
132
|
+
price,
|
|
133
|
+
subtotal: price,
|
|
134
|
+
quantity: 1,
|
|
135
|
+
special_instructions: '',
|
|
136
|
+
item_discount_details: null,
|
|
137
|
+
tax_rate: 0,
|
|
138
|
+
modifiers: null,
|
|
139
|
+
_discount_amount: 0,
|
|
140
|
+
_gross_amount: 0,
|
|
141
|
+
_gst_amount: 0,
|
|
142
|
+
_net_amount: 0,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function buildModernLine(group, slotIds, price = 300) {
|
|
146
|
+
return (0, specials_helpers_1.convertSpecialItemToOrderItem)({
|
|
147
|
+
specialItem: makeWorkableSpecial(group),
|
|
148
|
+
modifierSpecials: [{ _id: group._id, selectedItems: slotIds.map((id) => makeSlotItem(id, price)) }],
|
|
149
|
+
quantity: 1,
|
|
150
|
+
platform: PLATFORM,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function classicEngineState(converted, orderItem) {
|
|
154
|
+
return (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
155
|
+
item: converted,
|
|
156
|
+
orderItem,
|
|
157
|
+
platform: PLATFORM,
|
|
158
|
+
tenantId: TENANT_ID,
|
|
159
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
160
|
+
defaultMenuId: null,
|
|
161
|
+
soldoutModifiers: [],
|
|
162
|
+
}).workingData;
|
|
163
|
+
}
|
|
164
|
+
function optionClickId(engineItem, optionIndex = 0) {
|
|
165
|
+
const group = engineItem.modifiers[0];
|
|
166
|
+
return `${group._id}_${group.options[optionIndex]._id}`;
|
|
167
|
+
}
|
|
168
|
+
describe('convertSpecialToItem: quantity-capable classic groups', () => {
|
|
169
|
+
it('configures a single-item group to be selected in one click at the full quantity', () => {
|
|
170
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
171
|
+
const group = converted.modifiers[0];
|
|
172
|
+
// Required flag stays >= 1 (`min_num_options ?? min_aggregate ?? 0`
|
|
173
|
+
// consumers mark the group REQUIRED); the exact total is enforced by the
|
|
174
|
+
// aggregates, and max stays null so the radio switch never trips.
|
|
175
|
+
expect(group.min_num_options).toBe(1);
|
|
176
|
+
expect(group.max_num_options).toBeNull();
|
|
177
|
+
expect(group.min_aggregate_options_quantity).toBe(2);
|
|
178
|
+
expect(group.max_aggregate_options_quantity).toBe(2);
|
|
179
|
+
// Single item: the click quantity IS the required total (no choice).
|
|
180
|
+
expect(group.min_option_choice_quantity).toBe(2);
|
|
181
|
+
expect(group.max_option_choice_quantity).toBe(2);
|
|
182
|
+
});
|
|
183
|
+
it('keeps the per-option minimum at 1 for a mix of items', () => {
|
|
184
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [makeGroup({ items: ['pizzaA', 'pizzaB'] })] }), itemsMap, {});
|
|
185
|
+
const group = converted.modifiers[0];
|
|
186
|
+
expect(group.min_num_options).toBe(1);
|
|
187
|
+
expect(group.min_option_choice_quantity).toBe(1);
|
|
188
|
+
expect(group.max_option_choice_quantity).toBe(2);
|
|
189
|
+
expect(group.min_aggregate_options_quantity).toBe(2);
|
|
190
|
+
});
|
|
191
|
+
it('keeps a single-unit group as the engine-native RADIO shape (no steppers)', () => {
|
|
192
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [makeGroup({ quantity: 1, items: ['pizzaA', 'pizzaB'] })] }), itemsMap, {});
|
|
193
|
+
const group = converted.modifiers[0];
|
|
194
|
+
// One pick, no quantities involved: `max_num_options === 1` IS the switch
|
|
195
|
+
// the drawer reads for radio rows, and leaving the choice/aggregate fields
|
|
196
|
+
// null keeps the steppers (and their caps) out of a single-pick group.
|
|
197
|
+
expect(group.min_num_options).toBe(1);
|
|
198
|
+
expect(group.max_num_options).toBe(1);
|
|
199
|
+
expect(group.min_option_choice_quantity).toBeNull();
|
|
200
|
+
expect(group.max_option_choice_quantity).toBeNull();
|
|
201
|
+
expect(group.min_aggregate_options_quantity).toBeNull();
|
|
202
|
+
expect(group.max_aggregate_options_quantity).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('classic add: single choice with quantity > 1', () => {
|
|
206
|
+
it('auto-selects the lone option at the full quantity when the drawer opens', () => {
|
|
207
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
208
|
+
// The engine seeds a lone required option with `min_option_choice_quantity`
|
|
209
|
+
// — for a single-item group that IS the required total, so the drawer opens
|
|
210
|
+
// complete (same outcome as the modern flow's slot auto-fill).
|
|
211
|
+
const fresh = classicEngineState(converted);
|
|
212
|
+
expect(fresh.error_id).toBeUndefined();
|
|
213
|
+
expect(fresh.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 2 }));
|
|
214
|
+
});
|
|
215
|
+
it('auto-selects AND free-marks the lone option of a fully-free group on open', () => {
|
|
216
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [makeGroup({ num_free_items: 2 })] }), itemsMap, {});
|
|
217
|
+
// Free marking must run AFTER the auto-select, otherwise submitting
|
|
218
|
+
// without any interaction would charge for the auto-selected units.
|
|
219
|
+
const fresh = classicEngineState(converted);
|
|
220
|
+
expect(fresh.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 2, is_free: true }));
|
|
221
|
+
});
|
|
222
|
+
it('satisfies the required total with one click and stores the summed quantity', () => {
|
|
223
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
224
|
+
const fresh = classicEngineState(converted);
|
|
225
|
+
const clicked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh), true);
|
|
226
|
+
// Previously the group demanded two DISTINCT picks: clicking the only
|
|
227
|
+
// option left `error_id` set and the quantity stuck at 1.
|
|
228
|
+
expect(clicked.error_id).toBeUndefined();
|
|
229
|
+
expect(clicked.modifiers[0].options[0].quantity).toBe(2);
|
|
230
|
+
const orderItem = (0, order_engine_1.convertOrderEngineItemToOrderItem)(clicked, TENANT_ID);
|
|
231
|
+
expect(orderItem.modifiers[0].options).toEqual([expect.objectContaining({ ref: 'donut', quantity: 2 })]);
|
|
232
|
+
});
|
|
233
|
+
it('deselecting the only item restores the required error', () => {
|
|
234
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
235
|
+
const fresh = classicEngineState(converted);
|
|
236
|
+
const clicked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh), true);
|
|
237
|
+
const unclicked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(clicked, optionClickId(clicked), false);
|
|
238
|
+
expect(unclicked.error_id).toBe('mod-donut');
|
|
239
|
+
});
|
|
240
|
+
it('allows picking the same item twice in a multi-item group', () => {
|
|
241
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [makeGroup({ items: ['pizzaA', 'pizzaB'] })] }), itemsMap, {});
|
|
242
|
+
let engine = classicEngineState(converted);
|
|
243
|
+
const identifier = optionClickId(engine);
|
|
244
|
+
// Pick pizza A once, then STEP it up to 2 — the old tick-only group could
|
|
245
|
+
// only ever select two DISTINCT items.
|
|
246
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, identifier, true);
|
|
247
|
+
expect(engine.modifiers[0].options.find((o) => o._id === 'pizzaA').quantity).toBe(1);
|
|
248
|
+
engine = (0, order_engine_1.setUpdateSelectedOrderEngineOptionQuantity)(engine, identifier, 1, true);
|
|
249
|
+
expect(engine.modifiers[0].options.find((o) => o._id === 'pizzaA').quantity).toBe(2);
|
|
250
|
+
expect(engine.error_id).toBeUndefined();
|
|
251
|
+
});
|
|
252
|
+
it('marks both units free for a "2 Free Donuts" group', () => {
|
|
253
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [makeGroup({ num_free_items: 2 })] }), itemsMap, {});
|
|
254
|
+
const fresh = classicEngineState(converted);
|
|
255
|
+
const clicked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh), true);
|
|
256
|
+
expect(clicked.modifiers[0].options[0]).toEqual(expect.objectContaining({ quantity: 2, is_free: true }));
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe('classic add: single-unit groups behave like a radio modifier', () => {
|
|
260
|
+
const unitSpecial = (items, num_free_items = 0) => makeSpecial({ modifier_specials: [makeGroup({ quantity: 1, items, num_free_items })] });
|
|
261
|
+
it('selects one pick and switches between options (radio semantics)', () => {
|
|
262
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(unitSpecial(['pizzaA', 'pizzaB']), itemsMap, {});
|
|
263
|
+
const fresh = classicEngineState(converted);
|
|
264
|
+
const pickA = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh, 0), true);
|
|
265
|
+
expect(pickA.error_id).toBeUndefined();
|
|
266
|
+
expect(pickA.modifiers[0].options.map((option) => option.default)).toEqual([true, false]);
|
|
267
|
+
// Ticking the other item REPLACES the pick (radio), it does not add a unit.
|
|
268
|
+
const pickB = (0, order_engine_1.setCheckFieldInOrderEngineItem)(pickA, optionClickId(pickA, 1), true);
|
|
269
|
+
expect(pickB.modifiers[0].options.map((option) => option.default)).toEqual([false, true]);
|
|
270
|
+
expect(pickB.modifiers[0].options[1].quantity).toBe(1);
|
|
271
|
+
expect(pickB.error_id).toBeUndefined();
|
|
272
|
+
});
|
|
273
|
+
it('auto-selects the only option and the required pick cannot be cleared', () => {
|
|
274
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(unitSpecial(['donut']), itemsMap, {});
|
|
275
|
+
const fresh = classicEngineState(converted);
|
|
276
|
+
expect(fresh.modifiers[0].options[0].default).toBe(true);
|
|
277
|
+
expect(fresh.error_id).toBeUndefined();
|
|
278
|
+
// The radio screen always sends `shouldCheck: true` for the row it renders
|
|
279
|
+
// as selected — the pick stays selected (required radio).
|
|
280
|
+
const reclicked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh), true);
|
|
281
|
+
expect(reclicked.modifiers[0].options[0].default).toBe(true);
|
|
282
|
+
expect(reclicked.error_id).toBeUndefined();
|
|
283
|
+
});
|
|
284
|
+
it('free-marks the single pick when num_free_items covers it', () => {
|
|
285
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(unitSpecial(['pizzaA', 'pizzaB'], 1), itemsMap, {});
|
|
286
|
+
const fresh = classicEngineState(converted);
|
|
287
|
+
const picked = (0, order_engine_1.setCheckFieldInOrderEngineItem)(fresh, optionClickId(fresh, 0), true);
|
|
288
|
+
expect(picked.modifiers[0].options[0]).toEqual(expect.objectContaining({ quantity: 1, is_free: true }));
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
describe('classic edit: repeated stored options aggregate into one engine option', () => {
|
|
292
|
+
it('maps a merged [qty 2] line without losing units or flagging an error', () => {
|
|
293
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
294
|
+
const modern = buildModernLine(makeGroup(), ['donut', 'donut']);
|
|
295
|
+
const engine = classicEngineState(converted, modern);
|
|
296
|
+
expect(engine.error_id).toBeUndefined();
|
|
297
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 2, is_free: false }));
|
|
298
|
+
const resaved = (0, order_engine_1.convertOrderEngineItemToOrderItem)(engine, TENANT_ID);
|
|
299
|
+
expect(resaved.modifiers[0].options).toEqual([
|
|
300
|
+
expect.objectContaining({ ref: 'donut', quantity: 2, is_free: false }),
|
|
301
|
+
]);
|
|
302
|
+
});
|
|
303
|
+
it('maps a free/paid split line (previously blocked) keeping it PAID', () => {
|
|
304
|
+
const group = makeGroup({ num_free_items: 1 });
|
|
305
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [group] }), itemsMap, {});
|
|
306
|
+
const modern = buildModernLine(group, ['donut', 'donut']);
|
|
307
|
+
// Modern free marking split the two units: one free, one paid.
|
|
308
|
+
expect(modern.modifiers[0].options.map((o) => o.is_free)).toEqual([true, false]);
|
|
309
|
+
const engine = classicEngineState(converted, modern);
|
|
310
|
+
expect(engine.error_id).toBeUndefined();
|
|
311
|
+
// One engine option cannot be half free: any paid occurrence keeps it paid.
|
|
312
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ quantity: 2, is_free: false }));
|
|
313
|
+
});
|
|
314
|
+
it('keeps an all-free repeated line free', () => {
|
|
315
|
+
const group = makeGroup({ num_free_items: 2 });
|
|
316
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ modifier_specials: [group] }), itemsMap, {});
|
|
317
|
+
const modern = buildModernLine(group, ['donut', 'donut']);
|
|
318
|
+
const engine = classicEngineState(converted, modern);
|
|
319
|
+
expect(engine.error_id).toBeUndefined();
|
|
320
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ quantity: 2, is_free: true }));
|
|
321
|
+
});
|
|
322
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
// SCOPE GUARD — the two setup-only engine rules must never leak into the
|
|
7
|
+
// regular item selection path:
|
|
8
|
+
//
|
|
9
|
+
// 1. duplicate stored occurrences of one option are AGGREGATED for
|
|
10
|
+
// SPECIAL / HALF_HALF order items (merged repeats, free/paid splits,
|
|
11
|
+
// legacy per-slot options). Regular ITEM conversions keep the original
|
|
12
|
+
// single-match (`find`) lookup.
|
|
13
|
+
// 2. free marking (`num_free_options`) runs AFTER the lone-option
|
|
14
|
+
// auto-select for setups (auto-selected option takes part in it).
|
|
15
|
+
// Regular ITEM conversions keep the original position (free marking
|
|
16
|
+
// before the auto-select).
|
|
17
|
+
//
|
|
18
|
+
// If these tests fail, a specials/half-half change has altered the item
|
|
19
|
+
// process — that is not allowed.
|
|
20
|
+
// ============================================================================
|
|
21
|
+
const TENANT_ID = 'tenant-1';
|
|
22
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
23
|
+
function makeItem(overrides = {}) {
|
|
24
|
+
return {
|
|
25
|
+
_id: 'item-1',
|
|
26
|
+
brand_id: 'brand-1',
|
|
27
|
+
tenants: [TENANT_ID],
|
|
28
|
+
category_id: 'cat-1',
|
|
29
|
+
included_platforms: [PLATFORM],
|
|
30
|
+
name: 'Item',
|
|
31
|
+
hide_name: false,
|
|
32
|
+
description: '',
|
|
33
|
+
active: true,
|
|
34
|
+
sold_out: [],
|
|
35
|
+
sort_id: 1,
|
|
36
|
+
price: { BASE_PRICE: 500 },
|
|
37
|
+
discount_amount: null,
|
|
38
|
+
is_discount_percentage: false,
|
|
39
|
+
tax_rate: null,
|
|
40
|
+
keywords: [],
|
|
41
|
+
caveats: [],
|
|
42
|
+
dietary_preferences: [],
|
|
43
|
+
image_url: '',
|
|
44
|
+
ingredients: null,
|
|
45
|
+
item_special_hours: null,
|
|
46
|
+
modifiers: null,
|
|
47
|
+
is_featured: false,
|
|
48
|
+
featured_sort_id: 0,
|
|
49
|
+
display_price: null,
|
|
50
|
+
show_starting_from: false,
|
|
51
|
+
createdAt: new Date('2024-01-01'),
|
|
52
|
+
updatedAt: new Date('2024-01-02'),
|
|
53
|
+
...overrides,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function makeStoredOption(quantity, is_free) {
|
|
57
|
+
return {
|
|
58
|
+
_id: 'opt-a',
|
|
59
|
+
ref: 'opt-a',
|
|
60
|
+
name: 'A',
|
|
61
|
+
price: 300,
|
|
62
|
+
quantity,
|
|
63
|
+
is_free,
|
|
64
|
+
modifiers: [],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function makeStoredModifier(options) {
|
|
68
|
+
return { _id: 'mod-1', ref: 'mod-1', name: 'Sauce', options };
|
|
69
|
+
}
|
|
70
|
+
function makeOrderItem(modifiers, itemType) {
|
|
71
|
+
return {
|
|
72
|
+
_id: 'order-item-1',
|
|
73
|
+
item_id: 'item-1',
|
|
74
|
+
menu_id: null,
|
|
75
|
+
item_type: itemType,
|
|
76
|
+
name: 'Item',
|
|
77
|
+
price: 500,
|
|
78
|
+
subtotal: 0,
|
|
79
|
+
quantity: 1,
|
|
80
|
+
special_instructions: '',
|
|
81
|
+
item_discount_details: null,
|
|
82
|
+
tax_rate: 0,
|
|
83
|
+
modifiers,
|
|
84
|
+
_discount_amount: 0,
|
|
85
|
+
_gross_amount: 0,
|
|
86
|
+
_gst_amount: 0,
|
|
87
|
+
_net_amount: 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** One modifier with the single option `opt-a` the fixtures reference. */
|
|
91
|
+
const itemWithOneOption = makeItem({
|
|
92
|
+
modifiers: [
|
|
93
|
+
{
|
|
94
|
+
_id: 'mod-1',
|
|
95
|
+
ref: 'mod-1',
|
|
96
|
+
name: 'Sauce',
|
|
97
|
+
description: '',
|
|
98
|
+
active: true,
|
|
99
|
+
sold_out: [],
|
|
100
|
+
sort_id: 1,
|
|
101
|
+
options: [
|
|
102
|
+
{
|
|
103
|
+
_id: 'opt-a',
|
|
104
|
+
ref: 'opt-a',
|
|
105
|
+
name: 'A',
|
|
106
|
+
active: true,
|
|
107
|
+
sold_out: [],
|
|
108
|
+
sort_id: 1,
|
|
109
|
+
excluded_platforms: [],
|
|
110
|
+
price: { BASE_PRICE: 300 },
|
|
111
|
+
modifiers: null,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
function convert(item, orderItem, orderItemType) {
|
|
118
|
+
return (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
119
|
+
item,
|
|
120
|
+
orderItem,
|
|
121
|
+
platform: PLATFORM,
|
|
122
|
+
tenantId: TENANT_ID,
|
|
123
|
+
orderItemType,
|
|
124
|
+
defaultMenuId: null,
|
|
125
|
+
soldoutModifiers: [],
|
|
126
|
+
}).workingData;
|
|
127
|
+
}
|
|
128
|
+
describe('engine scope guard: duplicate occurrences (setup-only aggregation)', () => {
|
|
129
|
+
it('KEEPS the original single-match lookup for ITEM conversions', () => {
|
|
130
|
+
const orderItem = makeOrderItem([makeStoredModifier([makeStoredOption(2, false), makeStoredOption(1, true)])], constants_1.ORDER_ITEM_TYPE_ENUM.ITEM);
|
|
131
|
+
const engine = convert(itemWithOneOption, orderItem, constants_1.ORDER_ITEM_TYPE_ENUM.ITEM);
|
|
132
|
+
const option = engine.modifiers[0].options[0];
|
|
133
|
+
// Original behavior: FIRST occurrence wins (quantity 2, is_free false —
|
|
134
|
+
// the second occurrence is ignored), exactly as before the setup work.
|
|
135
|
+
expect(option).toEqual(expect.objectContaining({ default: true, quantity: 2, is_free: false }));
|
|
136
|
+
});
|
|
137
|
+
it('AGGREGATES occurrences for SPECIAL conversions (merged repeats / free split)', () => {
|
|
138
|
+
const orderItem = makeOrderItem([makeStoredModifier([makeStoredOption(2, false), makeStoredOption(1, true)])], constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL);
|
|
139
|
+
const engine = convert(itemWithOneOption, orderItem, constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL);
|
|
140
|
+
const option = engine.modifiers[0].options[0];
|
|
141
|
+
// Quantity summed (2 + 1); a paid occurrence keeps the row paid.
|
|
142
|
+
expect(option).toEqual(expect.objectContaining({ default: true, quantity: 3, is_free: false }));
|
|
143
|
+
expect(engine.error_id).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
it('AGGREGATES all-free occurrences to a free quantity row (SPECIAL)', () => {
|
|
146
|
+
const orderItem = makeOrderItem([makeStoredModifier([makeStoredOption(2, true), makeStoredOption(1, true)])], constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL);
|
|
147
|
+
const engine = convert(itemWithOneOption, orderItem, constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL);
|
|
148
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 3, is_free: true }));
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('engine scope guard: free marking position (setup-only reorder)', () => {
|
|
152
|
+
// A required modifier with ONE option and a free budget covering it — the
|
|
153
|
+
// exact shape the reorder targets.
|
|
154
|
+
const freshItem = makeItem({
|
|
155
|
+
modifiers: [
|
|
156
|
+
{
|
|
157
|
+
_id: 'mod-1',
|
|
158
|
+
ref: 'mod-1',
|
|
159
|
+
name: 'Sauce',
|
|
160
|
+
description: '',
|
|
161
|
+
active: true,
|
|
162
|
+
sold_out: [],
|
|
163
|
+
sort_id: 1,
|
|
164
|
+
min_num_options: 1,
|
|
165
|
+
max_num_options: 1,
|
|
166
|
+
num_free_options: 1,
|
|
167
|
+
options: [
|
|
168
|
+
{
|
|
169
|
+
_id: 'opt-a',
|
|
170
|
+
ref: 'opt-a',
|
|
171
|
+
name: 'A',
|
|
172
|
+
active: true,
|
|
173
|
+
sold_out: [],
|
|
174
|
+
sort_id: 1,
|
|
175
|
+
excluded_platforms: [],
|
|
176
|
+
price: { BASE_PRICE: 300 },
|
|
177
|
+
modifiers: null,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
it('KEEPS the original position for ITEM conversions (auto-selected, not free)', () => {
|
|
184
|
+
const engine = convert(freshItem, undefined, constants_1.ORDER_ITEM_TYPE_ENUM.ITEM);
|
|
185
|
+
// Original behavior: free marking ran BEFORE the auto-select, so the
|
|
186
|
+
// auto-selected option is not free until the user interacts.
|
|
187
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 1, is_free: false }));
|
|
188
|
+
});
|
|
189
|
+
it('free-marks the auto-selected option for SPECIAL conversions', () => {
|
|
190
|
+
const engine = convert(freshItem, undefined, constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL);
|
|
191
|
+
expect(engine.modifiers[0].options[0]).toEqual(expect.objectContaining({ default: true, quantity: 1, is_free: true }));
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -328,8 +328,16 @@ describe('Specials alone — convertSpecialToItem pricing', () => {
|
|
|
328
328
|
],
|
|
329
329
|
}), itemsMap, {});
|
|
330
330
|
const group = item.modifiers[0];
|
|
331
|
-
|
|
332
|
-
|
|
331
|
+
// Quantity-capable group (classic parity with the modern slot flow): the
|
|
332
|
+
// exact total is enforced by the AGGREGATES (any mix, repeats allowed),
|
|
333
|
+
// the drawer renders quantity rows, min_num_options stays 1 (required
|
|
334
|
+
// flag), and num_free_options still mirrors num_free_items.
|
|
335
|
+
expect(group.min_num_options).toBe(1);
|
|
336
|
+
expect(group.max_num_options).toBeNull();
|
|
337
|
+
expect(group.min_aggregate_options_quantity).toBe(2);
|
|
338
|
+
expect(group.max_aggregate_options_quantity).toBe(2);
|
|
339
|
+
expect(group.min_option_choice_quantity).toBe(1); // a real mix of items
|
|
340
|
+
expect(group.max_option_choice_quantity).toBe(2);
|
|
333
341
|
expect(group.num_free_options).toBe(1);
|
|
334
342
|
});
|
|
335
343
|
it('exclusive_refs zero nested item modifier prices; excluded_refs REMOVE them (recursive)', () => {
|