@managesome/eposmatic-toolkit 0.2.713 → 0.2.716
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/halfhalf-setup-helpers.d.ts +31 -1
- package/lib/helpers/utils/halfhalf-setup-helpers.js +81 -29
- package/lib/helpers/utils/specials-helpers.d.ts +1 -1
- package/lib/helpers/utils/specials-helpers.js +54 -6
- package/lib/tests/specials-halfhalf-options.test.js +261 -3
- package/lib/tests/specials-halfhalf-pricing.test.d.ts +1 -0
- package/lib/tests/specials-halfhalf-pricing.test.js +957 -0
- package/package.json +1 -1
|
@@ -43,6 +43,30 @@ export declare function divideItemPriceBySegments<T extends {
|
|
|
43
43
|
modifiers?: IModifier[] | null | undefined;
|
|
44
44
|
}>(item: T, segments: number | undefined | null): T;
|
|
45
45
|
export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem>(halfhalfSetups: IHalfHalfSetup[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableHalfHalfSetup<T>[];
|
|
46
|
+
export type ISpecialHalfHalfItem = {
|
|
47
|
+
item_id: string;
|
|
48
|
+
upsell_price: IPrice | null | undefined;
|
|
49
|
+
sort_id?: number;
|
|
50
|
+
};
|
|
51
|
+
export interface IConvertHalfHalfToItemOptions {
|
|
52
|
+
/**
|
|
53
|
+
* When the half-half is an OPTION inside a special, the segment options ARE
|
|
54
|
+
* the special's own (non-half-half) items — the half-half's original item
|
|
55
|
+
* list is NOT used. Each option is priced from its special upsell divided
|
|
56
|
+
* by the number of segments (no upsell → free), the half-half's own ref
|
|
57
|
+
* rules/per-item upsells are ignored, and only `choose_expensive_segment_price`
|
|
58
|
+
* is taken from the setup. Upsell prices are thus defined once in the
|
|
59
|
+
* special and apply whether an item is picked directly or inside a half-half.
|
|
60
|
+
*/
|
|
61
|
+
specialItems?: ISpecialHalfHalfItem[];
|
|
62
|
+
/**
|
|
63
|
+
* In special context this REPLACES the half-half's own setup upsell as the
|
|
64
|
+
* item-level price: it is the special's upsell for the half-half option
|
|
65
|
+
* itself (null/undefined → the half-half is free inside the special). The
|
|
66
|
+
* half-half's own `upsell_price` is NEVER used inside a special.
|
|
67
|
+
*/
|
|
68
|
+
specialHalfHalfUpsell?: IPrice | null | undefined;
|
|
69
|
+
}
|
|
46
70
|
/**
|
|
47
71
|
* Converts an IHalfHalfSetup into an IItem so it can flow through the standard
|
|
48
72
|
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
@@ -53,6 +77,12 @@ export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends II
|
|
|
53
77
|
* Required (price-defining) modifier option prices are divided with the base
|
|
54
78
|
* (e.g. Pizza Size 1150 -> 575); optional upsell modifier prices stay full.
|
|
55
79
|
*
|
|
80
|
+
* When the half-half is nested in a special (pass `specialItems`), the special
|
|
81
|
+
* is the authority instead: the segment options are the special's own items
|
|
82
|
+
* (priced from their special upsell split per segment), the half-half's own
|
|
83
|
+
* item list/ref rules/per-item upsells are ignored, and only
|
|
84
|
+
* `choose_expensive_segment_price` is taken from the setup.
|
|
85
|
+
*
|
|
56
86
|
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
57
87
|
* included_platforms), no special-hours / platform-based price resolution,
|
|
58
88
|
* and NO `choose_expensive_segment_price` handling: that rule depends on
|
|
@@ -69,7 +99,7 @@ export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends II
|
|
|
69
99
|
*
|
|
70
100
|
* Returns null only when no option can be resolved from the items map.
|
|
71
101
|
*/
|
|
72
|
-
export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem
|
|
102
|
+
export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>, options?: IConvertHalfHalfToItemOptions): IItem | null;
|
|
73
103
|
interface IConvertHalfHalfToOrderItem {
|
|
74
104
|
halfHalfItem: IWorkableHalfHalfSetup<IItem>;
|
|
75
105
|
selectedHalfHalfItems: (IOrderItem | null)[];
|
|
@@ -117,6 +117,29 @@ function divideItemPriceBySegments(item, segments) {
|
|
|
117
117
|
};
|
|
118
118
|
return result;
|
|
119
119
|
}
|
|
120
|
+
const zeroModifierPrices = (modifiers) => {
|
|
121
|
+
if (modifiers == null || modifiers.length === 0)
|
|
122
|
+
return modifiers;
|
|
123
|
+
return modifiers.map((modifier) => ({
|
|
124
|
+
...modifier,
|
|
125
|
+
options: (modifier.options ?? []).map((option) => ({
|
|
126
|
+
...option,
|
|
127
|
+
price: null,
|
|
128
|
+
modifiers: zeroModifierPrices(option.modifiers),
|
|
129
|
+
})),
|
|
130
|
+
}));
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* A half-half nested in a special is priced ONLY by the special's item-level
|
|
134
|
+
* upsell (split per segment): every other price inside the segment item — its
|
|
135
|
+
* own price and the prices of its modifier options at any depth — is IGNORED
|
|
136
|
+
* (zeroed), so nothing else can leak into the deal. Options stay selectable;
|
|
137
|
+
* the special's own excluded/exclusive ref rules are applied downstream by
|
|
138
|
+
* `convertSpecialToItem` (`applyModifierSpecialRefRules`).
|
|
139
|
+
*/
|
|
140
|
+
function zeroItemPrices(item) {
|
|
141
|
+
return { ...item, price: null, modifiers: zeroModifierPrices(item.modifiers) };
|
|
142
|
+
}
|
|
120
143
|
function isRequiredModifierGroup(modifier) {
|
|
121
144
|
return ((modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
122
145
|
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0));
|
|
@@ -304,7 +327,6 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
304
327
|
}
|
|
305
328
|
return halfhalfMenu;
|
|
306
329
|
}
|
|
307
|
-
// ====================================================================================================
|
|
308
330
|
/**
|
|
309
331
|
* Converts an IHalfHalfSetup into an IItem so it can flow through the standard
|
|
310
332
|
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
@@ -315,6 +337,12 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
315
337
|
* Required (price-defining) modifier option prices are divided with the base
|
|
316
338
|
* (e.g. Pizza Size 1150 -> 575); optional upsell modifier prices stay full.
|
|
317
339
|
*
|
|
340
|
+
* When the half-half is nested in a special (pass `specialItems`), the special
|
|
341
|
+
* is the authority instead: the segment options are the special's own items
|
|
342
|
+
* (priced from their special upsell split per segment), the half-half's own
|
|
343
|
+
* item list/ref rules/per-item upsells are ignored, and only
|
|
344
|
+
* `choose_expensive_segment_price` is taken from the setup.
|
|
345
|
+
*
|
|
318
346
|
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
319
347
|
* included_platforms), no special-hours / platform-based price resolution,
|
|
320
348
|
* and NO `choose_expensive_segment_price` handling: that rule depends on
|
|
@@ -331,17 +359,23 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
331
359
|
*
|
|
332
360
|
* Returns null only when no option can be resolved from the items map.
|
|
333
361
|
*/
|
|
334
|
-
function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
|
|
362
|
+
function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
|
|
363
|
+
const isSpecialContext = options?.specialItems != null;
|
|
335
364
|
// Fields are carried through as-is (no schedule resolution here).
|
|
336
365
|
const upsell_price = halfhalfSetup.upsell_price;
|
|
337
366
|
const discount_amount = halfhalfSetup.discount_amount;
|
|
338
367
|
const is_discount_percentage = halfhalfSetup.is_discount_percentage;
|
|
339
368
|
// ── Build shared option list (segment-neutral ids) ─────────────
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
.sort((a, b) => a.sort_id - b.sort_id)
|
|
369
|
+
// In a special the segment options ARE the special's own items; the
|
|
370
|
+
// half-half's original item list is never used. Standalone uses the
|
|
371
|
+
// half-half's own list (respecting its excluded_refs).
|
|
372
|
+
const halfHalfItems = isSpecialContext
|
|
373
|
+
? [...options.specialItems].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0))
|
|
374
|
+
: [...halfhalfSetup.items]
|
|
375
|
+
// Respect excluded_refs: items whose item_id (ref) is listed are
|
|
376
|
+
// removed from the selectable list (same semantics as specials').
|
|
377
|
+
.filter((setupItem) => !halfhalfSetup.excluded_refs.includes(setupItem.item_id))
|
|
378
|
+
.sort((a, b) => a.sort_id - b.sort_id);
|
|
345
379
|
// Aggregate the union of keywords/caveats/dietary_preferences across all
|
|
346
380
|
// constituent items so the half-half shows them too.
|
|
347
381
|
const allKeywords = [];
|
|
@@ -356,32 +390,39 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
|
|
|
356
390
|
allKeywords.push(...(catalogItem.keywords ?? []));
|
|
357
391
|
allCaveats.push(...(catalogItem.caveats ?? []));
|
|
358
392
|
allDietaryPreferences.push(...(catalogItem.dietary_preferences ?? []));
|
|
359
|
-
//
|
|
360
|
-
//
|
|
361
|
-
//
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
393
|
+
// Inside a special the segment item carries NO pricing of its own: its
|
|
394
|
+
// base price and its modifier option prices (at any depth) are zeroed so
|
|
395
|
+
// only the special's item-level upsell (applied below, split per segment)
|
|
396
|
+
// can charge. Standalone keeps the item's modifiers (own ref rules first,
|
|
397
|
+
// then the price structure divided by the number of segments).
|
|
398
|
+
const segmentItem = isSpecialContext
|
|
399
|
+
? zeroItemPrices(catalogItem)
|
|
400
|
+
: divideItemPriceBySegments({
|
|
401
|
+
...catalogItem,
|
|
402
|
+
modifiers: (0, specials_helpers_1.applyModifierSpecialRefRules)(catalogItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs),
|
|
403
|
+
}, halfhalfSetup.segments.length);
|
|
366
404
|
optionEntries.push({
|
|
367
405
|
catalogItem,
|
|
368
406
|
segmentItem,
|
|
369
407
|
itemUpsell: halfHalfItem.upsell_price,
|
|
370
|
-
sortId: halfHalfItem.sort_id,
|
|
408
|
+
sortId: halfHalfItem.sort_id ?? 0,
|
|
371
409
|
});
|
|
372
410
|
}
|
|
373
411
|
const baseOptions = [];
|
|
374
412
|
for (const entry of optionEntries) {
|
|
375
413
|
const { catalogItem, segmentItem, itemUpsell, sortId } = entry;
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
380
|
-
|
|
414
|
+
// In a special the special's item-level upsell is the only price source:
|
|
415
|
+
// segment option = special upsell / segments (no item price, no own
|
|
416
|
+
// per-item upsell; no special upsell => free). Standalone keeps the item
|
|
417
|
+
// price/segments + the half-half's own per-item upsell.
|
|
418
|
+
let optionPrice = isSpecialContext
|
|
419
|
+
? (0, platform_num_1.convertPriceObjToSegmentPrice)(itemUpsell ?? null, halfhalfSetup.segments.length)
|
|
420
|
+
: segmentItem.price;
|
|
421
|
+
if (!isSpecialContext && itemUpsell != null) {
|
|
381
422
|
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, itemUpsell);
|
|
382
423
|
}
|
|
383
|
-
// exclusive_refs: this option becomes free (price 0).
|
|
384
|
-
if (halfhalfSetup.exclusive_refs.includes(catalogItem._id)) {
|
|
424
|
+
// exclusive_refs (own rules only): this option becomes free (price 0).
|
|
425
|
+
if (!isSpecialContext && halfhalfSetup.exclusive_refs.includes(catalogItem._id)) {
|
|
385
426
|
optionPrice = null;
|
|
386
427
|
}
|
|
387
428
|
baseOptions.push({
|
|
@@ -399,8 +440,10 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
|
|
|
399
440
|
// so platform availability can be applied by the filter layer downstream.
|
|
400
441
|
excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
|
|
401
442
|
// Carry the source item's special hours so the filter layer can apply
|
|
402
|
-
// schedule availability (pure mapping, no resolution here).
|
|
403
|
-
|
|
443
|
+
// schedule availability (pure mapping, no resolution here). Inside a
|
|
444
|
+
// special the segment item's schedule is fully ignored — the special
|
|
445
|
+
// owns availability/pricing.
|
|
446
|
+
item_modifier_option_special_hours: isSpecialContext ? null : catalogItem.item_special_hours,
|
|
404
447
|
price: optionPrice,
|
|
405
448
|
modifiers: segmentItem.modifiers,
|
|
406
449
|
});
|
|
@@ -446,17 +489,26 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
|
|
|
446
489
|
sold_out: halfhalfSetup.sold_out,
|
|
447
490
|
sort_id: 0,
|
|
448
491
|
// half-half-level upsell is added ONCE at item level; segment options
|
|
449
|
-
// carry the per-segment base (+ own item upsell) prices.
|
|
450
|
-
price
|
|
451
|
-
|
|
452
|
-
|
|
492
|
+
// carry the per-segment base (+ own item upsell) prices. Inside a special
|
|
493
|
+
// the half-half's own setup upsell is IGNORED — the item price is the
|
|
494
|
+
// special's upsell for the half-half option itself (null = free).
|
|
495
|
+
price: isSpecialContext ? (options?.specialHalfHalfUpsell ?? null) : upsell_price,
|
|
496
|
+
// Inside a special the half-half's own discount does NOT apply — the
|
|
497
|
+
// deal's pricing is the only authority (the special's upsell for the
|
|
498
|
+
// half-half is the item price; standalone keeps the setup discount).
|
|
499
|
+
discount_amount: isSpecialContext ? null : discount_amount,
|
|
500
|
+
is_discount_percentage: isSpecialContext ? false : is_discount_percentage,
|
|
453
501
|
caveats: Array.from(new Set(allCaveats)),
|
|
454
502
|
dietary_preferences: Array.from(new Set(allDietaryPreferences)),
|
|
455
503
|
tax_rate: null,
|
|
456
504
|
keywords: Array.from(new Set(allKeywords)),
|
|
457
505
|
image_url: halfhalfSetup.image_url,
|
|
458
506
|
ingredients: null,
|
|
459
|
-
|
|
507
|
+
// Inside a special the half-half's own schedule is ignored — the deal's
|
|
508
|
+
// schedule governs the half-half option (availability is checked at open
|
|
509
|
+
// via isSetupApplicable). Standalone keeps its schedule for the filter
|
|
510
|
+
// layer.
|
|
511
|
+
item_special_hours: isSpecialContext ? null : halfhalfSetup.item_special_hours,
|
|
460
512
|
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
461
513
|
is_featured: false,
|
|
462
514
|
featured_sort_id: 0,
|
|
@@ -94,5 +94,5 @@ export declare function deStructureSpecialOrderItem(orderItem: IOrderItem, speci
|
|
|
94
94
|
*
|
|
95
95
|
* Returns null only when no option can be resolved from the items map.
|
|
96
96
|
*/
|
|
97
|
-
export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>, halfhalfSetups
|
|
97
|
+
export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>, halfhalfSetups: Record<string, IHalfHalfSetup>): IItem | null;
|
|
98
98
|
export {};
|
|
@@ -447,7 +447,33 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
447
447
|
if (catalogItem == null && halfhalfSetups != null) {
|
|
448
448
|
const halfhalfSetup = halfhalfSetups[specialItem.item_id];
|
|
449
449
|
if (halfhalfSetup != null) {
|
|
450
|
-
|
|
450
|
+
// The special's own (non-half-half) items are the ONLY segment
|
|
451
|
+
// options of a half-half nested here — the half-half's original
|
|
452
|
+
// item list is ignored. Pricing comes from each item's special
|
|
453
|
+
// upsell (split per segment), so an upsell defined once in the
|
|
454
|
+
// special applies whether the item is picked directly or inside a
|
|
455
|
+
// half-half. Only `choose_expensive_segment_price` is taken from
|
|
456
|
+
// the setup.
|
|
457
|
+
const specialItems = [];
|
|
458
|
+
for (let m = 0; m < modifierSpecial.items.length; m++) {
|
|
459
|
+
const sibling = modifierSpecial.items[m];
|
|
460
|
+
if (sibling.item_id === specialItem.item_id)
|
|
461
|
+
continue;
|
|
462
|
+
const siblingIsHalfHalf = itemsMap[sibling.item_id] == null && halfhalfSetups?.[sibling.item_id] != null;
|
|
463
|
+
if (!siblingIsHalfHalf) {
|
|
464
|
+
specialItems.push({
|
|
465
|
+
item_id: sibling.item_id,
|
|
466
|
+
upsell_price: sibling.upsell_price ?? null,
|
|
467
|
+
sort_id: sibling.sort_id,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const halfhalfItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(halfhalfSetup, itemsMap, {
|
|
472
|
+
specialItems,
|
|
473
|
+
// The half-half option's own price inside the special is the
|
|
474
|
+
// special's upsell for the half-half (NOT the setup's own).
|
|
475
|
+
specialHalfHalfUpsell: specialItem.upsell_price ?? null,
|
|
476
|
+
});
|
|
451
477
|
if (halfhalfItem != null) {
|
|
452
478
|
catalogItem = halfhalfItem;
|
|
453
479
|
isHalfHalfOption = true;
|
|
@@ -465,9 +491,20 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
465
491
|
// (num_free_options in the drawer handles free-vs-paid)
|
|
466
492
|
// no special price → use item's own price
|
|
467
493
|
// upsell_price is always merged on top
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
494
|
+
// For a half-half option the converted item's price ALREADY is the
|
|
495
|
+
// special's upsell for the half-half (specialHalfHalfUpsell), so the
|
|
496
|
+
// upsell must not be merged again — a pass-through special (no special
|
|
497
|
+
// price) would otherwise double it. Regular items keep the standard
|
|
498
|
+
// rule: option = (special price ? null : item price) + special upsell.
|
|
499
|
+
let optionPrice;
|
|
500
|
+
if (isHalfHalfOption) {
|
|
501
|
+
optionPrice = special.price != null ? (specialItem.upsell_price ?? null) : catalogItem.price;
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
optionPrice = special.price != null ? null : catalogItem.price;
|
|
505
|
+
if (specialItem.upsell_price != null) {
|
|
506
|
+
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, specialItem.upsell_price);
|
|
507
|
+
}
|
|
471
508
|
}
|
|
472
509
|
// Apply the modifier-special group's ref rules to the source item's own
|
|
473
510
|
// modifiers (excluded_refs removes, exclusive_refs zeroes price).
|
|
@@ -492,8 +529,19 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
492
529
|
// so platform availability can be applied by the filter layer downstream.
|
|
493
530
|
excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
|
|
494
531
|
// Carry the source item's special hours so the filter layer can apply
|
|
495
|
-
// schedule
|
|
496
|
-
|
|
532
|
+
// schedule AVAILABILITY (pure mapping, no resolution here). Item
|
|
533
|
+
// schedule-level PRICING/DISCOUNTS are ignored inside a special: they
|
|
534
|
+
// are stripped here so availability (days/time/date) is honored but
|
|
535
|
+
// the schedule can never re-price the option. `omit_items_schedule`
|
|
536
|
+
// drops the schedule entirely (availability too).
|
|
537
|
+
item_modifier_option_special_hours: modifierSpecial.omit_items_schedule
|
|
538
|
+
? null
|
|
539
|
+
: (catalogItem.item_special_hours ?? []).map((hour) => ({
|
|
540
|
+
...hour,
|
|
541
|
+
price: null,
|
|
542
|
+
discount_amount: null,
|
|
543
|
+
is_discount_percentage: false,
|
|
544
|
+
})),
|
|
497
545
|
price: optionPrice,
|
|
498
546
|
modifiers: itemModifiers,
|
|
499
547
|
});
|
|
@@ -145,11 +145,12 @@ describe('convertSpecialToItem with half-half options', () => {
|
|
|
145
145
|
expect(halfHalfOption.name).toBe('Half/Half Pizza Large');
|
|
146
146
|
expect(halfHalfOption.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
|
|
147
147
|
expect(halfHalfOption.choose_expensive_segment_price).toBe(true);
|
|
148
|
-
// Segment modifiers (one single-select per segment)
|
|
149
|
-
//
|
|
148
|
+
// Segment modifiers (one single-select per segment). The segment options
|
|
149
|
+
// are the SPECIAL's own items (non-half-half entries of the group), NOT
|
|
150
|
+
// the half-half's original items — only milan is listed in the special.
|
|
150
151
|
const segmentModifiers = halfHalfOption.modifiers ?? [];
|
|
151
152
|
expect(segmentModifiers).toHaveLength(2);
|
|
152
|
-
expect(segmentModifiers[0].options).
|
|
153
|
+
expect(segmentModifiers[0].options.map((o) => o._id)).toEqual(['milan']);
|
|
153
154
|
expect(segmentModifiers[0].options[0].ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
|
|
154
155
|
const drinkModifier = item.modifiers[1];
|
|
155
156
|
expect(drinkModifier.name).toBe('Drink');
|
|
@@ -181,6 +182,263 @@ describe('convertSpecialToItem with half-half options', () => {
|
|
|
181
182
|
expect((0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap)).toBeNull();
|
|
182
183
|
});
|
|
183
184
|
});
|
|
185
|
+
describe('nested half-half pricing inside a special (special is pricing authority)', () => {
|
|
186
|
+
it('prices segment options from the special item upsell only', () => {
|
|
187
|
+
const itemsMap = {
|
|
188
|
+
milan: makeItem('milan'), // catalog price 1000 — must be ignored
|
|
189
|
+
torent: makeItem('torent'), // catalog price 1000 — must be ignored
|
|
190
|
+
cola: makeItem('cola'),
|
|
191
|
+
};
|
|
192
|
+
const halfhalfMap = {
|
|
193
|
+
'halfhalf-1': makeHalfHalfSetup({
|
|
194
|
+
// Own per-item upsell + own excluded ref — BOTH must be ignored
|
|
195
|
+
// inside a special (only the special's item upsell counts).
|
|
196
|
+
items: [
|
|
197
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: { BASE_PRICE: 50 } },
|
|
198
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 50 } },
|
|
199
|
+
],
|
|
200
|
+
excluded_refs: ['milan'],
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
const special = makeSpecialWithModifier({
|
|
204
|
+
modifier_specials: [
|
|
205
|
+
{
|
|
206
|
+
_id: 'mod-pizza',
|
|
207
|
+
name: 'First Pizza',
|
|
208
|
+
sort_id: 1,
|
|
209
|
+
quantity: 1,
|
|
210
|
+
num_free_items: 0,
|
|
211
|
+
excluded_refs: [],
|
|
212
|
+
exclusive_refs: [],
|
|
213
|
+
omit_items_schedule: false,
|
|
214
|
+
items: [
|
|
215
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null }, // basic -> free
|
|
216
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } }, // premium +$2
|
|
217
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } }, // half-half +$1
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap);
|
|
223
|
+
expect(item).not.toBeNull();
|
|
224
|
+
const pizzaModifier = item.modifiers[0];
|
|
225
|
+
const halfHalfOption = pizzaModifier.options.find((option) => option._id === 'halfhalf-1');
|
|
226
|
+
expect(halfHalfOption).toBeDefined();
|
|
227
|
+
// Half-half option keeps the special's upsell only.
|
|
228
|
+
expect(halfHalfOption.price).toEqual({ BASE_PRICE: 100 });
|
|
229
|
+
expect(halfHalfOption.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
|
|
230
|
+
expect(halfHalfOption.choose_expensive_segment_price).toBe(true);
|
|
231
|
+
const segmentModifiers = halfHalfOption.modifiers ?? [];
|
|
232
|
+
expect(segmentModifiers).toHaveLength(2);
|
|
233
|
+
const segmentOptions = segmentModifiers[0].options;
|
|
234
|
+
// milan: own excluded_refs ignored (still selectable), no special upsell -> free.
|
|
235
|
+
const milanOption = segmentOptions.find((option) => option._id === 'milan');
|
|
236
|
+
expect(milanOption).toBeDefined();
|
|
237
|
+
expect(milanOption.price).toBeNull();
|
|
238
|
+
// torent: own per-item upsell ignored; special +$2 / 2 segments = +$1.
|
|
239
|
+
const torentOption = segmentOptions.find((option) => option._id === 'torent');
|
|
240
|
+
expect(torentOption).toBeDefined();
|
|
241
|
+
expect(torentOption.price).toEqual({ BASE_PRICE: 100 });
|
|
242
|
+
});
|
|
243
|
+
it('lets the special exclusive_refs free a segment option price', () => {
|
|
244
|
+
const itemsMap = {
|
|
245
|
+
milan: makeItem('milan'),
|
|
246
|
+
torent: makeItem('torent'),
|
|
247
|
+
cola: makeItem('cola'),
|
|
248
|
+
};
|
|
249
|
+
const halfhalfMap = {
|
|
250
|
+
'halfhalf-1': makeHalfHalfSetup(),
|
|
251
|
+
};
|
|
252
|
+
const special = makeSpecialWithModifier({
|
|
253
|
+
modifier_specials: [
|
|
254
|
+
{
|
|
255
|
+
_id: 'mod-pizza',
|
|
256
|
+
name: 'First Pizza',
|
|
257
|
+
sort_id: 1,
|
|
258
|
+
quantity: 1,
|
|
259
|
+
num_free_items: 0,
|
|
260
|
+
excluded_refs: [],
|
|
261
|
+
exclusive_refs: ['torent'], // special ref rule -> segment option free
|
|
262
|
+
omit_items_schedule: false,
|
|
263
|
+
items: [
|
|
264
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
265
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
266
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap);
|
|
272
|
+
expect(item).not.toBeNull();
|
|
273
|
+
const pizzaModifier = item.modifiers[0];
|
|
274
|
+
const halfHalfOption = pizzaModifier.options.find((option) => option._id === 'halfhalf-1');
|
|
275
|
+
expect(halfHalfOption).toBeDefined();
|
|
276
|
+
const segmentModifiers = halfHalfOption.modifiers ?? [];
|
|
277
|
+
const segmentOptions = segmentModifiers[0].options;
|
|
278
|
+
const torentOption = segmentOptions.find((option) => option._id === 'torent');
|
|
279
|
+
// Special's exclusive_refs zero the segment option price (free).
|
|
280
|
+
expect(torentOption.price).toBeNull();
|
|
281
|
+
});
|
|
282
|
+
it('ignores segment item modifier prices inside a special (e.g. Pizza Size +575)', () => {
|
|
283
|
+
const itemsMap = {
|
|
284
|
+
milan: makeItem('milan', {
|
|
285
|
+
// Segment item with its own required, priced modifier (real-world shape).
|
|
286
|
+
modifiers: [
|
|
287
|
+
{
|
|
288
|
+
_id: 'size-mod',
|
|
289
|
+
ref: 'size-mod',
|
|
290
|
+
name: 'Pizza Size',
|
|
291
|
+
description: 'Choose your size',
|
|
292
|
+
active: true,
|
|
293
|
+
sold_out: [],
|
|
294
|
+
sort_id: 1,
|
|
295
|
+
min_num_options: 1,
|
|
296
|
+
max_num_options: 1,
|
|
297
|
+
options: [
|
|
298
|
+
{
|
|
299
|
+
_id: 'large-13',
|
|
300
|
+
ref: 'large-13',
|
|
301
|
+
name: 'Large 13"',
|
|
302
|
+
active: true,
|
|
303
|
+
sold_out: [],
|
|
304
|
+
sort_id: 1,
|
|
305
|
+
excluded_platforms: [],
|
|
306
|
+
price: { BASE_PRICE: 575 },
|
|
307
|
+
modifiers: null,
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
}),
|
|
313
|
+
torent: makeItem('torent'),
|
|
314
|
+
};
|
|
315
|
+
const halfhalfMap = {
|
|
316
|
+
'halfhalf-1': makeHalfHalfSetup({
|
|
317
|
+
items: [
|
|
318
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: { BASE_PRICE: 50 } },
|
|
319
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
320
|
+
],
|
|
321
|
+
}),
|
|
322
|
+
};
|
|
323
|
+
const special = makeSpecialWithModifier({
|
|
324
|
+
modifier_specials: [
|
|
325
|
+
{
|
|
326
|
+
_id: 'mod-pizza',
|
|
327
|
+
name: 'First Pizza',
|
|
328
|
+
sort_id: 1,
|
|
329
|
+
quantity: 1,
|
|
330
|
+
num_free_items: 0,
|
|
331
|
+
excluded_refs: [],
|
|
332
|
+
exclusive_refs: [],
|
|
333
|
+
omit_items_schedule: false,
|
|
334
|
+
items: [
|
|
335
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null }, // no upsell -> free
|
|
336
|
+
{ item_id: 'halfhalf-1', sort_id: 2, upsell_price: { BASE_PRICE: 100 } },
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
});
|
|
341
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap);
|
|
342
|
+
expect(item).not.toBeNull();
|
|
343
|
+
const halfHalfOption = item.modifiers[0].options.find((option) => option._id === 'halfhalf-1');
|
|
344
|
+
expect(halfHalfOption).toBeDefined();
|
|
345
|
+
const segmentModifiers = halfHalfOption.modifiers ?? [];
|
|
346
|
+
const milanOption = segmentModifiers[0].options.find((option) => option._id === 'milan');
|
|
347
|
+
expect(milanOption).toBeDefined();
|
|
348
|
+
// No special upsell for milan -> segment option free (own upsell ignored).
|
|
349
|
+
expect(milanOption.price).toBeNull();
|
|
350
|
+
// The segment item's own modifier (Pizza Size +575) must NOT charge.
|
|
351
|
+
const sizeModifier = (milanOption.modifiers ?? [])[0];
|
|
352
|
+
expect(sizeModifier.name).toBe('Pizza Size');
|
|
353
|
+
expect(sizeModifier.options[0].price).toBeNull();
|
|
354
|
+
// Still selectable (structure kept).
|
|
355
|
+
expect(sizeModifier.options[0].name).toBe('Large 13"');
|
|
356
|
+
});
|
|
357
|
+
it('never leaks original half-half item or modifier prices into the selection', () => {
|
|
358
|
+
// Reproduces the reported bug: option level shows no price, but selecting
|
|
359
|
+
// the half-half would previously add prices from the ORIGINAL items.
|
|
360
|
+
const itemsMap = {
|
|
361
|
+
milan: makeItem('milan', {
|
|
362
|
+
modifiers: [
|
|
363
|
+
{
|
|
364
|
+
_id: 'size-mod',
|
|
365
|
+
ref: 'size-mod',
|
|
366
|
+
name: 'Pizza Size',
|
|
367
|
+
description: 'Choose your size',
|
|
368
|
+
active: true,
|
|
369
|
+
sold_out: [],
|
|
370
|
+
sort_id: 1,
|
|
371
|
+
min_num_options: 1,
|
|
372
|
+
max_num_options: 1,
|
|
373
|
+
options: [
|
|
374
|
+
{
|
|
375
|
+
_id: 'large-13',
|
|
376
|
+
ref: 'large-13',
|
|
377
|
+
name: 'Large 13"',
|
|
378
|
+
active: true,
|
|
379
|
+
sold_out: [],
|
|
380
|
+
sort_id: 1,
|
|
381
|
+
excluded_platforms: [],
|
|
382
|
+
price: { BASE_PRICE: 575 },
|
|
383
|
+
modifiers: null,
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
}),
|
|
389
|
+
torent: makeItem('torent'),
|
|
390
|
+
};
|
|
391
|
+
const halfhalfMap = {
|
|
392
|
+
'halfhalf-1': makeHalfHalfSetup({
|
|
393
|
+
items: [
|
|
394
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: { BASE_PRICE: 50 } },
|
|
395
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 50 } },
|
|
396
|
+
],
|
|
397
|
+
}),
|
|
398
|
+
};
|
|
399
|
+
const special = makeSpecialWithModifier({
|
|
400
|
+
modifier_specials: [
|
|
401
|
+
{
|
|
402
|
+
_id: 'mod-pizza',
|
|
403
|
+
name: 'First Pizza',
|
|
404
|
+
sort_id: 1,
|
|
405
|
+
quantity: 1,
|
|
406
|
+
num_free_items: 0,
|
|
407
|
+
excluded_refs: [],
|
|
408
|
+
exclusive_refs: [],
|
|
409
|
+
omit_items_schedule: false,
|
|
410
|
+
items: [
|
|
411
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
412
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
413
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
});
|
|
418
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap);
|
|
419
|
+
expect(item).not.toBeNull();
|
|
420
|
+
const halfHalfOption = item.modifiers[0].options.find((option) => option._id === 'halfhalf-1');
|
|
421
|
+
expect(halfHalfOption).toBeDefined();
|
|
422
|
+
expect(halfHalfOption.price).toEqual({ BASE_PRICE: 100 });
|
|
423
|
+
// Collect every price inside the half-half option at ANY depth (segment
|
|
424
|
+
// groups -> options -> nested modifiers -> options ...).
|
|
425
|
+
const collectPrices = (modifiers, acc = []) => {
|
|
426
|
+
for (const modifier of modifiers ?? []) {
|
|
427
|
+
for (const option of modifier.options) {
|
|
428
|
+
acc.push(option.price);
|
|
429
|
+
collectPrices(option.modifiers, acc);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return acc;
|
|
433
|
+
};
|
|
434
|
+
const allPrices = collectPrices(halfHalfOption.modifiers);
|
|
435
|
+
const priced = allPrices.filter((price) => price != null);
|
|
436
|
+
// The ONLY prices allowed are the special's upsell split per segment:
|
|
437
|
+
// both segments' Torent (premium) = $2 / 2 = 100. NO 575 (Pizza Size),
|
|
438
|
+
// NO 50 (half-half own upsell), NO 1000/2 (item prices) anywhere.
|
|
439
|
+
expect(priced).toEqual([{ BASE_PRICE: 100 }, { BASE_PRICE: 100 }]);
|
|
440
|
+
});
|
|
441
|
+
});
|
|
184
442
|
describe('convertSpecialItemToOrderItem with ref_type', () => {
|
|
185
443
|
it('marks option ref_type for item and half-half selections', () => {
|
|
186
444
|
const workableSpecial = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|