@managesome/eposmatic-toolkit 0.2.761 → 0.2.763
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 +15 -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.js +15 -3
- package/lib/schemas/models/orders.d.ts +108 -108
- package/lib/tests/cart-actions.test.js +79 -0
- package/lib/tests/specials-platform-availability.test.d.ts +1 -0
- package/lib/tests/specials-platform-availability.test.js +240 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cart_actions_1 = require("../helpers/store/cart-actions");
|
|
4
|
+
const constants_1 = require("../constants");
|
|
4
5
|
const OFFER_ID = 'offer-loyalty-reward';
|
|
5
6
|
const VOUCHER_ID = 'offer-voucher-reward';
|
|
6
7
|
const GIFT_CARD_ID = 'gift-card-reward';
|
|
@@ -150,3 +151,81 @@ describe('getCashierAppliedDiscountAmount', () => {
|
|
|
150
151
|
expect((0, cart_actions_1.getCashierAppliedDiscountAmount)(undefined)).toBe(0);
|
|
151
152
|
});
|
|
152
153
|
});
|
|
154
|
+
function makeSyncItem(params) {
|
|
155
|
+
return {
|
|
156
|
+
_id: params._id,
|
|
157
|
+
item_id: `item-${params._id}`,
|
|
158
|
+
menu_id: null,
|
|
159
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.ITEM,
|
|
160
|
+
name: 'Item',
|
|
161
|
+
price: 100,
|
|
162
|
+
quantity: 1,
|
|
163
|
+
subtotal: 100,
|
|
164
|
+
tax_rate: 0,
|
|
165
|
+
special_instructions: '',
|
|
166
|
+
modifiers: [],
|
|
167
|
+
item_discount_details: null,
|
|
168
|
+
is_ready: params.is_ready,
|
|
169
|
+
prep_started_at: params.prep_started_at,
|
|
170
|
+
ready_minutes: params.ready_minutes,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
describe('calculateCartOrderInfoAndSyncData — ready minutes on completion', () => {
|
|
174
|
+
const minutesAgo = (minutes) => new Date(Date.now() - minutes * 60000);
|
|
175
|
+
it('stamps ready_minutes from the item prep clock when completion marks it ready', () => {
|
|
176
|
+
const order = makeOrder({
|
|
177
|
+
order_status: constants_1.ORDER_STATUS_ENUM.COMPLETED,
|
|
178
|
+
categories: [
|
|
179
|
+
{
|
|
180
|
+
category_id: 'c1',
|
|
181
|
+
items: [makeSyncItem({ _id: 'a', is_ready: false, prep_started_at: minutesAgo(12.2) })],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(order);
|
|
186
|
+
const item = result.categories[0].items[0];
|
|
187
|
+
expect(item.is_ready).toBe(true);
|
|
188
|
+
expect(item.ready_minutes).toBe(12);
|
|
189
|
+
});
|
|
190
|
+
it('falls back to the order stage clock when the item has no prep_started_at', () => {
|
|
191
|
+
const order = makeOrder({
|
|
192
|
+
order_status: constants_1.ORDER_STATUS_ENUM.COMPLETED,
|
|
193
|
+
order_status_updated_at: minutesAgo(8.2),
|
|
194
|
+
categories: [
|
|
195
|
+
{
|
|
196
|
+
category_id: 'c1',
|
|
197
|
+
items: [makeSyncItem({ _id: 'a', is_ready: false, prep_started_at: null })],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(order);
|
|
202
|
+
expect(result.categories[0].items[0].ready_minutes).toBe(8);
|
|
203
|
+
});
|
|
204
|
+
it('keeps the stored duration for items that were already ready', () => {
|
|
205
|
+
const order = makeOrder({
|
|
206
|
+
order_status: constants_1.ORDER_STATUS_ENUM.COMPLETED,
|
|
207
|
+
categories: [
|
|
208
|
+
{
|
|
209
|
+
category_id: 'c1',
|
|
210
|
+
items: [makeSyncItem({ _id: 'a', is_ready: true, ready_minutes: 7, prep_started_at: minutesAgo(30) })],
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(order);
|
|
215
|
+
expect(result.categories[0].items[0].ready_minutes).toBe(7);
|
|
216
|
+
});
|
|
217
|
+
it('does not stamp ready_minutes while the order is not completed', () => {
|
|
218
|
+
const order = makeOrder({
|
|
219
|
+
order_status: constants_1.ORDER_STATUS_ENUM.PREPARING,
|
|
220
|
+
categories: [
|
|
221
|
+
{
|
|
222
|
+
category_id: 'c1',
|
|
223
|
+
items: [makeSyncItem({ _id: 'a', is_ready: false, prep_started_at: minutesAgo(12.2) })],
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(order);
|
|
228
|
+
expect(result.categories[0].items[0].is_ready).toBeFalsy();
|
|
229
|
+
expect(result.categories[0].items[0].ready_minutes).toBeUndefined();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const specials_helpers_1 = require("../helpers/utils/specials-helpers");
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Specials: platform membership of CONSTITUENT items.
|
|
7
|
+
//
|
|
8
|
+
// - The special's own `included_platforms` is the platform gate for the
|
|
9
|
+
// deal. Its items are NOT gated by platform membership: a deal may
|
|
10
|
+
// legitimately feature items that don't belong to the current platform and
|
|
11
|
+
// they are shown and selectable anyway.
|
|
12
|
+
// - INACTIVE items stay excluded. A group whose items are ALL inactive
|
|
13
|
+
// resolves empty and blocks the special (nothing to select); a group with
|
|
14
|
+
// at least one active item keeps the deal, hiding only the inactive ones.
|
|
15
|
+
// - Tenant / schedule checks on the items are unchanged.
|
|
16
|
+
// ============================================================================
|
|
17
|
+
const TENANT_ID = 'tenant-1';
|
|
18
|
+
const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
|
|
19
|
+
const OTHER_PLATFORM = constants_1.PLATFORMS_ENUM.WEB_DELIVERY;
|
|
20
|
+
/**
|
|
21
|
+
* Never-applicable schedule: no days at all, so `findApplicableSchedule`
|
|
22
|
+
* finds no schedule for the current day and returns `false`.
|
|
23
|
+
*/
|
|
24
|
+
function makeScheduledOutHours() {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
days_index: [],
|
|
28
|
+
disabled_outside_date_range: false,
|
|
29
|
+
start_time: 0,
|
|
30
|
+
end_time: 24 * 3600000,
|
|
31
|
+
start_date: null,
|
|
32
|
+
end_date: null,
|
|
33
|
+
price: null,
|
|
34
|
+
is_discount_percentage: false,
|
|
35
|
+
excluded_platforms: [],
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
function makeItem(id, overrides = {}) {
|
|
40
|
+
return {
|
|
41
|
+
_id: id,
|
|
42
|
+
brand_id: 'brand-1',
|
|
43
|
+
tenants: [TENANT_ID],
|
|
44
|
+
category_id: 'pizza-cat',
|
|
45
|
+
included_platforms: [PLATFORM],
|
|
46
|
+
name: `Item ${id}`,
|
|
47
|
+
active: true,
|
|
48
|
+
sold_out: [],
|
|
49
|
+
sort_id: 1,
|
|
50
|
+
image_url: `https://example.com/${id}.jpg`,
|
|
51
|
+
price: { BASE_PRICE: 1000 },
|
|
52
|
+
discount_amount: null,
|
|
53
|
+
is_discount_percentage: false,
|
|
54
|
+
tax_rate: null,
|
|
55
|
+
keywords: [],
|
|
56
|
+
caveats: [],
|
|
57
|
+
dietary_preferences: [],
|
|
58
|
+
hide_name: false,
|
|
59
|
+
description: '',
|
|
60
|
+
ingredients: null,
|
|
61
|
+
is_featured: false,
|
|
62
|
+
featured_sort_id: 0,
|
|
63
|
+
item_special_hours: null,
|
|
64
|
+
display_price: null,
|
|
65
|
+
show_starting_from: false,
|
|
66
|
+
createdAt: new Date('2024-01-01'),
|
|
67
|
+
updatedAt: new Date('2024-01-02'),
|
|
68
|
+
modifiers: null,
|
|
69
|
+
...overrides,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function makeModifierSpecial(overrides = {}) {
|
|
73
|
+
return {
|
|
74
|
+
_id: 'mod-pizza',
|
|
75
|
+
name: 'First Pizza',
|
|
76
|
+
sort_id: 1,
|
|
77
|
+
quantity: 1,
|
|
78
|
+
num_free_items: 0,
|
|
79
|
+
excluded_refs: [],
|
|
80
|
+
exclusive_refs: [],
|
|
81
|
+
omit_items_schedule: false,
|
|
82
|
+
items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
|
|
83
|
+
...overrides,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function makeSpecialWithModifier(overrides = {}) {
|
|
87
|
+
return {
|
|
88
|
+
_id: 'special-1',
|
|
89
|
+
brand_id: 'brand-1',
|
|
90
|
+
tenants: [TENANT_ID],
|
|
91
|
+
category_id: 'combo-cat',
|
|
92
|
+
included_platforms: [PLATFORM],
|
|
93
|
+
name: 'Buy 1 Pizza Get 1 Free',
|
|
94
|
+
description: 'Deal',
|
|
95
|
+
active: true,
|
|
96
|
+
sold_out: [],
|
|
97
|
+
sort_id: 1,
|
|
98
|
+
image_url: 'https://example.com/special.jpg',
|
|
99
|
+
price: { BASE_PRICE: 1500 },
|
|
100
|
+
discount_amount: null,
|
|
101
|
+
is_discount_percentage: false,
|
|
102
|
+
display_price: null,
|
|
103
|
+
show_starting_from: false,
|
|
104
|
+
item_special_hours: null,
|
|
105
|
+
modifier_specials: [makeModifierSpecial()],
|
|
106
|
+
createdAt: new Date('2024-01-01'),
|
|
107
|
+
updatedAt: new Date('2024-01-02'),
|
|
108
|
+
...overrides,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
describe('specials: constituent items are not gated by platform membership', () => {
|
|
112
|
+
it('shows the special when every item of the group is outside the platform', () => {
|
|
113
|
+
const itemsMap = {
|
|
114
|
+
milan: makeItem('milan', { included_platforms: [OTHER_PLATFORM] }),
|
|
115
|
+
};
|
|
116
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
117
|
+
expect(workable).toBeDefined();
|
|
118
|
+
expect(workable.modifier_specials).toHaveLength(1);
|
|
119
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan']);
|
|
120
|
+
// The item keeps its own platform membership — it is shown as-is.
|
|
121
|
+
expect(workable.modifier_specials[0].items[0].included_platforms).toEqual([OTHER_PLATFORM]);
|
|
122
|
+
});
|
|
123
|
+
it('shows out-of-platform items alongside in-platform items', () => {
|
|
124
|
+
const itemsMap = {
|
|
125
|
+
milan: makeItem('milan'),
|
|
126
|
+
torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
|
|
127
|
+
};
|
|
128
|
+
const special = makeSpecialWithModifier({
|
|
129
|
+
modifier_specials: [
|
|
130
|
+
makeModifierSpecial({
|
|
131
|
+
items: [
|
|
132
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
133
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
134
|
+
],
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
139
|
+
expect(workable).toBeDefined();
|
|
140
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan', 'torent']);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe('specials: inactive items still gate the deal', () => {
|
|
144
|
+
it('hides the special when every item of a group is inactive', () => {
|
|
145
|
+
const itemsMap = {
|
|
146
|
+
milan: makeItem('milan', { active: false }),
|
|
147
|
+
torent: makeItem('torent', { active: false }),
|
|
148
|
+
};
|
|
149
|
+
const special = makeSpecialWithModifier({
|
|
150
|
+
modifier_specials: [
|
|
151
|
+
makeModifierSpecial({
|
|
152
|
+
items: [
|
|
153
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
154
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
155
|
+
],
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
160
|
+
expect(workable).toBeUndefined();
|
|
161
|
+
});
|
|
162
|
+
it('hides the special when every item is inactive, regardless of platform membership', () => {
|
|
163
|
+
const itemsMap = {
|
|
164
|
+
milan: makeItem('milan', { active: false }),
|
|
165
|
+
torent: makeItem('torent', { active: false, included_platforms: [OTHER_PLATFORM] }),
|
|
166
|
+
};
|
|
167
|
+
const special = makeSpecialWithModifier({
|
|
168
|
+
modifier_specials: [
|
|
169
|
+
makeModifierSpecial({
|
|
170
|
+
items: [
|
|
171
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
172
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
173
|
+
],
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
178
|
+
expect(workable).toBeUndefined();
|
|
179
|
+
});
|
|
180
|
+
it('keeps the special when only some items are inactive', () => {
|
|
181
|
+
const itemsMap = {
|
|
182
|
+
milan: makeItem('milan', { active: false }),
|
|
183
|
+
torent: makeItem('torent'),
|
|
184
|
+
};
|
|
185
|
+
const special = makeSpecialWithModifier({
|
|
186
|
+
modifier_specials: [
|
|
187
|
+
makeModifierSpecial({
|
|
188
|
+
items: [
|
|
189
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
190
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
191
|
+
],
|
|
192
|
+
}),
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
196
|
+
expect(workable).toBeDefined();
|
|
197
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
|
|
198
|
+
});
|
|
199
|
+
it('keeps the special when an inactive item is mixed with an out-of-platform item', () => {
|
|
200
|
+
const itemsMap = {
|
|
201
|
+
milan: makeItem('milan', { active: false }),
|
|
202
|
+
torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
|
|
203
|
+
};
|
|
204
|
+
const special = makeSpecialWithModifier({
|
|
205
|
+
modifier_specials: [
|
|
206
|
+
makeModifierSpecial({
|
|
207
|
+
items: [
|
|
208
|
+
{ item_id: 'milan', sort_id: 1, upsell_price: null },
|
|
209
|
+
{ item_id: 'torent', sort_id: 2, upsell_price: null },
|
|
210
|
+
],
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
|
|
215
|
+
expect(workable).toBeDefined();
|
|
216
|
+
expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
describe('specials: tenant and schedule checks on items are unchanged', () => {
|
|
220
|
+
it("hides the special when a group's items all belong to another tenant", () => {
|
|
221
|
+
const itemsMap = {
|
|
222
|
+
milan: makeItem('milan', { tenants: ['other-tenant'] }),
|
|
223
|
+
};
|
|
224
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
225
|
+
expect(workable).toBeUndefined();
|
|
226
|
+
});
|
|
227
|
+
it('still filters scheduled-out out-of-platform items from the options (deal kept)', () => {
|
|
228
|
+
const itemsMap = {
|
|
229
|
+
milan: makeItem('milan', {
|
|
230
|
+
included_platforms: [OTHER_PLATFORM],
|
|
231
|
+
item_special_hours: makeScheduledOutHours(),
|
|
232
|
+
}),
|
|
233
|
+
};
|
|
234
|
+
const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
|
|
235
|
+
// The item is outside its own schedule right now -> not selectable, but
|
|
236
|
+
// the special itself stays (its own schedule is the menu-level gate).
|
|
237
|
+
expect(workable).toBeDefined();
|
|
238
|
+
expect(workable.modifier_specials[0].items).toHaveLength(0);
|
|
239
|
+
});
|
|
240
|
+
});
|