@managesome/eposmatic-toolkit 0.2.762 → 0.2.764
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/store/cart-actions.js +2 -0
- package/lib/helpers/utils/platform-catalog.d.ts +1 -1
- package/lib/helpers/utils/platform-catalog.js +5 -2
- package/lib/helpers/utils/specials-helpers.d.ts +9 -3
- package/lib/helpers/utils/specials-helpers.js +33 -9
- package/lib/tests/specials-platform-availability.test.d.ts +1 -0
- package/lib/tests/specials-platform-availability.test.js +340 -0
- package/package.json +1 -1
|
@@ -1427,6 +1427,8 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
1427
1427
|
// ready_minutes in sync with that transition (mirrors the order status
|
|
1428
1428
|
// updates): measured from the item's own prep clock, falling back to the
|
|
1429
1429
|
// order's stage clock. Already-ready items keep their stored duration.
|
|
1430
|
+
// Keep in sync with items-service updateOrderStatus (aggregation pipeline
|
|
1431
|
+
// stamp) and updateOrder (new-item prep stamp).
|
|
1430
1432
|
let readyMinutes;
|
|
1431
1433
|
if (item.is_ready !== true && isCompleted) {
|
|
1432
1434
|
const readyMinutesAnchor = item.prep_started_at ?? data.order_status_updated_at;
|
|
@@ -47,7 +47,7 @@ type ISimplifiedSetupWithAvailability = {
|
|
|
47
47
|
export declare function isSimplifiedSetupApplicable(setup: ISimplifiedSetupWithAvailability, platform: PLATFORMS_ENUM): boolean;
|
|
48
48
|
export declare function getPlatformModifierOptions(options: IModifierOption[], platform: PLATFORMS_ENUM, excludeIds?: string[]): IModifierOption[];
|
|
49
49
|
export declare function getPlatformModifiers(modifiers: IModifier[] | null | undefined, platform: PLATFORMS_ENUM | undefined, excludeIds?: string[]): IModifier[] | null;
|
|
50
|
-
export declare function convertItemToWorkableItem<T extends IItem | ISimplifiedCatalogItem>(item: T, platform: PLATFORMS_ENUM, tenantId: string | undefined, omitSchedule?: boolean, omitSchedulePricing?: boolean): T | null;
|
|
50
|
+
export declare function convertItemToWorkableItem<T extends IItem | ISimplifiedCatalogItem>(item: T, platform: PLATFORMS_ENUM, tenantId: string | undefined, omitSchedule?: boolean, omitSchedulePricing?: boolean, omitPlatformCheck?: boolean): T | null;
|
|
51
51
|
export declare function convertOptionToWorkableOption(option: IModifierOption, platform: PLATFORMS_ENUM): IModifierOption | null;
|
|
52
52
|
export declare function convertCatalogToWorkableCatalog<T extends ICatalog | ISimplifiedCatalog>(catalogs: T[], platform: PLATFORMS_ENUM | undefined, tenantId: string | undefined): T[];
|
|
53
53
|
/**
|
|
@@ -184,10 +184,13 @@ function getPlatformModifiers(modifiers, platform, excludeIds = []) {
|
|
|
184
184
|
return platformModifiers;
|
|
185
185
|
}
|
|
186
186
|
// ==========================================================><====================================================
|
|
187
|
-
function convertItemToWorkableItem(item, platform, tenantId, omitSchedule, omitSchedulePricing) {
|
|
187
|
+
function convertItemToWorkableItem(item, platform, tenantId, omitSchedule, omitSchedulePricing, omitPlatformCheck) {
|
|
188
188
|
// if item is not active or it is not included in the current platform, we skip it
|
|
189
189
|
if (!item.active ||
|
|
190
|
-
|
|
190
|
+
// Items resolved INSIDE a setup (specials) pass `omitPlatformCheck`: the
|
|
191
|
+
// setup's own platform membership is that gate, and its items are shown
|
|
192
|
+
// even when they don't belong to the current platform.
|
|
193
|
+
(!omitPlatformCheck && !item.included_platforms.includes(platform)) ||
|
|
191
194
|
// This condition will only work in POS. This condition is for call center
|
|
192
195
|
(item.tenants != null && !item.tenants.includes(tenantId))) {
|
|
193
196
|
return null;
|
|
@@ -78,9 +78,15 @@ export declare function deStructureSpecialOrderItem(orderItem: IOrderItem, speci
|
|
|
78
78
|
* included_platforms) and no special-hours / platform-based price
|
|
79
79
|
* resolution happens here. Setup fields are copied through as-is:
|
|
80
80
|
* - `item_special_hours` is preserved on the output item,
|
|
81
|
-
* -
|
|
82
|
-
*
|
|
83
|
-
*
|
|
81
|
+
* - ITEM options are platform-open (`excluded_platforms: []`): constituent
|
|
82
|
+
* items are shown even when they don't belong to the current platform (the
|
|
83
|
+
* special's own `included_platforms` is the platform gate — same rule as
|
|
84
|
+
* `convertSpecialsToWorkableSpecials`; the classic drawer engine and the
|
|
85
|
+
* `hasAllModifierOptionsAvailable` gates must not filter them),
|
|
86
|
+
* - HALF-HALF options keep the derived (complement) `excluded_platforms` from
|
|
87
|
+
* the converted half-half item, so the half-half setup's own platform gate
|
|
88
|
+
* still applies (the classic counterpart of the platform-filtered
|
|
89
|
+
* `visibleHalfHalfItems` in the modern flow).
|
|
84
90
|
*
|
|
85
91
|
* Availability-aware consumers compose this with `isSetupApplicable(...)`
|
|
86
92
|
* (and `convertItemToWorkableItem(...)` / `getPlatformModifiers(...)` for
|
|
@@ -174,12 +174,18 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
174
174
|
}
|
|
175
175
|
continue;
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
// Constituent items are NOT gated by platform membership (the last
|
|
178
|
+
// `true`): the special's own `included_platforms` is the platform gate,
|
|
179
|
+
// and a deal may legitimately feature items that don't belong to the
|
|
180
|
+
// current platform — they are shown and selectable anyway. Inactive
|
|
181
|
+
// items stay excluded here; when EVERY item of a group is inactive the
|
|
182
|
+
// group resolves empty and blocks the special (see `hasEmptyGroup`).
|
|
183
|
+
const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true, true);
|
|
178
184
|
if (!workableItem) {
|
|
179
185
|
// The item failed ONLY its own schedule: probe without the schedule
|
|
180
186
|
// check to tell "scheduled out right now" apart from "structurally
|
|
181
|
-
// unavailable" (inactive /
|
|
182
|
-
if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true) != null) {
|
|
187
|
+
// unavailable" (inactive / tenant filtered).
|
|
188
|
+
if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true, true) != null) {
|
|
183
189
|
hasScheduledOutItem = true;
|
|
184
190
|
}
|
|
185
191
|
continue;
|
|
@@ -202,6 +208,12 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
202
208
|
// its items are merely outside their own schedule right now. Item
|
|
203
209
|
// schedules filter the selectable options at selection time; menu-level
|
|
204
210
|
// validity is governed by the special's own schedule.
|
|
211
|
+
//
|
|
212
|
+
// With platform membership no longer gating constituent items, a group
|
|
213
|
+
// only ends up here when NONE of its items are usable: they are all
|
|
214
|
+
// INACTIVE (product rule: all-inactive group blocks the deal), missing
|
|
215
|
+
// from the catalog, or belong to another tenant. Out-of-platform items
|
|
216
|
+
// are resolvable and are shown.
|
|
205
217
|
if (items.length === 0 && !hasHalfHalfRef && !hasScheduledOutItem) {
|
|
206
218
|
hasEmptyGroup = true;
|
|
207
219
|
continue;
|
|
@@ -420,9 +432,15 @@ function deStructureSpecialOrderItem(orderItem, specialItem) {
|
|
|
420
432
|
* included_platforms) and no special-hours / platform-based price
|
|
421
433
|
* resolution happens here. Setup fields are copied through as-is:
|
|
422
434
|
* - `item_special_hours` is preserved on the output item,
|
|
423
|
-
* -
|
|
424
|
-
*
|
|
425
|
-
*
|
|
435
|
+
* - ITEM options are platform-open (`excluded_platforms: []`): constituent
|
|
436
|
+
* items are shown even when they don't belong to the current platform (the
|
|
437
|
+
* special's own `included_platforms` is the platform gate — same rule as
|
|
438
|
+
* `convertSpecialsToWorkableSpecials`; the classic drawer engine and the
|
|
439
|
+
* `hasAllModifierOptionsAvailable` gates must not filter them),
|
|
440
|
+
* - HALF-HALF options keep the derived (complement) `excluded_platforms` from
|
|
441
|
+
* the converted half-half item, so the half-half setup's own platform gate
|
|
442
|
+
* still applies (the classic counterpart of the platform-filtered
|
|
443
|
+
* `visibleHalfHalfItems` in the modern flow).
|
|
426
444
|
*
|
|
427
445
|
* Availability-aware consumers compose this with `isSetupApplicable(...)`
|
|
428
446
|
* (and `convertItemToWorkableItem(...)` / `getPlatformModifiers(...)` for
|
|
@@ -540,9 +558,15 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
540
558
|
// Only on a nested half-half: the setup flag so the engine normalizes
|
|
541
559
|
// the option's own segment groups at selection time.
|
|
542
560
|
...(isHalfHalfOption && halfHalfChooseExpensive ? { choose_expensive_segment_price: true } : {}),
|
|
543
|
-
//
|
|
544
|
-
//
|
|
545
|
-
|
|
561
|
+
// Constituent items are NOT platform-gated inside a special (same
|
|
562
|
+
// rule as the menu/list conversion): regular item options are
|
|
563
|
+
// platform-open so the drawer engine (`getPlatformModifiers`) and the
|
|
564
|
+
// availability gates (`hasAllModifierOptionsAvailable`) keep them.
|
|
565
|
+
// Half-half options keep the derived complement — the half-half
|
|
566
|
+
// setup's own platform gate still applies.
|
|
567
|
+
excluded_platforms: isHalfHalfOption
|
|
568
|
+
? (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms)
|
|
569
|
+
: [],
|
|
546
570
|
// Carry the source item's special hours so the filter layer can apply
|
|
547
571
|
// schedule AVAILABILITY (pure mapping, no resolution here). Item
|
|
548
572
|
// schedule-level PRICING/DISCOUNTS are ignored inside a special: they
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const platform_catalog_1 = require("../helpers/utils/platform-catalog");
|
|
5
|
+
const specials_helpers_1 = require("../helpers/utils/specials-helpers");
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Specials: platform membership of CONSTITUENT items.
|
|
8
|
+
//
|
|
9
|
+
// - The special's own `included_platforms` is the platform gate for the
|
|
10
|
+
// deal. Its items are NOT gated by platform membership: a deal may
|
|
11
|
+
// legitimately feature items that don't belong to the current platform and
|
|
12
|
+
// they are shown and selectable anyway.
|
|
13
|
+
// - INACTIVE items stay excluded. A group whose items are ALL inactive
|
|
14
|
+
// resolves empty and blocks the special (nothing to select); a group with
|
|
15
|
+
// at least one active item keeps the deal, hiding only the inactive ones.
|
|
16
|
+
// - Tenant / schedule checks on the items are unchanged.
|
|
17
|
+
// ============================================================================
|
|
18
|
+
const TENANT_ID = 'tenant-1';
|
|
19
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
20
|
+
const OTHER_PLATFORM = constants_1.PLATFORMS_ENUM.WEB_DELIVERY;
|
|
21
|
+
/**
|
|
22
|
+
* Never-applicable schedule: no days at all, so `findApplicableSchedule`
|
|
23
|
+
* finds no schedule for the current day and returns `false`.
|
|
24
|
+
*/
|
|
25
|
+
function makeScheduledOutHours() {
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
days_index: [],
|
|
29
|
+
disabled_outside_date_range: false,
|
|
30
|
+
start_time: 0,
|
|
31
|
+
end_time: 24 * 3600000,
|
|
32
|
+
start_date: null,
|
|
33
|
+
end_date: null,
|
|
34
|
+
price: null,
|
|
35
|
+
is_discount_percentage: false,
|
|
36
|
+
excluded_platforms: [],
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
function makeItem(id, overrides = {}) {
|
|
41
|
+
return {
|
|
42
|
+
_id: id,
|
|
43
|
+
brand_id: 'brand-1',
|
|
44
|
+
tenants: [TENANT_ID],
|
|
45
|
+
category_id: 'pizza-cat',
|
|
46
|
+
included_platforms: [PLATFORM],
|
|
47
|
+
name: `Item ${id}`,
|
|
48
|
+
active: true,
|
|
49
|
+
sold_out: [],
|
|
50
|
+
sort_id: 1,
|
|
51
|
+
image_url: `https://example.com/${id}.jpg`,
|
|
52
|
+
price: { BASE_PRICE: 1000 },
|
|
53
|
+
discount_amount: null,
|
|
54
|
+
is_discount_percentage: false,
|
|
55
|
+
tax_rate: null,
|
|
56
|
+
keywords: [],
|
|
57
|
+
caveats: [],
|
|
58
|
+
dietary_preferences: [],
|
|
59
|
+
hide_name: false,
|
|
60
|
+
description: '',
|
|
61
|
+
ingredients: null,
|
|
62
|
+
is_featured: false,
|
|
63
|
+
featured_sort_id: 0,
|
|
64
|
+
item_special_hours: null,
|
|
65
|
+
display_price: null,
|
|
66
|
+
show_starting_from: false,
|
|
67
|
+
createdAt: new Date('2024-01-01'),
|
|
68
|
+
updatedAt: new Date('2024-01-02'),
|
|
69
|
+
modifiers: null,
|
|
70
|
+
...overrides,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function makeModifierSpecial(overrides = {}) {
|
|
74
|
+
return {
|
|
75
|
+
_id: 'mod-pizza',
|
|
76
|
+
name: 'First Pizza',
|
|
77
|
+
sort_id: 1,
|
|
78
|
+
quantity: 1,
|
|
79
|
+
num_free_items: 0,
|
|
80
|
+
excluded_refs: [],
|
|
81
|
+
exclusive_refs: [],
|
|
82
|
+
omit_items_schedule: false,
|
|
83
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
84
|
+
...overrides,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function makeSpecialWithModifier(overrides = {}) {
|
|
88
|
+
return {
|
|
89
|
+
_id: 'special-1',
|
|
90
|
+
brand_id: 'brand-1',
|
|
91
|
+
tenants: [TENANT_ID],
|
|
92
|
+
category_id: 'combo-cat',
|
|
93
|
+
included_platforms: [PLATFORM],
|
|
94
|
+
name: 'Buy 1 Pizza Get 1 Free',
|
|
95
|
+
description: 'Deal',
|
|
96
|
+
active: true,
|
|
97
|
+
sold_out: [],
|
|
98
|
+
sort_id: 1,
|
|
99
|
+
image_url: 'https://example.com/special.jpg',
|
|
100
|
+
price: { BASE_PRICE: 1500 },
|
|
101
|
+
discount_amount: null,
|
|
102
|
+
is_discount_percentage: false,
|
|
103
|
+
display_price: null,
|
|
104
|
+
show_starting_from: false,
|
|
105
|
+
item_special_hours: null,
|
|
106
|
+
modifier_specials: [makeModifierSpecial()],
|
|
107
|
+
createdAt: new Date('2024-01-01'),
|
|
108
|
+
updatedAt: new Date('2024-01-02'),
|
|
109
|
+
...overrides,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function makeHalfHalfSetup(overrides = {}) {
|
|
113
|
+
return {
|
|
114
|
+
_id: 'halfhalf-1',
|
|
115
|
+
brand_id: 'brand-1',
|
|
116
|
+
tenants: [TENANT_ID],
|
|
117
|
+
category_id: 'pizza-cat',
|
|
118
|
+
included_platforms: [PLATFORM],
|
|
119
|
+
name: 'Half/Half Pizza Large',
|
|
120
|
+
description: 'Two halves',
|
|
121
|
+
active: true,
|
|
122
|
+
sold_out: [],
|
|
123
|
+
image_url: 'https://example.com/halfhalf.jpg',
|
|
124
|
+
upsell_price: null,
|
|
125
|
+
discount_amount: null,
|
|
126
|
+
is_discount_percentage: false,
|
|
127
|
+
sort_id: 1,
|
|
128
|
+
choose_expensive_segment_price: true,
|
|
129
|
+
segments: [
|
|
130
|
+
{ _id: 'seg-1', name: 'First Pizza', sort_id: 1 },
|
|
131
|
+
{ _id: 'seg-2', name: 'Second Pizza', sort_id: 2 },
|
|
132
|
+
],
|
|
133
|
+
// Ignored inside a special: the segment options ARE the group's own items.
|
|
134
|
+
items: [],
|
|
135
|
+
exclusive_refs: [],
|
|
136
|
+
excluded_refs: [],
|
|
137
|
+
item_special_hours: null,
|
|
138
|
+
createdAt: new Date('2024-01-01'),
|
|
139
|
+
updatedAt: new Date('2024-01-02'),
|
|
140
|
+
...overrides,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
describe('specials: constituent items are not gated by platform membership', () => {
|
|
144
|
+
it('shows the special when every item of the group is outside the platform', () => {
|
|
145
|
+
const itemsMap = {
|
|
146
|
+
milan: makeItem('milan', { included_platforms: [OTHER_PLATFORM] }),
|
|
147
|
+
};
|
|
148
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
149
|
+
expect(workable).toBeDefined();
|
|
150
|
+
expect(workable.modifier_specials).toHaveLength(1);
|
|
151
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan']);
|
|
152
|
+
// The item keeps its own platform membership — it is shown as-is.
|
|
153
|
+
expect(workable.modifier_specials[0].items[0].included_platforms).toEqual([OTHER_PLATFORM]);
|
|
154
|
+
});
|
|
155
|
+
it('shows out-of-platform items alongside in-platform items', () => {
|
|
156
|
+
const itemsMap = {
|
|
157
|
+
milan: makeItem('milan'),
|
|
158
|
+
torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
|
|
159
|
+
};
|
|
160
|
+
const special = makeSpecialWithModifier({
|
|
161
|
+
modifier_specials: [
|
|
162
|
+
makeModifierSpecial({
|
|
163
|
+
items: [
|
|
164
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
165
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
166
|
+
],
|
|
167
|
+
}),
|
|
168
|
+
],
|
|
169
|
+
});
|
|
170
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
171
|
+
expect(workable).toBeDefined();
|
|
172
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan', 'torent']);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe('specials: inactive items still gate the deal', () => {
|
|
176
|
+
it('hides the special when every item of a group is inactive', () => {
|
|
177
|
+
const itemsMap = {
|
|
178
|
+
milan: makeItem('milan', { active: false }),
|
|
179
|
+
torent: makeItem('torent', { active: false }),
|
|
180
|
+
};
|
|
181
|
+
const special = makeSpecialWithModifier({
|
|
182
|
+
modifier_specials: [
|
|
183
|
+
makeModifierSpecial({
|
|
184
|
+
items: [
|
|
185
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
186
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
187
|
+
],
|
|
188
|
+
}),
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
192
|
+
expect(workable).toBeUndefined();
|
|
193
|
+
});
|
|
194
|
+
it('hides the special when every item is inactive, regardless of platform membership', () => {
|
|
195
|
+
const itemsMap = {
|
|
196
|
+
milan: makeItem('milan', { active: false }),
|
|
197
|
+
torent: makeItem('torent', { active: false, included_platforms: [OTHER_PLATFORM] }),
|
|
198
|
+
};
|
|
199
|
+
const special = makeSpecialWithModifier({
|
|
200
|
+
modifier_specials: [
|
|
201
|
+
makeModifierSpecial({
|
|
202
|
+
items: [
|
|
203
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
204
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
205
|
+
],
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
210
|
+
expect(workable).toBeUndefined();
|
|
211
|
+
});
|
|
212
|
+
it('keeps the special when only some items are inactive', () => {
|
|
213
|
+
const itemsMap = {
|
|
214
|
+
milan: makeItem('milan', { active: false }),
|
|
215
|
+
torent: makeItem('torent'),
|
|
216
|
+
};
|
|
217
|
+
const special = makeSpecialWithModifier({
|
|
218
|
+
modifier_specials: [
|
|
219
|
+
makeModifierSpecial({
|
|
220
|
+
items: [
|
|
221
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
222
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
223
|
+
],
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
228
|
+
expect(workable).toBeDefined();
|
|
229
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
|
|
230
|
+
});
|
|
231
|
+
it('keeps the special when an inactive item is mixed with an out-of-platform item', () => {
|
|
232
|
+
const itemsMap = {
|
|
233
|
+
milan: makeItem('milan', { active: false }),
|
|
234
|
+
torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
|
|
235
|
+
};
|
|
236
|
+
const special = makeSpecialWithModifier({
|
|
237
|
+
modifier_specials: [
|
|
238
|
+
makeModifierSpecial({
|
|
239
|
+
items: [
|
|
240
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
241
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
247
|
+
expect(workable).toBeDefined();
|
|
248
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe('specials: tenant and schedule checks on items are unchanged', () => {
|
|
252
|
+
it("hides the special when a group's items all belong to another tenant", () => {
|
|
253
|
+
const itemsMap = {
|
|
254
|
+
milan: makeItem('milan', { tenants: ['other-tenant'] }),
|
|
255
|
+
};
|
|
256
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
257
|
+
expect(workable).toBeUndefined();
|
|
258
|
+
});
|
|
259
|
+
it('still filters scheduled-out out-of-platform items from the options (deal kept)', () => {
|
|
260
|
+
const itemsMap = {
|
|
261
|
+
milan: makeItem('milan', {
|
|
262
|
+
included_platforms: [OTHER_PLATFORM],
|
|
263
|
+
item_special_hours: makeScheduledOutHours(),
|
|
264
|
+
}),
|
|
265
|
+
};
|
|
266
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
267
|
+
// The item is outside its own schedule right now -> not selectable, but
|
|
268
|
+
// the special itself stays (its own schedule is the menu-level gate).
|
|
269
|
+
expect(workable).toBeDefined();
|
|
270
|
+
expect(workable.modifier_specials[0].items).toHaveLength(0);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
describe('convertSpecialToItem: classic preview option platform flags', () => {
|
|
274
|
+
it('marks regular item options platform-open so the classic gates keep them', () => {
|
|
275
|
+
const itemsMap = {
|
|
276
|
+
milan: makeItem('milan'),
|
|
277
|
+
torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
|
|
278
|
+
};
|
|
279
|
+
const special = makeSpecialWithModifier({
|
|
280
|
+
modifier_specials: [
|
|
281
|
+
makeModifierSpecial({
|
|
282
|
+
items: [
|
|
283
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
284
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
285
|
+
],
|
|
286
|
+
}),
|
|
287
|
+
],
|
|
288
|
+
});
|
|
289
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, {});
|
|
290
|
+
expect(converted).not.toBeNull();
|
|
291
|
+
if (converted == null)
|
|
292
|
+
return;
|
|
293
|
+
// Both options are available on every platform — the classic drawer
|
|
294
|
+
// engine and the availability gates must keep them.
|
|
295
|
+
expect(converted.modifiers?.[0].options.map((option) => option.excluded_platforms)).toEqual([[], []]);
|
|
296
|
+
expect((0, platform_catalog_1.hasAllModifierOptionsAvailable)(converted, PLATFORM)).toBe(true);
|
|
297
|
+
});
|
|
298
|
+
it('keeps the derived platform complement on half-half options', () => {
|
|
299
|
+
const itemsMap = { milan: makeItem('milan') };
|
|
300
|
+
const halfhalfSetups = {
|
|
301
|
+
'halfhalf-1': makeHalfHalfSetup({ included_platforms: [OTHER_PLATFORM] }),
|
|
302
|
+
};
|
|
303
|
+
const special = makeSpecialWithModifier({
|
|
304
|
+
modifier_specials: [
|
|
305
|
+
makeModifierSpecial({
|
|
306
|
+
items: [
|
|
307
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
308
|
+
{ item_id: 'halfhalf-1', sort_id: 2, upsell_price: null },
|
|
309
|
+
],
|
|
310
|
+
}),
|
|
311
|
+
],
|
|
312
|
+
});
|
|
313
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfSetups);
|
|
314
|
+
expect(converted).not.toBeNull();
|
|
315
|
+
if (converted == null)
|
|
316
|
+
return;
|
|
317
|
+
const options = converted.modifiers?.[0].options ?? [];
|
|
318
|
+
// The half-half setup is not on the current platform -> its option keeps
|
|
319
|
+
// the setup's own platform gate ...
|
|
320
|
+
const halfHalfOption = options.find((option) => option._id === 'halfhalf-1');
|
|
321
|
+
expect(halfHalfOption).toBeDefined();
|
|
322
|
+
expect(halfHalfOption?.excluded_platforms).toContain(PLATFORM);
|
|
323
|
+
expect(halfHalfOption?.excluded_platforms).not.toContain(OTHER_PLATFORM);
|
|
324
|
+
// ... while regular items stay platform-open.
|
|
325
|
+
const itemOption = options.find((option) => option._id === 'milan');
|
|
326
|
+
expect(itemOption?.excluded_platforms).toEqual([]);
|
|
327
|
+
});
|
|
328
|
+
it('keeps the classic gate blocking when every item of a group is inactive', () => {
|
|
329
|
+
const itemsMap = {
|
|
330
|
+
milan: makeItem('milan', { active: false }),
|
|
331
|
+
};
|
|
332
|
+
const converted = (0, specials_helpers_1.convertSpecialToItem)(makeSpecialWithModifier(), itemsMap, {});
|
|
333
|
+
// The conversion itself is pure (no availability filtering) ...
|
|
334
|
+
expect(converted).not.toBeNull();
|
|
335
|
+
if (converted == null)
|
|
336
|
+
return;
|
|
337
|
+
// ... while the classic-preview gate still blocks the all-inactive group.
|
|
338
|
+
expect((0, platform_catalog_1.hasAllModifierOptionsAvailable)(converted, PLATFORM)).toBe(false);
|
|
339
|
+
});
|
|
340
|
+
});
|