@managesome/eposmatic-toolkit 0.2.713 → 0.2.714

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.
@@ -43,6 +43,23 @@ 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
+ }
46
63
  /**
47
64
  * Converts an IHalfHalfSetup into an IItem so it can flow through the standard
48
65
  * catalog → drawer → cart pipeline just like a regular catalog item.
@@ -53,6 +70,12 @@ export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends II
53
70
  * Required (price-defining) modifier option prices are divided with the base
54
71
  * (e.g. Pizza Size 1150 -> 575); optional upsell modifier prices stay full.
55
72
  *
73
+ * When the half-half is nested in a special (pass `specialItems`), the special
74
+ * is the authority instead: the segment options are the special's own items
75
+ * (priced from their special upsell split per segment), the half-half's own
76
+ * item list/ref rules/per-item upsells are ignored, and only
77
+ * `choose_expensive_segment_price` is taken from the setup.
78
+ *
56
79
  * PURE CONVERSION ONLY — no availability filtering (active / tenants /
57
80
  * included_platforms), no special-hours / platform-based price resolution,
58
81
  * and NO `choose_expensive_segment_price` handling: that rule depends on
@@ -69,7 +92,7 @@ export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends II
69
92
  *
70
93
  * Returns null only when no option can be resolved from the items map.
71
94
  */
72
- export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>): IItem | null;
95
+ export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>, options?: IConvertHalfHalfToItemOptions): IItem | null;
73
96
  interface IConvertHalfHalfToOrderItem {
74
97
  halfHalfItem: IWorkableHalfHalfSetup<IItem>;
75
98
  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
- const halfHalfItems = [...halfhalfSetup.items]
341
- // Respect excluded_refs: items whose item_id (ref) is listed are removed
342
- // from the selectable list (same semantics as specials' excluded_refs).
343
- .filter((setupItem) => !halfhalfSetup.excluded_refs.includes(setupItem.item_id))
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
- // Ref rules first (excluded/exclusive), then divide the price structure
360
- // by the number of segments (required/price-defining modifier prices are
361
- // divided; optional upsell modifier prices stay full).
362
- const segmentItem = divideItemPriceBySegments({
363
- ...catalogItem,
364
- modifiers: (0, specials_helpers_1.applyModifierSpecialRefRules)(catalogItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs),
365
- }, halfhalfSetup.segments.length);
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
- // Option price = (item's original price / segments) + this item's own
377
- // upsell (added on top). The half-half upsell is a ONE-TIME addition on
378
- // the item price, not merged per segment.
379
- let optionPrice = segmentItem.price;
380
- if (itemUpsell != null) {
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({
@@ -447,7 +447,30 @@ 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
- const halfhalfItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(halfhalfSetup, itemsMap);
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
+ });
451
474
  if (halfhalfItem != null) {
452
475
  catalogItem = halfhalfItem;
453
476
  isHalfHalfOption = true;
@@ -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); their options are
149
- // real items -> ITEM.
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).toHaveLength(2);
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 {};