@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
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const halfhalf_setup_helpers_1 = require("../helpers/utils/halfhalf-setup-helpers");
|
|
5
|
+
const order_engine_1 = require("../helpers/utils/order-engine");
|
|
6
|
+
const specials_helpers_1 = require("../helpers/utils/specials-helpers");
|
|
7
|
+
const TENANT_ID = 'tenant-1';
|
|
8
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Fixtures
|
|
11
|
+
// ============================================================================
|
|
12
|
+
function makeItem(id, overrides = {}) {
|
|
13
|
+
return {
|
|
14
|
+
_id: id,
|
|
15
|
+
brand_id: 'brand-1',
|
|
16
|
+
tenants: ['tenant-1'],
|
|
17
|
+
category_id: 'pizza-cat',
|
|
18
|
+
included_platforms: [PLATFORM],
|
|
19
|
+
name: `Item ${id}`,
|
|
20
|
+
hide_name: false,
|
|
21
|
+
description: '',
|
|
22
|
+
active: true,
|
|
23
|
+
sold_out: [],
|
|
24
|
+
sort_id: 1,
|
|
25
|
+
price: { BASE_PRICE: 1000 },
|
|
26
|
+
discount_amount: null,
|
|
27
|
+
is_discount_percentage: false,
|
|
28
|
+
tax_rate: null,
|
|
29
|
+
keywords: [],
|
|
30
|
+
caveats: [],
|
|
31
|
+
dietary_preferences: [],
|
|
32
|
+
image_url: `https://example.com/${id}.jpg`,
|
|
33
|
+
ingredients: null,
|
|
34
|
+
item_special_hours: null,
|
|
35
|
+
display_price: null,
|
|
36
|
+
show_starting_from: false,
|
|
37
|
+
use_source_ingredients: false,
|
|
38
|
+
is_featured: false,
|
|
39
|
+
featured_sort_id: 0,
|
|
40
|
+
createdAt: new Date('2024-01-01'),
|
|
41
|
+
updatedAt: new Date('2024-01-02'),
|
|
42
|
+
modifiers: null,
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function makeOption(id, overrides = {}) {
|
|
47
|
+
return {
|
|
48
|
+
_id: id,
|
|
49
|
+
ref: id,
|
|
50
|
+
name: `Option ${id}`,
|
|
51
|
+
active: true,
|
|
52
|
+
sold_out: [],
|
|
53
|
+
sort_id: 1,
|
|
54
|
+
excluded_platforms: [],
|
|
55
|
+
price: null,
|
|
56
|
+
modifiers: null,
|
|
57
|
+
...overrides,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function makeModifier(id, options, overrides = {}) {
|
|
61
|
+
return {
|
|
62
|
+
_id: id,
|
|
63
|
+
ref: id,
|
|
64
|
+
name: `Modifier ${id}`,
|
|
65
|
+
description: '',
|
|
66
|
+
active: true,
|
|
67
|
+
sold_out: [],
|
|
68
|
+
sort_id: 1,
|
|
69
|
+
options,
|
|
70
|
+
...overrides,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Standard required "Pizza Size" group (1150 / 500), plus optional upsell. */
|
|
74
|
+
function makePizzaSizeAndExtra() {
|
|
75
|
+
return [
|
|
76
|
+
makeModifier('size-mod', [
|
|
77
|
+
makeOption('large-13', { name: 'Large 13"', price: { BASE_PRICE: 1150 } }),
|
|
78
|
+
makeOption('small-11', { name: 'Small 11"', price: { BASE_PRICE: 500 } }),
|
|
79
|
+
], { name: 'Pizza Size', min_num_options: 1, max_num_options: 1 }),
|
|
80
|
+
makeModifier('extra-mod', [makeOption('cheese', { name: 'Extra Cheese', price: { BASE_PRICE: 200 } })], {
|
|
81
|
+
name: 'Extras',
|
|
82
|
+
max_num_options: 1,
|
|
83
|
+
}),
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
function makeHalfHalfSetup(overrides = {}) {
|
|
87
|
+
return {
|
|
88
|
+
_id: 'halfhalf-1',
|
|
89
|
+
brand_id: 'brand-1',
|
|
90
|
+
tenants: ['tenant-1'],
|
|
91
|
+
category_id: 'pizza-cat',
|
|
92
|
+
included_platforms: [PLATFORM],
|
|
93
|
+
name: 'Half/Half Pizza Large',
|
|
94
|
+
description: 'Two halves',
|
|
95
|
+
active: true,
|
|
96
|
+
sold_out: [],
|
|
97
|
+
image_url: 'https://example.com/halfhalf.jpg',
|
|
98
|
+
upsell_price: { BASE_PRICE: 300 },
|
|
99
|
+
discount_amount: null,
|
|
100
|
+
is_discount_percentage: false,
|
|
101
|
+
choose_expensive_segment_price: true,
|
|
102
|
+
segments: [
|
|
103
|
+
{ _id: 'seg-1', name: 'First Half', sort_id: 1 },
|
|
104
|
+
{ _id: 'seg-2', name: 'Second Half', sort_id: 2 },
|
|
105
|
+
],
|
|
106
|
+
items: [
|
|
107
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: { BASE_PRICE: 50 } },
|
|
108
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 60 } },
|
|
109
|
+
],
|
|
110
|
+
exclusive_refs: [],
|
|
111
|
+
excluded_refs: [],
|
|
112
|
+
item_special_hours: null,
|
|
113
|
+
createdAt: new Date('2024-01-01'),
|
|
114
|
+
updatedAt: new Date('2024-01-02'),
|
|
115
|
+
...overrides,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function makeSpecial(overrides = {}) {
|
|
119
|
+
return {
|
|
120
|
+
_id: 'special-1',
|
|
121
|
+
brand_id: 'brand-1',
|
|
122
|
+
tenants: ['tenant-1'],
|
|
123
|
+
category_id: 'combo-cat',
|
|
124
|
+
included_platforms: [PLATFORM],
|
|
125
|
+
name: 'Buy 1 Pizza Get 1 Free',
|
|
126
|
+
description: 'Deal',
|
|
127
|
+
active: true,
|
|
128
|
+
sold_out: [],
|
|
129
|
+
sort_id: 1,
|
|
130
|
+
image_url: 'https://example.com/special.jpg',
|
|
131
|
+
price: { BASE_PRICE: 1500 },
|
|
132
|
+
discount_amount: null,
|
|
133
|
+
is_discount_percentage: false,
|
|
134
|
+
display_price: null,
|
|
135
|
+
show_starting_from: false,
|
|
136
|
+
item_special_hours: null,
|
|
137
|
+
modifier_specials: [
|
|
138
|
+
{
|
|
139
|
+
_id: 'mod-pizza',
|
|
140
|
+
name: 'First Pizza',
|
|
141
|
+
sort_id: 1,
|
|
142
|
+
quantity: 1,
|
|
143
|
+
num_free_items: 0,
|
|
144
|
+
excluded_refs: [],
|
|
145
|
+
exclusive_refs: [],
|
|
146
|
+
omit_items_schedule: false,
|
|
147
|
+
items: [
|
|
148
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
149
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
createdAt: new Date('2024-01-01'),
|
|
154
|
+
updatedAt: new Date('2024-01-02'),
|
|
155
|
+
...overrides,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function modifySpecialItems(map, items) {
|
|
159
|
+
return {
|
|
160
|
+
...map,
|
|
161
|
+
modifier_specials: map.modifier_specials.map((group, i) => (i === 0 ? { ...group, items } : group)),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function priceOf(price) {
|
|
165
|
+
if (price == null)
|
|
166
|
+
return null;
|
|
167
|
+
const base = price.BASE_PRICE ?? 0;
|
|
168
|
+
return base;
|
|
169
|
+
}
|
|
170
|
+
/** Always-applicable schedule (all days, full day) with a distinct price. */
|
|
171
|
+
function makeSchedule(overrides = {}) {
|
|
172
|
+
return {
|
|
173
|
+
days_index: Object.values(constants_1.DAY_INDEX_ENUM),
|
|
174
|
+
disabled_outside_date_range: false,
|
|
175
|
+
start_time: 0,
|
|
176
|
+
end_time: 24 * 3600000,
|
|
177
|
+
start_date: null,
|
|
178
|
+
end_date: null,
|
|
179
|
+
price: { BASE_PRICE: 999 },
|
|
180
|
+
is_discount_percentage: false,
|
|
181
|
+
excluded_platforms: [],
|
|
182
|
+
...overrides,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// 1) Half/Half ALONE
|
|
187
|
+
// ============================================================================
|
|
188
|
+
describe('Half/Half alone — convertHalfHalfToItem pricing', () => {
|
|
189
|
+
const itemsMap = {
|
|
190
|
+
milan: makeItem('milan', { price: { BASE_PRICE: 1000 } }),
|
|
191
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1200 } }),
|
|
192
|
+
cola: makeItem('cola', { price: { BASE_PRICE: 300 } }),
|
|
193
|
+
};
|
|
194
|
+
it('item keeps setup upsell once; segment option = item price/segments + own item upsell', () => {
|
|
195
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup(), itemsMap);
|
|
196
|
+
expect(item).not.toBeNull();
|
|
197
|
+
// Setup upsell at item level (charged once, not per segment).
|
|
198
|
+
expect(priceOf(item.price)).toBe(300);
|
|
199
|
+
const segments = item.modifiers ?? [];
|
|
200
|
+
expect(segments).toHaveLength(2);
|
|
201
|
+
expect(segments[0].min_num_options).toBe(1);
|
|
202
|
+
expect(segments[0].max_num_options).toBe(1);
|
|
203
|
+
// milan: 1000/2 + 50 = 550 ; torent: 1200/2 + 60 = 660 — SAME in both segments.
|
|
204
|
+
for (const seg of segments) {
|
|
205
|
+
const milan = seg.options.find((o) => o._id === 'milan');
|
|
206
|
+
const torent = seg.options.find((o) => o._id === 'torent');
|
|
207
|
+
expect(priceOf(milan.price)).toBe(550);
|
|
208
|
+
expect(priceOf(torent.price)).toBe(660);
|
|
209
|
+
expect(milan.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
it('required (price-defining) modifier prices divide by segments; optional upsells stay full', () => {
|
|
213
|
+
const setup = makeHalfHalfSetup({
|
|
214
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
215
|
+
});
|
|
216
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(setup, {
|
|
217
|
+
...itemsMap,
|
|
218
|
+
milan: makeItem('milan', { modifiers: makePizzaSizeAndExtra() }),
|
|
219
|
+
});
|
|
220
|
+
const milan = item.modifiers[0].options.find((o) => o._id === 'milan');
|
|
221
|
+
// Required Pizza Size divided by 2: 1150 -> 575, 500 -> 250.
|
|
222
|
+
const size = milan.modifiers.find((m) => m._id === 'size-mod');
|
|
223
|
+
expect(priceOf(size.options.find((o) => o._id === 'large-13').price)).toBe(575);
|
|
224
|
+
expect(priceOf(size.options.find((o) => o._id === 'small-11').price)).toBe(250);
|
|
225
|
+
// Optional upsell stays FULL (200), not divided.
|
|
226
|
+
const extra = milan.modifiers.find((m) => m._id === 'extra-mod');
|
|
227
|
+
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBe(200);
|
|
228
|
+
});
|
|
229
|
+
it('own excluded_refs remove segment items; own exclusive_refs make them free', () => {
|
|
230
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|
|
231
|
+
excluded_refs: ['milan'],
|
|
232
|
+
exclusive_refs: ['torent'],
|
|
233
|
+
}), itemsMap);
|
|
234
|
+
const segOptions = item.modifiers[0].options;
|
|
235
|
+
expect(segOptions.map((o) => o._id)).toEqual(['torent']); // milan removed
|
|
236
|
+
const torent = segOptions[0];
|
|
237
|
+
expect(torent.price).toBeNull(); // free but still selectable
|
|
238
|
+
});
|
|
239
|
+
it('a four-segment (quarters) setup divides by 4, including own upsell', () => {
|
|
240
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|
|
241
|
+
segments: [
|
|
242
|
+
{ _id: 'q-1', name: 'Quarter 1', sort_id: 1 },
|
|
243
|
+
{ _id: 'q-2', name: 'Quarter 2', sort_id: 2 },
|
|
244
|
+
{ _id: 'q-3', name: 'Quarter 3', sort_id: 3 },
|
|
245
|
+
{ _id: 'q-4', name: 'Quarter 4', sort_id: 4 },
|
|
246
|
+
],
|
|
247
|
+
items: [{ item_id: 'torent', sort_id: 1, upsell_price: { BASE_PRICE: 40 } }],
|
|
248
|
+
}), itemsMap);
|
|
249
|
+
expect(item.modifiers).toHaveLength(4);
|
|
250
|
+
// 1200/4 + 40 = 340.
|
|
251
|
+
expect(priceOf(item.modifiers[0].options[0].price)).toBe(340);
|
|
252
|
+
});
|
|
253
|
+
it('returns null when no segment item resolves', () => {
|
|
254
|
+
expect((0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup(), { cola: itemsMap.cola })).toBeNull();
|
|
255
|
+
});
|
|
256
|
+
it('free half-half (no setup upsell, no own item upsells): item price/segments only', () => {
|
|
257
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|
|
258
|
+
upsell_price: null,
|
|
259
|
+
items: [
|
|
260
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
261
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
262
|
+
],
|
|
263
|
+
}), itemsMap);
|
|
264
|
+
expect(item.price).toBeNull();
|
|
265
|
+
expect(priceOf(item.modifiers[0].options.find((o) => o._id === 'milan').price)).toBe(500);
|
|
266
|
+
expect(priceOf(item.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(600);
|
|
267
|
+
});
|
|
268
|
+
it('choose_expensive: selection already at the expensive segment stays unchanged (all premium)', () => {
|
|
269
|
+
const halfHalfItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup(), itemsMap);
|
|
270
|
+
let engine = (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
271
|
+
item: halfHalfItem,
|
|
272
|
+
orderItem: undefined,
|
|
273
|
+
platform: PLATFORM,
|
|
274
|
+
tenantId: TENANT_ID,
|
|
275
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
276
|
+
defaultMenuId: null,
|
|
277
|
+
soldoutModifiers: [],
|
|
278
|
+
});
|
|
279
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'seg-1_torent', true, false);
|
|
280
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'seg-2_torent', true, false);
|
|
281
|
+
const result = (0, order_engine_1.applyChooseExpensiveSegmentPrice)(engine);
|
|
282
|
+
const seg1 = result.modifiers.find((m) => m._id === 'seg-1');
|
|
283
|
+
const seg2 = result.modifiers.find((m) => m._id === 'seg-2');
|
|
284
|
+
// Both halves already at the max (660): nothing to raise, nothing changes.
|
|
285
|
+
expect(seg1.options.find((o) => o._id === 'torent').price).toBe(660);
|
|
286
|
+
expect(seg2.options.find((o) => o._id === 'torent').price).toBe(660);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
// ============================================================================
|
|
290
|
+
// 2) Specials ALONE
|
|
291
|
+
// ============================================================================
|
|
292
|
+
describe('Specials alone — convertSpecialToItem pricing', () => {
|
|
293
|
+
const itemsMap = {
|
|
294
|
+
milan: makeItem('milan', { price: { BASE_PRICE: 1000 } }),
|
|
295
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1000 } }),
|
|
296
|
+
cola: makeItem('cola', { price: { BASE_PRICE: 300 } }),
|
|
297
|
+
};
|
|
298
|
+
it('one-price special: options carry ONLY the special item upsell (base free)', () => {
|
|
299
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial(), itemsMap, {});
|
|
300
|
+
const options = item.modifiers[0].options;
|
|
301
|
+
// milan no upsell -> free; torent +200; catalog price 1000 never used.
|
|
302
|
+
expect(priceOf(options.find((o) => o._id === 'milan').price)).toBeNull();
|
|
303
|
+
expect(priceOf(options.find((o) => o._id === 'torent').price)).toBe(200);
|
|
304
|
+
});
|
|
305
|
+
it('pass-through special (no special price): option = item price + upsell', () => {
|
|
306
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({ price: null }), itemsMap, {});
|
|
307
|
+
const options = item.modifiers[0].options;
|
|
308
|
+
expect(priceOf(options.find((o) => o._id === 'milan').price)).toBe(1000);
|
|
309
|
+
expect(priceOf(options.find((o) => o._id === 'torent').price)).toBe(1200);
|
|
310
|
+
});
|
|
311
|
+
it('num_free_options mirrors num_free_items', () => {
|
|
312
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({
|
|
313
|
+
modifier_specials: [
|
|
314
|
+
{
|
|
315
|
+
_id: 'mod-pizza',
|
|
316
|
+
name: 'First Pizza',
|
|
317
|
+
sort_id: 1,
|
|
318
|
+
quantity: 2,
|
|
319
|
+
num_free_items: 1,
|
|
320
|
+
excluded_refs: [],
|
|
321
|
+
exclusive_refs: [],
|
|
322
|
+
omit_items_schedule: false,
|
|
323
|
+
items: [
|
|
324
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
325
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
}), itemsMap, {});
|
|
330
|
+
const group = item.modifiers[0];
|
|
331
|
+
expect(group.min_num_options).toBe(2);
|
|
332
|
+
expect(group.max_num_options).toBe(2);
|
|
333
|
+
expect(group.num_free_options).toBe(1);
|
|
334
|
+
});
|
|
335
|
+
it('exclusive_refs zero nested item modifier prices; excluded_refs REMOVE them (recursive)', () => {
|
|
336
|
+
// Case A: exclusive_refs -> Large 13" free (still selectable).
|
|
337
|
+
const exclusive = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial({
|
|
338
|
+
modifier_specials: [
|
|
339
|
+
{
|
|
340
|
+
_id: 'mod-pizza',
|
|
341
|
+
name: 'First Pizza',
|
|
342
|
+
sort_id: 1,
|
|
343
|
+
quantity: 1,
|
|
344
|
+
num_free_items: 0,
|
|
345
|
+
excluded_refs: [],
|
|
346
|
+
exclusive_refs: ['large-13'],
|
|
347
|
+
omit_items_schedule: false,
|
|
348
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
}), [{ item_id: 'milan', sort_id: 1, upsell_price: null }]), {
|
|
352
|
+
...itemsMap,
|
|
353
|
+
milan: makeItem('milan', { modifiers: makePizzaSizeAndExtra() }),
|
|
354
|
+
}, {});
|
|
355
|
+
const milanOption = exclusive.modifiers[0].options[0];
|
|
356
|
+
const size = milanOption.modifiers.find((m) => m._id === 'size-mod');
|
|
357
|
+
expect(priceOf(size.options.find((o) => o._id === 'large-13').price)).toBeNull();
|
|
358
|
+
// Specials-alone: only the exclusive ref was zeroed — other modifier
|
|
359
|
+
// prices are kept (small = 500, extra cheese = 200).
|
|
360
|
+
expect(priceOf(size.options.find((o) => o._id === 'small-11').price)).toBe(500);
|
|
361
|
+
const extra = milanOption.modifiers.find((m) => m._id === 'extra-mod');
|
|
362
|
+
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBe(200);
|
|
363
|
+
// Case B: excluded_refs -> extras group removed entirely.
|
|
364
|
+
const excluded = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({
|
|
365
|
+
modifier_specials: [
|
|
366
|
+
{
|
|
367
|
+
_id: 'mod-pizza',
|
|
368
|
+
name: 'First Pizza',
|
|
369
|
+
sort_id: 1,
|
|
370
|
+
quantity: 1,
|
|
371
|
+
num_free_items: 0,
|
|
372
|
+
excluded_refs: ['extra-mod'],
|
|
373
|
+
exclusive_refs: [],
|
|
374
|
+
omit_items_schedule: false,
|
|
375
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
}), {
|
|
379
|
+
...itemsMap,
|
|
380
|
+
milan: makeItem('milan', { modifiers: makePizzaSizeAndExtra() }),
|
|
381
|
+
}, {});
|
|
382
|
+
const milanOpt = excluded.modifiers[0].options[0];
|
|
383
|
+
expect(milanOpt.modifiers.map((m) => m._id)).toEqual(['size-mod']);
|
|
384
|
+
});
|
|
385
|
+
it('returns null when a group has no resolvable options', () => {
|
|
386
|
+
const special = makeSpecial({
|
|
387
|
+
modifier_specials: [
|
|
388
|
+
{
|
|
389
|
+
_id: 'mod-pizza',
|
|
390
|
+
name: 'First Pizza',
|
|
391
|
+
sort_id: 1,
|
|
392
|
+
quantity: 1,
|
|
393
|
+
num_free_items: 0,
|
|
394
|
+
excluded_refs: [],
|
|
395
|
+
exclusive_refs: [],
|
|
396
|
+
omit_items_schedule: false,
|
|
397
|
+
items: [{ item_id: 'missing', sort_id: 1, upsell_price: null }],
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
});
|
|
401
|
+
expect((0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, {})).toBeNull();
|
|
402
|
+
});
|
|
403
|
+
it('modifier-level exclusive_refs zero EVERY option price of that modifier group', () => {
|
|
404
|
+
const special = makeSpecial({
|
|
405
|
+
modifier_specials: [
|
|
406
|
+
{
|
|
407
|
+
_id: 'mod-pizza',
|
|
408
|
+
name: 'First Pizza',
|
|
409
|
+
sort_id: 1,
|
|
410
|
+
quantity: 1,
|
|
411
|
+
num_free_items: 0,
|
|
412
|
+
excluded_refs: [],
|
|
413
|
+
exclusive_refs: ['size-mod'],
|
|
414
|
+
omit_items_schedule: false,
|
|
415
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
});
|
|
419
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, {
|
|
420
|
+
...itemsMap,
|
|
421
|
+
milan: makeItem('milan', { modifiers: makePizzaSizeAndExtra() }),
|
|
422
|
+
}, {});
|
|
423
|
+
const milanOption = item.modifiers[0].options[0];
|
|
424
|
+
const size = milanOption.modifiers.find((m) => m._id === 'size-mod');
|
|
425
|
+
// Group-level exclusive: BOTH sizes free; unrelated group unaffected.
|
|
426
|
+
expect(priceOf(size.options.find((o) => o._id === 'large-13').price)).toBeNull();
|
|
427
|
+
expect(priceOf(size.options.find((o) => o._id === 'small-11').price)).toBeNull();
|
|
428
|
+
const extra = milanOption.modifiers.find((m) => m._id === 'extra-mod');
|
|
429
|
+
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBe(200);
|
|
430
|
+
});
|
|
431
|
+
it('one-price special with NO upsells: all options free; discount carried to item', () => {
|
|
432
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial({ discount_amount: { BASE_PRICE: 200 }, is_discount_percentage: true }), [
|
|
433
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
434
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
435
|
+
]), itemsMap, {});
|
|
436
|
+
expect(priceOf(item.discount_amount)).toBe(200);
|
|
437
|
+
expect(item.is_discount_percentage).toBe(true);
|
|
438
|
+
const options = item.modifiers[0].options;
|
|
439
|
+
expect(priceOf(options.find((o) => o._id === 'milan').price)).toBeNull();
|
|
440
|
+
expect(priceOf(options.find((o) => o._id === 'torent').price)).toBeNull();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
// ============================================================================
|
|
444
|
+
// 3) Specials WITH Half/Half (special is the pricing authority)
|
|
445
|
+
// ============================================================================
|
|
446
|
+
describe('Specials with Half/Half — convertSpecialToItem special-context pricing', () => {
|
|
447
|
+
const specialItems = [
|
|
448
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null }, // basic: free
|
|
449
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } }, // premium +2
|
|
450
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } }, // half-half +1
|
|
451
|
+
];
|
|
452
|
+
const itemsMap = {
|
|
453
|
+
milan: makeItem('milan', { price: { BASE_PRICE: 1000 }, modifiers: makePizzaSizeAndExtra() }),
|
|
454
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1200 } }),
|
|
455
|
+
cola: makeItem('cola', { price: { BASE_PRICE: 300 } }),
|
|
456
|
+
};
|
|
457
|
+
it('half-half option price = special upsell only (own setup upsell ignored)', () => {
|
|
458
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), itemsMap, {
|
|
459
|
+
'halfhalf-1': makeHalfHalfSetup({ upsell_price: { BASE_PRICE: 300 } }),
|
|
460
|
+
});
|
|
461
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
462
|
+
// 300 (own) is ignored; only the special's +100 applies.
|
|
463
|
+
expect(priceOf(hh.price)).toBe(100);
|
|
464
|
+
expect(hh.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
|
|
465
|
+
expect(hh.choose_expensive_segment_price).toBe(true);
|
|
466
|
+
});
|
|
467
|
+
it('pass-through special (no special price): half-half option price is not doubled', () => {
|
|
468
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial({ price: null }), [
|
|
469
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
470
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
471
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
472
|
+
]), itemsMap, { 'halfhalf-1': makeHalfHalfSetup({ upsell_price: { BASE_PRICE: 300 } }) });
|
|
473
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
474
|
+
// Item price already carries the special upsell (100) — must NOT merge it
|
|
475
|
+
// again (would be 200).
|
|
476
|
+
expect(priceOf(hh.price)).toBe(100);
|
|
477
|
+
});
|
|
478
|
+
it('segment options = special upsell / segments; item prices and own upsells ignored', () => {
|
|
479
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), itemsMap, {
|
|
480
|
+
'halfhalf-1': makeHalfHalfSetup(),
|
|
481
|
+
});
|
|
482
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
483
|
+
for (const seg of hh.modifiers ?? []) {
|
|
484
|
+
const milan = seg.options.find((o) => o._id === 'milan');
|
|
485
|
+
const torent = seg.options.find((o) => o._id === 'torent');
|
|
486
|
+
// milan: NO special upsell -> FREE (not 1000/2+50=550).
|
|
487
|
+
expect(priceOf(milan.price)).toBeNull();
|
|
488
|
+
// torent: +200 / 2 segments = +100 (not 1200/2+60=660).
|
|
489
|
+
expect(priceOf(torent.price)).toBe(100);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
it('segment item modifier prices are zeroed at any depth (Pizza Size +575)', () => {
|
|
493
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), itemsMap, {
|
|
494
|
+
'halfhalf-1': makeHalfHalfSetup(),
|
|
495
|
+
});
|
|
496
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
497
|
+
const milan = hh.modifiers[0].options.find((o) => o._id === 'milan');
|
|
498
|
+
// Structure kept, price gone: Large 13" (1150 -> would be 575) is FREE.
|
|
499
|
+
const size = milan.modifiers.find((m) => m._id === 'size-mod');
|
|
500
|
+
expect(size).toBeDefined();
|
|
501
|
+
expect(priceOf(size.options.find((o) => o._id === 'large-13').price)).toBeNull();
|
|
502
|
+
expect(priceOf(size.options.find((o) => o._id === 'small-11').price)).toBeNull();
|
|
503
|
+
const extra = milan.modifiers.find((m) => m._id === 'extra-mod');
|
|
504
|
+
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBeNull();
|
|
505
|
+
});
|
|
506
|
+
it('half-half own excluded/exclusive refs are ignored; only special refs apply', () => {
|
|
507
|
+
const setup = makeHalfHalfSetup({
|
|
508
|
+
excluded_refs: ['milan'], // own rule — must be ignored
|
|
509
|
+
exclusive_refs: ['torent'], // own rule — must be ignored
|
|
510
|
+
});
|
|
511
|
+
// Case A: special has no refs -> milan present AND torent still +100.
|
|
512
|
+
const noRefs = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), itemsMap, {
|
|
513
|
+
'halfhalf-1': setup,
|
|
514
|
+
});
|
|
515
|
+
const hhNoRefs = noRefs.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
516
|
+
const segIds = hhNoRefs.modifiers[0].options.map((o) => o._id);
|
|
517
|
+
expect(segIds).toEqual(['milan', 'torent']);
|
|
518
|
+
expect(priceOf(hhNoRefs.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
519
|
+
// Case B: special exclusive_refs ['torent'] -> segment torent FREE.
|
|
520
|
+
const exclusive = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({
|
|
521
|
+
modifier_specials: [
|
|
522
|
+
{
|
|
523
|
+
_id: 'mod-pizza',
|
|
524
|
+
name: 'First Pizza',
|
|
525
|
+
sort_id: 1,
|
|
526
|
+
quantity: 1,
|
|
527
|
+
num_free_items: 0,
|
|
528
|
+
excluded_refs: [],
|
|
529
|
+
exclusive_refs: ['torent'],
|
|
530
|
+
omit_items_schedule: false,
|
|
531
|
+
items: specialItems,
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
}), itemsMap, { 'halfhalf-1': setup });
|
|
535
|
+
const hhExclusive = exclusive.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
536
|
+
expect(priceOf(hhExclusive.modifiers[0].options.find((o) => o._id === 'torent').price)).toBeNull();
|
|
537
|
+
// Case C: special excluded_refs ['torent'] -> segment torent REMOVED even
|
|
538
|
+
// though the half-half's OWN exclusion was ['milan'] (only special refs
|
|
539
|
+
// apply; milan stays available despite the half-half's own rule).
|
|
540
|
+
const excluded = (0, specials_helpers_1.convertSpecialToItem)(makeSpecial({
|
|
541
|
+
modifier_specials: [
|
|
542
|
+
{
|
|
543
|
+
_id: 'mod-pizza',
|
|
544
|
+
name: 'First Pizza',
|
|
545
|
+
sort_id: 1,
|
|
546
|
+
quantity: 1,
|
|
547
|
+
num_free_items: 0,
|
|
548
|
+
excluded_refs: ['torent'],
|
|
549
|
+
exclusive_refs: [],
|
|
550
|
+
omit_items_schedule: false,
|
|
551
|
+
items: specialItems,
|
|
552
|
+
},
|
|
553
|
+
],
|
|
554
|
+
}), itemsMap, { 'halfhalf-1': setup });
|
|
555
|
+
const hhExcluded = excluded.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
556
|
+
expect(hhExcluded.modifiers[0].options.map((o) => o._id)).toEqual(['milan']);
|
|
557
|
+
});
|
|
558
|
+
it('four-segment half-half divides the special upsell by 4 (quarters)', () => {
|
|
559
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
560
|
+
{ item_id: 'torent', sort_id: 1, upsell_price: { BASE_PRICE: 400 } },
|
|
561
|
+
{ item_id: 'halfhalf-1', sort_id: 2, upsell_price: { BASE_PRICE: 100 } },
|
|
562
|
+
]), itemsMap, {
|
|
563
|
+
'halfhalf-1': makeHalfHalfSetup({
|
|
564
|
+
segments: [
|
|
565
|
+
{ _id: 'q-1', name: 'Quarter 1', sort_id: 1 },
|
|
566
|
+
{ _id: 'q-2', name: 'Quarter 2', sort_id: 2 },
|
|
567
|
+
{ _id: 'q-3', name: 'Quarter 3', sort_id: 3 },
|
|
568
|
+
{ _id: 'q-4', name: 'Quarter 4', sort_id: 4 },
|
|
569
|
+
],
|
|
570
|
+
}),
|
|
571
|
+
});
|
|
572
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
573
|
+
expect(hh.modifiers).toHaveLength(4);
|
|
574
|
+
// +400 / 4 quarters = +100 each (own 60/50 upsells ignored).
|
|
575
|
+
expect(priceOf(hh.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
576
|
+
});
|
|
577
|
+
it('a half-half in a special uses ONLY the special’s items as segment options', () => {
|
|
578
|
+
// The half-half setup contains milan + torent, but the special lists only
|
|
579
|
+
// milan + half-half -> torent (a half-half-only item) is NOT available
|
|
580
|
+
// inside the deal's half-half.
|
|
581
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
582
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
583
|
+
{ item_id: 'halfhalf-1', sort_id: 2, upsell_price: { BASE_PRICE: 100 } },
|
|
584
|
+
]), itemsMap, { 'halfhalf-1': makeHalfHalfSetup() });
|
|
585
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
586
|
+
// Only the special's own item is selectable; torent (catalog price 1200 +
|
|
587
|
+
// own upsell 60) never appears, so nothing can leak as free.
|
|
588
|
+
expect(hh.modifiers[0].options.map((o) => o._id)).toEqual(['milan']);
|
|
589
|
+
});
|
|
590
|
+
it('half-half option with NO special upsell -> free option; segments still special-priced', () => {
|
|
591
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
592
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
593
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
594
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: null },
|
|
595
|
+
]), itemsMap, { 'halfhalf-1': makeHalfHalfSetup({ upsell_price: { BASE_PRICE: 300 } }) });
|
|
596
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
597
|
+
// Own 300 ignored; NO special upsell -> the half-half option is free.
|
|
598
|
+
expect(hh.price).toBeNull();
|
|
599
|
+
// Segments still priced from the special's item upsells (+200/2 = 100).
|
|
600
|
+
expect(priceOf(hh.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
601
|
+
});
|
|
602
|
+
it('does not carry the choose_expensive flag when the setup flag is off', () => {
|
|
603
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
604
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
605
|
+
{ item_id: 'halfhalf-1', sort_id: 2, upsell_price: { BASE_PRICE: 100 } },
|
|
606
|
+
]), itemsMap, { 'halfhalf-1': makeHalfHalfSetup({ choose_expensive_segment_price: false }) });
|
|
607
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
608
|
+
expect(hh.choose_expensive_segment_price).toBeUndefined();
|
|
609
|
+
});
|
|
610
|
+
it('the SAME half-half in two deals follows each deal’s upsell (per-deal authority)', () => {
|
|
611
|
+
const halfhalfMap = { 'halfhalf-1': makeHalfHalfSetup() };
|
|
612
|
+
const dealA = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
613
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
614
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
615
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
616
|
+
]), itemsMap, halfhalfMap);
|
|
617
|
+
const dealB = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial({ price: { BASE_PRICE: 1800 } }), [
|
|
618
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
619
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 600 } },
|
|
620
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 200 } },
|
|
621
|
+
]), itemsMap, halfhalfMap);
|
|
622
|
+
const hhA = dealA.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
623
|
+
const hhB = dealB.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
624
|
+
// Same half-half setup: Deal A +200/2=100, Deal B +600/2=300; option too.
|
|
625
|
+
expect(priceOf(hhA.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
626
|
+
expect(priceOf(hhB.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(300);
|
|
627
|
+
expect(priceOf(hhA.price)).toBe(100);
|
|
628
|
+
expect(priceOf(hhB.price)).toBe(200);
|
|
629
|
+
});
|
|
630
|
+
it('with NO upsell anywhere (top-level and item-level): the whole half-half is free', () => {
|
|
631
|
+
// Original half-half HAS top-level (300) and per-item (50/60) upsells —
|
|
632
|
+
// none of them apply because the special defines none.
|
|
633
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
634
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
635
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
636
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: null },
|
|
637
|
+
]), itemsMap, {
|
|
638
|
+
'halfhalf-1': makeHalfHalfSetup({
|
|
639
|
+
upsell_price: { BASE_PRICE: 300 },
|
|
640
|
+
items: [
|
|
641
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: { BASE_PRICE: 50 } },
|
|
642
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 60 } },
|
|
643
|
+
],
|
|
644
|
+
}),
|
|
645
|
+
});
|
|
646
|
+
const hh = item.modifiers[0].options.find((o) => o._id === 'halfhalf-1');
|
|
647
|
+
expect(hh.price).toBeNull();
|
|
648
|
+
expect(priceOf(hh.modifiers[0].options.find((o) => o._id === 'milan').price)).toBeNull();
|
|
649
|
+
expect(priceOf(hh.modifiers[0].options.find((o) => o._id === 'torent').price)).toBeNull();
|
|
650
|
+
});
|
|
651
|
+
it('a half-half in a DIFFERENT modifier group uses THAT group’s own items', () => {
|
|
652
|
+
const groupItemsMap = {
|
|
653
|
+
milan: makeItem('milan'),
|
|
654
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1200 } }),
|
|
655
|
+
cola: makeItem('cola', { price: { BASE_PRICE: 300 } }),
|
|
656
|
+
fanta: makeItem('fanta', { price: { BASE_PRICE: 350 } }),
|
|
657
|
+
pepsi: makeItem('pepsi', { price: { BASE_PRICE: 400 } }),
|
|
658
|
+
};
|
|
659
|
+
const special = makeSpecial({
|
|
660
|
+
modifier_specials: [
|
|
661
|
+
{
|
|
662
|
+
_id: 'mod-pizza',
|
|
663
|
+
name: 'First Pizza',
|
|
664
|
+
sort_id: 1,
|
|
665
|
+
quantity: 1,
|
|
666
|
+
num_free_items: 0,
|
|
667
|
+
excluded_refs: [],
|
|
668
|
+
exclusive_refs: [],
|
|
669
|
+
omit_items_schedule: false,
|
|
670
|
+
items: [
|
|
671
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
672
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
673
|
+
{ item_id: 'hh-pizza', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
674
|
+
],
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
_id: 'mod-drink',
|
|
678
|
+
name: 'Drink',
|
|
679
|
+
sort_id: 2,
|
|
680
|
+
quantity: 1,
|
|
681
|
+
num_free_items: 0,
|
|
682
|
+
excluded_refs: [],
|
|
683
|
+
exclusive_refs: [],
|
|
684
|
+
omit_items_schedule: false,
|
|
685
|
+
items: [
|
|
686
|
+
{ item_id: 'cola', sort_id: 1, upsell_price: null },
|
|
687
|
+
{ item_id: 'fanta', sort_id: 2, upsell_price: { BASE_PRICE: 50 } },
|
|
688
|
+
{ item_id: 'hh-drink', sort_id: 3, upsell_price: { BASE_PRICE: 75 } },
|
|
689
|
+
],
|
|
690
|
+
},
|
|
691
|
+
],
|
|
692
|
+
});
|
|
693
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(special, groupItemsMap, {
|
|
694
|
+
// Own lists contain extra items (roma / pepsi) that are NOT in the
|
|
695
|
+
// specials — they must never appear.
|
|
696
|
+
'hh-pizza': makeHalfHalfSetup({
|
|
697
|
+
_id: 'hh-pizza',
|
|
698
|
+
items: [
|
|
699
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
700
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
701
|
+
{ item_id: 'roma', sort_id: 3, upsell_price: null },
|
|
702
|
+
],
|
|
703
|
+
}),
|
|
704
|
+
'hh-drink': makeHalfHalfSetup({
|
|
705
|
+
_id: 'hh-drink',
|
|
706
|
+
items: [
|
|
707
|
+
{ item_id: 'cola', sort_id: 1, upsell_price: null },
|
|
708
|
+
{ item_id: 'fanta', sort_id: 2, upsell_price: null },
|
|
709
|
+
{ item_id: 'pepsi', sort_id: 3, upsell_price: null },
|
|
710
|
+
],
|
|
711
|
+
}),
|
|
712
|
+
});
|
|
713
|
+
const pizzaGroup = item.modifiers.find((m) => m._id === 'mod-pizza');
|
|
714
|
+
const drinkGroup = item.modifiers.find((m) => m._id === 'mod-drink');
|
|
715
|
+
const hhPizza = pizzaGroup.options.find((o) => o._id === 'hh-pizza');
|
|
716
|
+
const hhDrink = drinkGroup.options.find((o) => o._id === 'hh-drink');
|
|
717
|
+
// Each half-half uses ITS OWN group's non-half-half items — not its own.
|
|
718
|
+
expect(hhPizza.modifiers[0].options.map((o) => o._id)).toEqual(['milan', 'torent']);
|
|
719
|
+
expect(hhDrink.modifiers[0].options.map((o) => o._id)).toEqual(['cola', 'fanta']);
|
|
720
|
+
expect(priceOf(hhPizza.price)).toBe(100);
|
|
721
|
+
expect(priceOf(hhDrink.price)).toBe(75);
|
|
722
|
+
// Item-level upsell from the drink group: +50 / 2 = 25.
|
|
723
|
+
expect(priceOf(hhDrink.modifiers[0].options.find((o) => o._id === 'fanta').price)).toBe(25);
|
|
724
|
+
});
|
|
725
|
+
it('two half-half options in the same group share the special’s items (not their own)', () => {
|
|
726
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
727
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
728
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
729
|
+
{ item_id: 'hh-flag', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
730
|
+
{ item_id: 'hh-no-flag', sort_id: 4, upsell_price: { BASE_PRICE: 100 } },
|
|
731
|
+
]), itemsMap, {
|
|
732
|
+
'hh-flag': makeHalfHalfSetup({
|
|
733
|
+
_id: 'hh-flag',
|
|
734
|
+
items: [
|
|
735
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
736
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
737
|
+
{ item_id: 'roma', sort_id: 3, upsell_price: null },
|
|
738
|
+
],
|
|
739
|
+
}),
|
|
740
|
+
'hh-no-flag': makeHalfHalfSetup({
|
|
741
|
+
_id: 'hh-no-flag',
|
|
742
|
+
choose_expensive_segment_price: false,
|
|
743
|
+
items: [
|
|
744
|
+
{ item_id: 'roma', sort_id: 1, upsell_price: null },
|
|
745
|
+
{ item_id: 'toskana', sort_id: 2, upsell_price: null },
|
|
746
|
+
],
|
|
747
|
+
}),
|
|
748
|
+
});
|
|
749
|
+
const options = item.modifiers[0].options;
|
|
750
|
+
const hhFlag = options.find((o) => o._id === 'hh-flag');
|
|
751
|
+
const hhNoFlag = options.find((o) => o._id === 'hh-no-flag');
|
|
752
|
+
// BOTH use the special's items (milan/torent) — roma/toskana never appear.
|
|
753
|
+
expect(hhFlag.modifiers[0].options.map((o) => o._id)).toEqual(['milan', 'torent']);
|
|
754
|
+
expect(hhNoFlag.modifiers[0].options.map((o) => o._id)).toEqual(['milan', 'torent']);
|
|
755
|
+
// Only the flagged setup carries choose_expensive.
|
|
756
|
+
expect(hhFlag.choose_expensive_segment_price).toBe(true);
|
|
757
|
+
expect(hhNoFlag.choose_expensive_segment_price).toBeUndefined();
|
|
758
|
+
expect(priceOf(hhNoFlag.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
759
|
+
});
|
|
760
|
+
it('special context: half-half item price is the SPECIAL’s upsell, not the setup’s own', () => {
|
|
761
|
+
const localItemsMap = {
|
|
762
|
+
milan: makeItem('milan'),
|
|
763
|
+
torent: makeItem('torent'),
|
|
764
|
+
};
|
|
765
|
+
const specialItems = [
|
|
766
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
767
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
768
|
+
];
|
|
769
|
+
// Setup's OWN upsell (300) and OWN discount (50%) — both must be ignored.
|
|
770
|
+
const noSpecialUpsell = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|
|
771
|
+
upsell_price: { BASE_PRICE: 300 },
|
|
772
|
+
discount_amount: { BASE_PRICE: 50 },
|
|
773
|
+
is_discount_percentage: true,
|
|
774
|
+
}), localItemsMap, { specialItems, specialHalfHalfUpsell: null });
|
|
775
|
+
expect(noSpecialUpsell.price).toBeNull();
|
|
776
|
+
// The half-half's own discount does NOT apply inside a special.
|
|
777
|
+
expect(noSpecialUpsell.discount_amount).toBeNull();
|
|
778
|
+
expect(noSpecialUpsell.is_discount_percentage).toBe(false);
|
|
779
|
+
// Segments unaffected (special items still priced by their upsell).
|
|
780
|
+
expect(priceOf(noSpecialUpsell.modifiers[0].options.find((o) => o._id === 'torent').price)).toBe(100);
|
|
781
|
+
// When the special DOES upsell the half-half, that becomes the item price.
|
|
782
|
+
const withSpecialUpsell = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({ upsell_price: { BASE_PRICE: 300 } }), localItemsMap, { specialItems, specialHalfHalfUpsell: { BASE_PRICE: 100 } });
|
|
783
|
+
expect(priceOf(withSpecialUpsell.price)).toBe(100);
|
|
784
|
+
});
|
|
785
|
+
it('special context clears the half-half item & segment schedules; standalone keeps them', () => {
|
|
786
|
+
const localItemsMap = {
|
|
787
|
+
milan: makeItem('milan', { item_special_hours: [makeSchedule()] }),
|
|
788
|
+
torent: makeItem('torent'),
|
|
789
|
+
};
|
|
790
|
+
const setup = makeHalfHalfSetup({ item_special_hours: [makeSchedule()] });
|
|
791
|
+
const specialItems = [{ item_id: 'milan', sort_id: 1, upsell_price: null }];
|
|
792
|
+
// Inside a special: the half-half's own schedule is fully ignored.
|
|
793
|
+
const specialCtx = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(setup, localItemsMap, {
|
|
794
|
+
specialItems,
|
|
795
|
+
specialHalfHalfUpsell: null,
|
|
796
|
+
});
|
|
797
|
+
expect(specialCtx.item_special_hours).toBeNull();
|
|
798
|
+
expect(specialCtx.modifiers[0].options[0].item_modifier_option_special_hours).toBeNull();
|
|
799
|
+
// Standalone: schedules carried for the filter layer.
|
|
800
|
+
const standalone = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(setup, localItemsMap);
|
|
801
|
+
expect(standalone.item_special_hours).toHaveLength(1);
|
|
802
|
+
expect(standalone.modifiers[0].options[0].item_modifier_option_special_hours).toHaveLength(1);
|
|
803
|
+
});
|
|
804
|
+
it('special context clears the half-half item & segment schedules; standalone keeps them', () => {
|
|
805
|
+
const localItemsMap = {
|
|
806
|
+
milan: makeItem('milan', { item_special_hours: [makeSchedule()] }),
|
|
807
|
+
torent: makeItem('torent'),
|
|
808
|
+
};
|
|
809
|
+
const setup = makeHalfHalfSetup({ item_special_hours: [makeSchedule()] });
|
|
810
|
+
const specialItems = [{ item_id: 'milan', sort_id: 1, upsell_price: null }];
|
|
811
|
+
// Inside a special: the half-half's own schedule is fully ignored.
|
|
812
|
+
const specialCtx = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(setup, localItemsMap, {
|
|
813
|
+
specialItems,
|
|
814
|
+
specialHalfHalfUpsell: null,
|
|
815
|
+
});
|
|
816
|
+
expect(specialCtx.item_special_hours).toBeNull();
|
|
817
|
+
expect(specialCtx.modifiers[0].options[0].item_modifier_option_special_hours).toBeNull();
|
|
818
|
+
// Standalone: schedules carried for the filter layer.
|
|
819
|
+
const standalone = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(setup, localItemsMap);
|
|
820
|
+
expect(standalone.item_special_hours).toHaveLength(1);
|
|
821
|
+
expect(standalone.modifiers[0].options[0].item_modifier_option_special_hours).toHaveLength(1);
|
|
822
|
+
});
|
|
823
|
+
it('standalone keeps the half-half setup upsell AND discount (no regression)', () => {
|
|
824
|
+
const localItemsMap = {
|
|
825
|
+
milan: makeItem('milan'),
|
|
826
|
+
torent: makeItem('torent'),
|
|
827
|
+
};
|
|
828
|
+
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|
|
829
|
+
upsell_price: { BASE_PRICE: 300 },
|
|
830
|
+
discount_amount: { BASE_PRICE: 50 },
|
|
831
|
+
is_discount_percentage: true,
|
|
832
|
+
}), localItemsMap);
|
|
833
|
+
expect(priceOf(item.price)).toBe(300);
|
|
834
|
+
expect(priceOf(item.discount_amount)).toBe(50);
|
|
835
|
+
expect(item.is_discount_percentage).toBe(true);
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
// ============================================================================
|
|
839
|
+
// 4) Engine — choose_expensive_segment_price end-to-end
|
|
840
|
+
// ============================================================================
|
|
841
|
+
describe('choose_expensive_segment_price end-to-end (specials with half-half)', () => {
|
|
842
|
+
const specialItems = [
|
|
843
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
844
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
845
|
+
{ item_id: 'halfhalf-1', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
846
|
+
];
|
|
847
|
+
function buildEngine() {
|
|
848
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), {
|
|
849
|
+
milan: makeItem('milan', { modifiers: makePizzaSizeAndExtra() }),
|
|
850
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1200 } }),
|
|
851
|
+
}, { 'halfhalf-1': makeHalfHalfSetup() });
|
|
852
|
+
return (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
853
|
+
item,
|
|
854
|
+
orderItem: undefined,
|
|
855
|
+
platform: PLATFORM,
|
|
856
|
+
tenantId: TENANT_ID,
|
|
857
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
858
|
+
defaultMenuId: null,
|
|
859
|
+
soldoutModifiers: [],
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
function segmentOptions(engine, halfHalfId = 'halfhalf-1') {
|
|
863
|
+
const hh = engine.modifiers[0].options.find((o) => o._id === halfHalfId);
|
|
864
|
+
return hh.modifiers.map((seg) => seg.options.map((o) => ({ id: o._id, price: o.price, default: o.default })));
|
|
865
|
+
}
|
|
866
|
+
it('basic + premium selection raises basic half to premium using special-derived prices (+1 each)', () => {
|
|
867
|
+
let engine = buildEngine();
|
|
868
|
+
// Real UI flow: selection happens through the special's engine item, so
|
|
869
|
+
// the identifier is the FULL path (group -> half-half option -> segment
|
|
870
|
+
// -> option) and setCheckField auto-normalizes via its SPECIAL branch.
|
|
871
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-1_milan', true, false);
|
|
872
|
+
expect(segmentOptions(engine)[0].find((o) => o.id === 'milan').price).toBe(100);
|
|
873
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-2_torent', true, false);
|
|
874
|
+
const after = segmentOptions(engine);
|
|
875
|
+
// seg-1 selected MILAN raised 0 -> 100; seg-2 selected TORENT stays 100.
|
|
876
|
+
// Unselected options untouched; NO 575 from Pizza Size anywhere.
|
|
877
|
+
expect(after[0].find((o) => o.id === 'milan').price).toBe(100);
|
|
878
|
+
expect(after[1].find((o) => o.id === 'torent').price).toBe(100);
|
|
879
|
+
const flat = after.flat();
|
|
880
|
+
expect(flat.every((o) => o.price === 0 || o.price === 100)).toBe(true);
|
|
881
|
+
});
|
|
882
|
+
it('is idempotent (re-applying never lowers or changes prices)', () => {
|
|
883
|
+
let engine = buildEngine();
|
|
884
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-1_milan', true, false);
|
|
885
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-2_torent', true, false);
|
|
886
|
+
const once = segmentOptions(engine);
|
|
887
|
+
const twice = segmentOptions((0, order_engine_1.applyNestedChooseExpensiveSegmentPrice)(engine));
|
|
888
|
+
expect(twice).toEqual(once);
|
|
889
|
+
});
|
|
890
|
+
it('does nothing when the half-half flag is off', () => {
|
|
891
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), specialItems), { milan: makeItem('milan'), torent: makeItem('torent') }, { 'halfhalf-1': makeHalfHalfSetup({ choose_expensive_segment_price: false }) });
|
|
892
|
+
let engine = (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
893
|
+
item,
|
|
894
|
+
orderItem: undefined,
|
|
895
|
+
platform: PLATFORM,
|
|
896
|
+
tenantId: TENANT_ID,
|
|
897
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
898
|
+
defaultMenuId: null,
|
|
899
|
+
soldoutModifiers: [],
|
|
900
|
+
});
|
|
901
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-1_milan', true, false);
|
|
902
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_halfhalf-1_seg-2_torent', true, false);
|
|
903
|
+
const after = segmentOptions(engine);
|
|
904
|
+
// Milan stays free (no raise).
|
|
905
|
+
expect(after[0].find((o) => o.id === 'milan').price).toBe(0);
|
|
906
|
+
});
|
|
907
|
+
it('standalone half-half still raises to the most expensive segment (regression)', () => {
|
|
908
|
+
const halfHalfItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup(), {
|
|
909
|
+
milan: makeItem('milan', { price: { BASE_PRICE: 1000 } }),
|
|
910
|
+
torent: makeItem('torent', { price: { BASE_PRICE: 1200 } }),
|
|
911
|
+
});
|
|
912
|
+
let engine = (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
913
|
+
item: halfHalfItem,
|
|
914
|
+
orderItem: undefined,
|
|
915
|
+
platform: PLATFORM,
|
|
916
|
+
tenantId: TENANT_ID,
|
|
917
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
918
|
+
defaultMenuId: null,
|
|
919
|
+
soldoutModifiers: [],
|
|
920
|
+
});
|
|
921
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'seg-1_milan', true, false);
|
|
922
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'seg-2_torent', true, false);
|
|
923
|
+
const result = (0, order_engine_1.applyChooseExpensiveSegmentPrice)(engine);
|
|
924
|
+
const seg1Milan = result.modifiers.find((m) => m._id === 'seg-1').options.find((o) => o._id === 'milan');
|
|
925
|
+
const seg2Torent = result.modifiers.find((m) => m._id === 'seg-2').options.find((o) => o._id === 'torent');
|
|
926
|
+
// milan 550 raised to 660; torent 660 unchanged.
|
|
927
|
+
expect(seg1Milan.price).toBe(660);
|
|
928
|
+
expect(seg2Torent.price).toBe(660);
|
|
929
|
+
});
|
|
930
|
+
it('with mixed flagged/unflagged half-half options, only the flagged one normalizes', () => {
|
|
931
|
+
const item = (0, specials_helpers_1.convertSpecialToItem)(modifySpecialItems(makeSpecial(), [
|
|
932
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
933
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: { BASE_PRICE: 200 } },
|
|
934
|
+
{ item_id: 'hh-flag', sort_id: 3, upsell_price: { BASE_PRICE: 100 } },
|
|
935
|
+
{ item_id: 'hh-no-flag', sort_id: 4, upsell_price: { BASE_PRICE: 100 } },
|
|
936
|
+
]), { milan: makeItem('milan'), torent: makeItem('torent') }, {
|
|
937
|
+
'hh-flag': makeHalfHalfSetup({ _id: 'hh-flag' }),
|
|
938
|
+
'hh-no-flag': makeHalfHalfSetup({ _id: 'hh-no-flag', choose_expensive_segment_price: false }),
|
|
939
|
+
});
|
|
940
|
+
let engine = (0, order_engine_1.convertCatalogItemToOrderEngineItem)({
|
|
941
|
+
item,
|
|
942
|
+
orderItem: undefined,
|
|
943
|
+
platform: PLATFORM,
|
|
944
|
+
tenantId: TENANT_ID,
|
|
945
|
+
orderItemType: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
946
|
+
defaultMenuId: null,
|
|
947
|
+
soldoutModifiers: [],
|
|
948
|
+
});
|
|
949
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_hh-flag_seg-1_milan', true, false);
|
|
950
|
+
engine = (0, order_engine_1.setCheckFieldInOrderEngineItem)(engine, 'mod-pizza_hh-no-flag_seg-1_milan', true, false);
|
|
951
|
+
const hhFlag = engine.modifiers[0].options.find((o) => o._id === 'hh-flag');
|
|
952
|
+
const hhNoFlag = engine.modifiers[0].options.find((o) => o._id === 'hh-no-flag');
|
|
953
|
+
// Flagged: basic half raised to +100; un-flagged: stays free.
|
|
954
|
+
expect(hhFlag.modifiers[0].options.find((o) => o._id === 'milan').price).toBe(100);
|
|
955
|
+
expect(hhNoFlag.modifiers[0].options.find((o) => o._id === 'milan').price).toBe(0);
|
|
956
|
+
});
|
|
957
|
+
});
|