@managesome/eposmatic-toolkit 0.2.748 → 0.2.750
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 +8 -9
- package/lib/helpers/utils/halfhalf-setup-helpers.js +20 -27
- package/lib/tests/choose-expensive-edge-cases.test.js +11 -9
- package/lib/tests/choose-expensive-flow-verification.test.js +4 -3
- package/lib/tests/specials-halfhalf-pricing.test.js +3 -3
- package/package.json +1 -1
|
@@ -28,13 +28,12 @@ export type IWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem> = {
|
|
|
28
28
|
* segments (2 halves / 4 quarters):
|
|
29
29
|
*
|
|
30
30
|
* - the item-level `price` is divided by `segments`,
|
|
31
|
-
* -
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* "
|
|
35
|
-
* -
|
|
36
|
-
*
|
|
37
|
-
* - upsell prices are never touched here; callers merge them on top.
|
|
31
|
+
* - EVERY modifier option price is divided too (recursively, at any depth):
|
|
32
|
+
* required groups because they define the item's price (e.g. "Pizza Size" →
|
|
33
|
+
* "Large 13\""), optional groups because they apply to the same segment
|
|
34
|
+
* (e.g. "Extra Cheese" on one half),
|
|
35
|
+
* - item-level upsell prices are never touched here; callers merge them on
|
|
36
|
+
* top.
|
|
38
37
|
*
|
|
39
38
|
* Returns the item unchanged when `segments` is missing/<= 1.
|
|
40
39
|
*/
|
|
@@ -74,8 +73,8 @@ export interface IConvertHalfHalfToItemOptions {
|
|
|
74
73
|
* Each segment becomes a single-select IModifier (one option per available
|
|
75
74
|
* item, priced as `(item price / segments) + own upsell`), so duplicates
|
|
76
75
|
* across segments are allowed and each segment must be filled exactly once.
|
|
77
|
-
*
|
|
78
|
-
*
|
|
76
|
+
* All modifier option prices are divided with the base (e.g. Pizza Size
|
|
77
|
+
* 1150 -> 575, Extra Cheese 200 -> 100).
|
|
79
78
|
*
|
|
80
79
|
* When the half-half is nested in a special (pass `specialItems`), the special
|
|
81
80
|
* is the authority instead: the segment options are the special's own items
|
|
@@ -78,13 +78,12 @@ function getHalfhalfSetupWithPrice(halfhalfSetup, writeable) {
|
|
|
78
78
|
* segments (2 halves / 4 quarters):
|
|
79
79
|
*
|
|
80
80
|
* - the item-level `price` is divided by `segments`,
|
|
81
|
-
* -
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* "
|
|
85
|
-
* -
|
|
86
|
-
*
|
|
87
|
-
* - upsell prices are never touched here; callers merge them on top.
|
|
81
|
+
* - EVERY modifier option price is divided too (recursively, at any depth):
|
|
82
|
+
* required groups because they define the item's price (e.g. "Pizza Size" →
|
|
83
|
+
* "Large 13\""), optional groups because they apply to the same segment
|
|
84
|
+
* (e.g. "Extra Cheese" on one half),
|
|
85
|
+
* - item-level upsell prices are never touched here; callers merge them on
|
|
86
|
+
* top.
|
|
88
87
|
*
|
|
89
88
|
* Returns the item unchanged when `segments` is missing/<= 1.
|
|
90
89
|
*/
|
|
@@ -92,28 +91,22 @@ function divideItemPriceBySegments(item, segments) {
|
|
|
92
91
|
const divisor = segments ?? 1;
|
|
93
92
|
if (divisor <= 1)
|
|
94
93
|
return item;
|
|
95
|
-
const
|
|
94
|
+
const divideModifierPrices = (modifiers) => {
|
|
96
95
|
if (modifiers == null || modifiers.length === 0)
|
|
97
96
|
return modifiers;
|
|
98
|
-
return modifiers.map((modifier) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
...option,
|
|
107
|
-
price: (0, platform_num_1.convertPriceObjToSegmentPrice)(option.price ?? null, divisor),
|
|
108
|
-
modifiers: divideRequiredModifierPrices(option.modifiers),
|
|
109
|
-
})),
|
|
110
|
-
};
|
|
111
|
-
});
|
|
97
|
+
return modifiers.map((modifier) => ({
|
|
98
|
+
...modifier,
|
|
99
|
+
options: (modifier.options ?? []).map((option) => ({
|
|
100
|
+
...option,
|
|
101
|
+
price: (0, platform_num_1.convertPriceObjToSegmentPrice)(option.price ?? null, divisor),
|
|
102
|
+
modifiers: divideModifierPrices(option.modifiers),
|
|
103
|
+
})),
|
|
104
|
+
}));
|
|
112
105
|
};
|
|
113
106
|
const result = {
|
|
114
107
|
...item,
|
|
115
108
|
price: (0, platform_num_1.convertPriceObjToSegmentPrice)(item.price, divisor),
|
|
116
|
-
modifiers:
|
|
109
|
+
modifiers: divideModifierPrices(item.modifiers),
|
|
117
110
|
};
|
|
118
111
|
return result;
|
|
119
112
|
}
|
|
@@ -210,8 +203,8 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
210
203
|
// excluded_refs removes modifiers/options, exclusive_refs removes their price.
|
|
211
204
|
workableItem.modifiers = (0, specials_helpers_1.applyModifierSpecialRefRules)(workableItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs);
|
|
212
205
|
// Each half/quarter costs the item's price divided by the number of
|
|
213
|
-
// segments;
|
|
214
|
-
//
|
|
206
|
+
// segments; every modifier option price is divided with it (e.g. Pizza
|
|
207
|
+
// Size 1150 -> 575, Extra Cheese 200 -> 100).
|
|
215
208
|
const segmentItem = divideItemPriceBySegments(workableItem, halfhalfSetup.segments.length);
|
|
216
209
|
entries.push({
|
|
217
210
|
workableItem: segmentItem,
|
|
@@ -264,8 +257,8 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
264
257
|
* Each segment becomes a single-select IModifier (one option per available
|
|
265
258
|
* item, priced as `(item price / segments) + own upsell`), so duplicates
|
|
266
259
|
* across segments are allowed and each segment must be filled exactly once.
|
|
267
|
-
*
|
|
268
|
-
*
|
|
260
|
+
* All modifier option prices are divided with the base (e.g. Pizza Size
|
|
261
|
+
* 1150 -> 575, Extra Cheese 200 -> 100).
|
|
269
262
|
*
|
|
270
263
|
* When the half-half is nested in a special (pass `specialItems`), the special
|
|
271
264
|
* is the authority instead: the segment options are the special's own items
|
|
@@ -863,10 +863,11 @@ describe('modern flow converter — references + nested required flags', () => {
|
|
|
863
863
|
const milanoOption = engine.modifiers[1].options[0];
|
|
864
864
|
const milanoLeaf = milanoOption.modifiers[0].options[0];
|
|
865
865
|
const romaExtras = engine.modifiers[0].options[0].modifiers.find((m) => m._id === 'extra-roma');
|
|
866
|
-
// Milano (500) is levelled to ROMA's REQUIRED value only (575) — the
|
|
867
|
-
// extra does not raise it; it stays charged on ROMA alone
|
|
866
|
+
// Milano (500) is levelled to ROMA's REQUIRED value only (575) — the
|
|
867
|
+
// extra does not raise it; it stays charged on ROMA alone (divided with
|
|
868
|
+
// the segment: 200 -> 100).
|
|
868
869
|
expect(milanoLeaf.price).toBe(575);
|
|
869
|
-
expect(romaExtras.options[0].price).toBe(
|
|
870
|
+
expect(romaExtras.options[0].price).toBe(100);
|
|
870
871
|
});
|
|
871
872
|
});
|
|
872
873
|
// ============================================================================
|
|
@@ -958,11 +959,12 @@ describe('classic vs modern parity (same setup + same halves -> same charge)', (
|
|
|
958
959
|
// Second half: levelled to 575 in BOTH flows (500 -> 575).
|
|
959
960
|
expect((0, order_engine_1.getOrderEngineOptionSegmentValue)(classicSeg('seg-2', 'milano'))).toBe(575);
|
|
960
961
|
expect((0, order_engine_1.getOrderEngineOptionSegmentValue)(modernSeg(1))).toBe(575);
|
|
961
|
-
// The optional topping is charged identically (ROMA only,
|
|
962
|
-
|
|
963
|
-
expect(
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
expect(
|
|
962
|
+
// The optional topping is charged identically (ROMA only, divided with
|
|
963
|
+
// the segment: 200 -> 100).
|
|
964
|
+
expect(classicSeg('seg-1', 'roma').modifiers.find((m) => m._id === 'extra-roma').options[0].price).toBe(100);
|
|
965
|
+
expect(modernSeg(0).modifiers.find((m) => m._id === 'extra-roma').options[0].price).toBe(100);
|
|
966
|
+
// End to end: classic total == modern total (575 + 100 + 575).
|
|
967
|
+
expect(classic.subtotal).toBe(1250);
|
|
968
|
+
expect(modern.subtotal).toBe(1250);
|
|
967
969
|
});
|
|
968
970
|
});
|
|
@@ -241,12 +241,13 @@ describe('standalone half-half — classic vs modern parity', () => {
|
|
|
241
241
|
originalPriceReferences: state.originalPriceReferences,
|
|
242
242
|
});
|
|
243
243
|
expect(classicValue(classic, 'seg-1', 'roma')).toBe(1100);
|
|
244
|
-
|
|
245
|
-
expect(classic
|
|
244
|
+
// The optional topping divides with the segment too (200 -> 100).
|
|
245
|
+
expect(classicOption(classic, 'seg-1', 'roma').modifiers.find((m) => m._id === 'extra-mod').options[0].price).toBe(100);
|
|
246
|
+
expect(classic.subtotal).toBe(2300); // 1100 + 100 + 1100
|
|
246
247
|
const { engine: modern } = modernFlow({}, ['roma', 'milano'], true, true);
|
|
247
248
|
expect(modernValue(modern, 0)).toBe(1100);
|
|
248
249
|
expect(modernValue(modern, 1)).toBe(1100);
|
|
249
|
-
expect(modern.modifiers[0].options[0].modifiers.find((m) => m._id === 'extra-mod').options[0].price).toBe(
|
|
250
|
+
expect(modern.modifiers[0].options[0].modifiers.find((m) => m._id === 'extra-mod').options[0].price).toBe(100);
|
|
250
251
|
expect(modern.subtotal).toBe(classic.subtotal);
|
|
251
252
|
});
|
|
252
253
|
it('a single selected half: nothing is charged twice, unselected halves only preview the level (classic)', () => {
|
|
@@ -209,7 +209,7 @@ describe('Half/Half alone — convertHalfHalfToItem pricing', () => {
|
|
|
209
209
|
expect(milan.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
|
-
it('
|
|
212
|
+
it('all modifier option prices divide by segments (required and optional)', () => {
|
|
213
213
|
const setup = makeHalfHalfSetup({
|
|
214
214
|
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
215
215
|
});
|
|
@@ -222,9 +222,9 @@ describe('Half/Half alone — convertHalfHalfToItem pricing', () => {
|
|
|
222
222
|
const size = milan.modifiers.find((m) => m._id === 'size-mod');
|
|
223
223
|
expect(priceOf(size.options.find((o) => o._id === 'large-13').price)).toBe(575);
|
|
224
224
|
expect(priceOf(size.options.find((o) => o._id === 'small-11').price)).toBe(250);
|
|
225
|
-
// Optional
|
|
225
|
+
// Optional group divided too: 200 -> 100.
|
|
226
226
|
const extra = milan.modifiers.find((m) => m._id === 'extra-mod');
|
|
227
|
-
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBe(
|
|
227
|
+
expect(priceOf(extra.options.find((o) => o._id === 'cheese').price)).toBe(100);
|
|
228
228
|
});
|
|
229
229
|
it('own excluded_refs remove segment items; own exclusive_refs make them free', () => {
|
|
230
230
|
const item = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(makeHalfHalfSetup({
|