@managesome/eposmatic-toolkit 0.2.761 → 0.2.762
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.
|
@@ -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
|
+
});
|