@managesome/eposmatic-toolkit 0.3.2 → 0.3.4
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/constants/ORDER.d.ts +11 -0
- package/lib/constants/ORDER.js +13 -1
- package/lib/helpers/store/cart-actions.js +56 -0
- package/lib/helpers/store/common-order-actions.d.ts +1 -0
- package/lib/helpers/store/common-order-actions.js +13 -1
- package/lib/helpers/utils/order-engine.d.ts +1 -1
- package/lib/helpers/utils/order-engine.js +2 -2
- package/lib/tests/offer-apply-helpers.test.js +103 -2
- package/lib/tests/offers-helpers-edit-baseline.test.d.ts +1 -0
- package/lib/tests/offers-helpers-edit-baseline.test.js +367 -0
- package/lib/tests/void-items-with-reason.test.d.ts +1 -0
- package/lib/tests/void-items-with-reason.test.js +82 -0
- package/package.json +1 -1
package/lib/constants/ORDER.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { ORDER_STATUS_ENUM, ORDER_TYPE_ENUM } from './ENUMS';
|
|
2
|
+
/**
|
|
3
|
+
* System-generated void reason stamped on items the offer synchronization
|
|
4
|
+
* removes automatically — for example when an applied offer/reward is no
|
|
5
|
+
* longer qualified/unlocked after the cashier edited the order.
|
|
6
|
+
*
|
|
7
|
+
* The "Auto removed by system" marker identifies the void as automatic. Plain
|
|
8
|
+
* system text only: it must never carry staff attribution ("Permitted By ..." /
|
|
9
|
+
* "Staff uid: ...") — manual override attribution only applies to explicit
|
|
10
|
+
* cashier voids.
|
|
11
|
+
*/
|
|
12
|
+
export declare const OFFER_NO_LONGER_QUALIFIED_VOID_REASON = "Auto removed by system - Offer no longer qualified";
|
|
2
13
|
export interface IOrderStatusColorCode {
|
|
3
14
|
color: string;
|
|
4
15
|
contrast_color: string;
|
package/lib/constants/ORDER.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ORDER_STATUS_BY_ORDER_TYPE = exports.DEFAULT_ORDER_STATUS_COLOR_CODE_MAP = void 0;
|
|
3
|
+
exports.DEFAULT_ORDER_STATUS_BY_ORDER_TYPE = exports.DEFAULT_ORDER_STATUS_COLOR_CODE_MAP = exports.OFFER_NO_LONGER_QUALIFIED_VOID_REASON = void 0;
|
|
4
4
|
const ENUMS_1 = require("./ENUMS");
|
|
5
|
+
// =========================>>>><<<<=========================
|
|
6
|
+
/**
|
|
7
|
+
* System-generated void reason stamped on items the offer synchronization
|
|
8
|
+
* removes automatically — for example when an applied offer/reward is no
|
|
9
|
+
* longer qualified/unlocked after the cashier edited the order.
|
|
10
|
+
*
|
|
11
|
+
* The "Auto removed by system" marker identifies the void as automatic. Plain
|
|
12
|
+
* system text only: it must never carry staff attribution ("Permitted By ..." /
|
|
13
|
+
* "Staff uid: ...") — manual override attribution only applies to explicit
|
|
14
|
+
* cashier voids.
|
|
15
|
+
*/
|
|
16
|
+
exports.OFFER_NO_LONGER_QUALIFIED_VOID_REASON = 'Auto removed by system - Offer no longer qualified';
|
|
5
17
|
exports.DEFAULT_ORDER_STATUS_COLOR_CODE_MAP = {
|
|
6
18
|
[ENUMS_1.ORDER_STATUS_ENUM.UNCONFIRMED]: {
|
|
7
19
|
color: '#727472',
|
|
@@ -1269,6 +1269,11 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1269
1269
|
}
|
|
1270
1270
|
}
|
|
1271
1271
|
}
|
|
1272
|
+
// Items dropped below because their offer/reward is no longer qualified.
|
|
1273
|
+
// The last-synced iteration keeps them with a system-generated void reason
|
|
1274
|
+
// so the removal is traceable and never carries staff name/uid (manual
|
|
1275
|
+
// "Permitted By" attribution only applies to explicit cashier voids).
|
|
1276
|
+
const removedItemsReasonMap = {};
|
|
1272
1277
|
const newCategories = [];
|
|
1273
1278
|
for (let i = 0; i < categories.length; i++) {
|
|
1274
1279
|
const category = categories[i];
|
|
@@ -1285,6 +1290,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1285
1290
|
if (normalizedLoyaltyDiscountId != null) {
|
|
1286
1291
|
removedOfferIds.add(normalizedLoyaltyDiscountId);
|
|
1287
1292
|
}
|
|
1293
|
+
removedItemsReasonMap[item._id] = constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON;
|
|
1288
1294
|
continue;
|
|
1289
1295
|
}
|
|
1290
1296
|
if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
|
|
@@ -1292,6 +1298,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1292
1298
|
if (normalizedLoyaltyDiscountId != null) {
|
|
1293
1299
|
removedOfferIds.add(normalizedLoyaltyDiscountId);
|
|
1294
1300
|
}
|
|
1301
|
+
removedItemsReasonMap[item._id] = constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON;
|
|
1295
1302
|
continue;
|
|
1296
1303
|
}
|
|
1297
1304
|
unlockedOffersMap[loyaltyDiscountId] -= toPositiveInteger(item.quantity, 1);
|
|
@@ -1305,6 +1312,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1305
1312
|
if (normalizedVoucherDiscountId != null) {
|
|
1306
1313
|
removedOfferIds.add(normalizedVoucherDiscountId);
|
|
1307
1314
|
}
|
|
1315
|
+
removedItemsReasonMap[item._id] = constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON;
|
|
1308
1316
|
continue;
|
|
1309
1317
|
}
|
|
1310
1318
|
if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
|
|
@@ -1312,6 +1320,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1312
1320
|
if (normalizedVoucherDiscountId != null) {
|
|
1313
1321
|
removedOfferIds.add(normalizedVoucherDiscountId);
|
|
1314
1322
|
}
|
|
1323
|
+
removedItemsReasonMap[item._id] = constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON;
|
|
1315
1324
|
continue;
|
|
1316
1325
|
}
|
|
1317
1326
|
unlockedOffersMap[voucherDiscountId] -= toPositiveInteger(item.quantity, 1);
|
|
@@ -1338,13 +1347,60 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1338
1347
|
if (!hasChanges) {
|
|
1339
1348
|
return null;
|
|
1340
1349
|
}
|
|
1350
|
+
const syncedIterations = getIterationsWithAutoRemovedVoidReasons({
|
|
1351
|
+
iterations: data.iterations,
|
|
1352
|
+
removedItemsReasonMap,
|
|
1353
|
+
});
|
|
1341
1354
|
return {
|
|
1342
1355
|
...data,
|
|
1356
|
+
...(syncedIterations != null && syncedIterations !== data.iterations ? { iterations: syncedIterations } : {}),
|
|
1343
1357
|
categories: newCategories,
|
|
1344
1358
|
order_discount_details,
|
|
1345
1359
|
redeemed_offers,
|
|
1346
1360
|
};
|
|
1347
1361
|
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Stamp the system-generated void reason on the last-synced iteration items
|
|
1364
|
+
* for items the offer synchronization removed from the live cart.
|
|
1365
|
+
*
|
|
1366
|
+
* Removed items' reasons live on the first iteration (mirrors
|
|
1367
|
+
* `getRemoveItemFromCartData`) so the cart, receipts and the backend
|
|
1368
|
+
* void-items pipeline (`getVoidItemsWithReason`) can surface why the item was
|
|
1369
|
+
* removed. Items that never existed in the last-synced iteration (added during
|
|
1370
|
+
* the current edit) and items that already carry an explicit cashier reason
|
|
1371
|
+
* are left untouched.
|
|
1372
|
+
*/
|
|
1373
|
+
function getIterationsWithAutoRemovedVoidReasons({ iterations, removedItemsReasonMap, }) {
|
|
1374
|
+
if (Object.keys(removedItemsReasonMap).length === 0 || iterations == null || iterations.length === 0) {
|
|
1375
|
+
return iterations;
|
|
1376
|
+
}
|
|
1377
|
+
const [firstIteration, ...restIterations] = iterations;
|
|
1378
|
+
let hasChanges = false;
|
|
1379
|
+
const firstIterationCategories = firstIteration.categories.map((category) => {
|
|
1380
|
+
let categoryHasChanges = false;
|
|
1381
|
+
const items = category.items.map((prevItem) => {
|
|
1382
|
+
const autoVoidReason = removedItemsReasonMap[prevItem._id];
|
|
1383
|
+
if (autoVoidReason == null) {
|
|
1384
|
+
return prevItem;
|
|
1385
|
+
}
|
|
1386
|
+
// Keep an explicit cashier-provided reason when one already exists.
|
|
1387
|
+
if (prevItem.void_reason != null && prevItem.void_reason.length > 0) {
|
|
1388
|
+
return prevItem;
|
|
1389
|
+
}
|
|
1390
|
+
categoryHasChanges = true;
|
|
1391
|
+
hasChanges = true;
|
|
1392
|
+
return {
|
|
1393
|
+
...prevItem,
|
|
1394
|
+
void_reason: autoVoidReason,
|
|
1395
|
+
};
|
|
1396
|
+
});
|
|
1397
|
+
return categoryHasChanges ? { ...category, items } : category;
|
|
1398
|
+
});
|
|
1399
|
+
if (!hasChanges) {
|
|
1400
|
+
return iterations;
|
|
1401
|
+
}
|
|
1402
|
+
return [{ ...firstIteration, categories: firstIterationCategories }, ...restIterations];
|
|
1403
|
+
}
|
|
1348
1404
|
function hasItemLevelLoyaltyDiscountForId(categories, discountId) {
|
|
1349
1405
|
for (let categoryIndex = 0; categoryIndex < categories.length; categoryIndex++) {
|
|
1350
1406
|
const items = categories[categoryIndex].items;
|
|
@@ -32,6 +32,7 @@ export declare function getVoidItemsWithReason({ currentCategories, iterationsFr
|
|
|
32
32
|
newIterationCategories: IOrderCategory[];
|
|
33
33
|
voidOrderItems: IOrderItem[];
|
|
34
34
|
hasNewItems: boolean;
|
|
35
|
+
hasMissingVoidReason: boolean;
|
|
35
36
|
};
|
|
36
37
|
export declare function getSplitOrdersFromOrder(order: IOrder, splitBill: ISplitBill): IOrder[];
|
|
37
38
|
export {};
|
|
@@ -440,10 +440,17 @@ function getVoidItemsWithReason({ currentCategories, iterationsFromFrontend, pre
|
|
|
440
440
|
const hasNewItems = newItems.length > 0;
|
|
441
441
|
const voidOrderItems = [];
|
|
442
442
|
const newVoidOrderItemReasonsMap = {};
|
|
443
|
+
// A removed item with no non-empty `void_reason` in the latest frontend
|
|
444
|
+
// iteration falls back to the '-' placeholder on voidOrderItems below.
|
|
445
|
+
// Surface it so callers can reject reasonless voids before persisting.
|
|
446
|
+
let hasMissingVoidReason = false;
|
|
443
447
|
for (let i = 0; i < removedItems.length; i++) {
|
|
444
448
|
const { orderItem } = removedItems[i];
|
|
445
449
|
const voidReason = voidOrderItemReasonsMap[orderItem._id];
|
|
446
450
|
const isReady = voidOrderItemIsReadyMap[orderItem._id];
|
|
451
|
+
if (voidReason == null) {
|
|
452
|
+
hasMissingVoidReason = true;
|
|
453
|
+
}
|
|
447
454
|
voidOrderItems.push({
|
|
448
455
|
...orderItem,
|
|
449
456
|
...(isReady != null ? { is_ready: isReady } : {}),
|
|
@@ -481,7 +488,12 @@ function getVoidItemsWithReason({ currentCategories, iterationsFromFrontend, pre
|
|
|
481
488
|
items: newCategoryItems,
|
|
482
489
|
});
|
|
483
490
|
}
|
|
484
|
-
return {
|
|
491
|
+
return {
|
|
492
|
+
newIterationCategories,
|
|
493
|
+
voidOrderItems,
|
|
494
|
+
hasNewItems,
|
|
495
|
+
hasMissingVoidReason,
|
|
496
|
+
};
|
|
485
497
|
}
|
|
486
498
|
// ======================>Split Bill<======================
|
|
487
499
|
function syncDineinCoursesOnSplit(dinein_details, swapedItemIdsMap, totalChecks, isLastCheck) {
|
|
@@ -160,7 +160,7 @@ export declare function convertCatalogItemToOrderEngineItem({ item, orderItem, p
|
|
|
160
160
|
export declare function hasRequiredModifier<T extends IModifier | IOrderEngineModifier>(currentModifiers: T[] | null): boolean;
|
|
161
161
|
export declare function convertItemToOrderItem(item: IItem | ISimplifiedCatalogItem, menu_id: string | null, platform: PLATFORMS_ENUM | undefined, tenantId: string, orderItemType?: ORDER_ITEM_TYPE_ENUM): IOrderItem;
|
|
162
162
|
export declare function setCheckFieldInOrderEngineItem(orderEngineItem: IOrderEngineItem, identifier: string, shouldCheck: boolean, chooseExpensiveSegmentPrice?: boolean): IOrderEngineItem;
|
|
163
|
-
export declare function setIncrementOrderEngineItemQuantity(orderEngineItem: IOrderEngineItem, increment: number): IOrderEngineItem;
|
|
163
|
+
export declare function setIncrementOrderEngineItemQuantity(orderEngineItem: IOrderEngineItem, increment: number, isAbs?: boolean): IOrderEngineItem;
|
|
164
164
|
export declare function setUpdateSelectedOrderEngineOptionQuantity(orderEngineItem: IOrderEngineItem, identifier: string, newQuantity: number, isIncrement?: boolean): IOrderEngineItem;
|
|
165
165
|
export declare function getFlattenedOrderEngineItemModifiers(modifiers: IOrderEngineModifier[], keepOptionalModifiersAtBottom?: boolean): IOrderEngineModifier[];
|
|
166
166
|
export {};
|
|
@@ -1298,8 +1298,8 @@ function setCheckFieldInOrderEngineItem(orderEngineItem, identifier, shouldCheck
|
|
|
1298
1298
|
void chooseExpensiveSegmentPrice;
|
|
1299
1299
|
return updatedOrderEngineItem;
|
|
1300
1300
|
}
|
|
1301
|
-
function setIncrementOrderEngineItemQuantity(orderEngineItem, increment) {
|
|
1302
|
-
const newQuantity = increment + orderEngineItem.quantity;
|
|
1301
|
+
function setIncrementOrderEngineItemQuantity(orderEngineItem, increment, isAbs) {
|
|
1302
|
+
const newQuantity = isAbs ? Math.abs(increment) : increment + orderEngineItem.quantity;
|
|
1303
1303
|
const item_discount_details = (0, store_1.getItemQuantityChangeResults)({
|
|
1304
1304
|
newQuantity,
|
|
1305
1305
|
prevQuantity: orderEngineItem.quantity,
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
3
4
|
const cart_actions_1 = require("../helpers/store/cart-actions");
|
|
4
5
|
const offer_apply_helpers_1 = require("../helpers/utils/offer-apply-helpers");
|
|
5
6
|
const OFFER_ID = 'offer-reward-threshold';
|
|
6
7
|
const POST_ORDER_REWARD_TYPES = ['POINTS', 'CASHBACK', 'VOUCHER', 'GIFT_CARDS'];
|
|
7
|
-
function makeCategories({ itemDiscountDetails = null, quantity = 1, subtotal = 699, } = {}) {
|
|
8
|
+
function makeCategories({ itemDiscountDetails = null, quantity = 1, subtotal = 699, itemId = 'cart-item-1', voidReason = undefined, } = {}) {
|
|
8
9
|
return [
|
|
9
10
|
{
|
|
10
11
|
category_id: 'category-pizza',
|
|
11
12
|
items: [
|
|
12
13
|
{
|
|
13
|
-
_id:
|
|
14
|
+
_id: itemId,
|
|
14
15
|
item_id: 'item-classic-euro',
|
|
15
16
|
name: 'Classic Euro',
|
|
16
17
|
quantity,
|
|
17
18
|
subtotal,
|
|
18
19
|
modifiers: [],
|
|
19
20
|
item_discount_details: itemDiscountDetails,
|
|
21
|
+
...(voidReason != null ? { void_reason: voidReason } : {}),
|
|
20
22
|
},
|
|
21
23
|
],
|
|
22
24
|
},
|
|
@@ -108,3 +110,102 @@ describe('offer redeemed_offers sync', () => {
|
|
|
108
110
|
expect(result.redeemed_offers?.[OFFER_ID]).toBe(1);
|
|
109
111
|
});
|
|
110
112
|
});
|
|
113
|
+
describe('offer sync auto-removed items void reason', () => {
|
|
114
|
+
const getFlatItems = (categories) => (categories ?? []).flatMap((category) => category.items ?? []);
|
|
115
|
+
const makeIteration = (categories) => [{ categories }];
|
|
116
|
+
it('stamps the auto void reason on the last iteration when a de-qualified item reward is removed', () => {
|
|
117
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
118
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
119
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
120
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails })),
|
|
121
|
+
}), [], {}, {}, [makeOffer('ITEMS')]);
|
|
122
|
+
expect(getFlatItems(result.categories)).toHaveLength(0);
|
|
123
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBe(constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON);
|
|
124
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toContain('Auto removed by system');
|
|
125
|
+
});
|
|
126
|
+
it('stamps the auto void reason when the item reward evidence is gone', () => {
|
|
127
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
128
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
129
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
130
|
+
redeemed_offers: null,
|
|
131
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails })),
|
|
132
|
+
}), [], {}, { [OFFER_ID]: 1 }, [makeOffer('POINTS')]);
|
|
133
|
+
expect(getFlatItems(result.categories)).toHaveLength(0);
|
|
134
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBe(constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON);
|
|
135
|
+
});
|
|
136
|
+
it('does not stamp a void reason while the offer item remains qualified', () => {
|
|
137
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
138
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
139
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
140
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails })),
|
|
141
|
+
}), [], {}, { [OFFER_ID]: 1 }, [makeOffer('ITEMS')]);
|
|
142
|
+
expect(getFlatItems(result.categories)).toHaveLength(1);
|
|
143
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
it('does not stamp reasons for removed items that are not part of the last iteration', () => {
|
|
146
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
147
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
148
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
149
|
+
iterations: makeIteration(makeCategories({ itemId: 'cart-item-2' })),
|
|
150
|
+
}), [], {}, {}, [makeOffer('ITEMS')]);
|
|
151
|
+
expect(getFlatItems(result.categories)).toHaveLength(0);
|
|
152
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
it('preserves an explicit cashier reason already present on the last iteration item', () => {
|
|
155
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
156
|
+
const explicitReason = 'Quality Issue - Food quality not up to standard';
|
|
157
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
158
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
159
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails, voidReason: explicitReason })),
|
|
160
|
+
}), [], {}, {}, [makeOffer('ITEMS')]);
|
|
161
|
+
expect(getFlatItems(result.categories)).toHaveLength(0);
|
|
162
|
+
expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBe(explicitReason);
|
|
163
|
+
});
|
|
164
|
+
it('clears the stamped reason when the same item is added back (redo/replace) after re-qualifying', () => {
|
|
165
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
166
|
+
// Offer de-qualifies: sync removes the item and stamps the auto reason.
|
|
167
|
+
const dropped = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
168
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
169
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails })),
|
|
170
|
+
}), [], {}, {}, [makeOffer('ITEMS')]);
|
|
171
|
+
const removedItem = getFlatItems(dropped.iterations?.[0]?.categories)[0];
|
|
172
|
+
expect(removedItem?.void_reason).toBe(constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON);
|
|
173
|
+
// Cart redo/replace re-adds the exact removed line (same _id, item object
|
|
174
|
+
// still carries the auto reason).
|
|
175
|
+
const restored = (0, cart_actions_1.getAddItemToCartData)(dropped, {
|
|
176
|
+
category_id: 'category-pizza',
|
|
177
|
+
name: 'Pizza',
|
|
178
|
+
item: removedItem,
|
|
179
|
+
chosen_course_id: null,
|
|
180
|
+
replace_id: removedItem._id,
|
|
181
|
+
}, [], {});
|
|
182
|
+
const restoredItems = getFlatItems(restored.categories);
|
|
183
|
+
expect(restoredItems).toHaveLength(1);
|
|
184
|
+
expect(restoredItems[0]._id).toBe('cart-item-1');
|
|
185
|
+
expect(restoredItems[0].void_reason).toBeUndefined();
|
|
186
|
+
expect(getFlatItems(restored.iterations?.[0]?.categories)[0]?.void_reason).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
it('keeps the removed line void reason when the reward is re-added as a new line', () => {
|
|
189
|
+
const itemDiscountDetails = { loyalty_discount_id: OFFER_ID };
|
|
190
|
+
const dropped = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
191
|
+
categories: makeCategories({ itemDiscountDetails }),
|
|
192
|
+
iterations: makeIteration(makeCategories({ itemDiscountDetails })),
|
|
193
|
+
}), [], {}, {}, [makeOffer('ITEMS')]);
|
|
194
|
+
const restored = (0, cart_actions_1.getAddItemToCartData)(dropped, {
|
|
195
|
+
category_id: 'category-pizza',
|
|
196
|
+
name: 'Pizza',
|
|
197
|
+
item: {
|
|
198
|
+
...getFlatItems(dropped.iterations?.[0]?.categories)[0],
|
|
199
|
+
_id: 'cart-item-3',
|
|
200
|
+
item_discount_details: itemDiscountDetails,
|
|
201
|
+
},
|
|
202
|
+
chosen_course_id: null,
|
|
203
|
+
}, [], {});
|
|
204
|
+
const restoredItems = getFlatItems(restored.categories);
|
|
205
|
+
expect(restoredItems).toHaveLength(1);
|
|
206
|
+
expect(restoredItems[0]._id).toBe('cart-item-3');
|
|
207
|
+
expect(restoredItems[0].void_reason).toBeUndefined();
|
|
208
|
+
// The original line stays removed and keeps its auto reason for the void record.
|
|
209
|
+
expect(getFlatItems(restored.iterations?.[0]?.categories)[0]?.void_reason).toBe(constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const offers_helpers_1 = require("../helpers/utils/offers-helpers");
|
|
5
|
+
const OFFER_ID = 'offer-free-burger';
|
|
6
|
+
const BURGER_ITEM_ID = 'item-burger';
|
|
7
|
+
function makeCategories(subtotal = 2000) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
category_id: 'category-pizza',
|
|
11
|
+
items: [
|
|
12
|
+
{
|
|
13
|
+
_id: 'cart-item-1',
|
|
14
|
+
item_id: 'item-classic',
|
|
15
|
+
name: 'Classic',
|
|
16
|
+
quantity: 1,
|
|
17
|
+
subtotal,
|
|
18
|
+
modifiers: [],
|
|
19
|
+
item_discount_details: null,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
category_id: 'category-burger',
|
|
25
|
+
items: [
|
|
26
|
+
{
|
|
27
|
+
_id: 'cart-item-burger',
|
|
28
|
+
item_id: BURGER_ITEM_ID,
|
|
29
|
+
name: 'Chicken Burger',
|
|
30
|
+
quantity: 1,
|
|
31
|
+
subtotal: 0,
|
|
32
|
+
modifiers: [],
|
|
33
|
+
item_discount_details: {
|
|
34
|
+
loyalty_discount: 100,
|
|
35
|
+
loyalty_discount_id: OFFER_ID,
|
|
36
|
+
loyalty_discount_name: 'Free Chicken Burger on First order over 1500',
|
|
37
|
+
is_loyalty_discount_percentage: true,
|
|
38
|
+
loyalty_discount_reason: 'Free Chicken Burger on First order over 1500',
|
|
39
|
+
total_discount: 360,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
function makeFreeBurgerOffer(maxUsesPerCustomer = 1) {
|
|
47
|
+
return {
|
|
48
|
+
_id: OFFER_ID,
|
|
49
|
+
name: 'Free Chicken Burger on First order over 1500',
|
|
50
|
+
active: true,
|
|
51
|
+
auto_apply: true,
|
|
52
|
+
sort_id: 1,
|
|
53
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY],
|
|
54
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
55
|
+
pathway_to_unlock_type_orders: {
|
|
56
|
+
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
57
|
+
min_num_of_orders: 0,
|
|
58
|
+
max_num_of_orders: null,
|
|
59
|
+
total_amount: 1500,
|
|
60
|
+
max_amount: null,
|
|
61
|
+
orders_between_unlocks: null,
|
|
62
|
+
max_claims: 10000,
|
|
63
|
+
max_uses_per_customer: maxUsesPerCustomer,
|
|
64
|
+
},
|
|
65
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
66
|
+
reward_items: {
|
|
67
|
+
num_of_items: 1,
|
|
68
|
+
excluded_refs: [],
|
|
69
|
+
exclusive_refs: [],
|
|
70
|
+
item_ids: [BURGER_ITEM_ID],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function makeUsedCounts(usedTimes) {
|
|
75
|
+
return {
|
|
76
|
+
[constants_1.CUSTOMER_REDEMPTION_TYPE_ENUM.USED]: { [OFFER_ID]: usedTimes },
|
|
77
|
+
[constants_1.CUSTOMER_REDEMPTION_TYPE_ENUM.ASSIGNED]: {},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function runStats(options = {}) {
|
|
81
|
+
return (0, offers_helpers_1.getOffersWithStats)({
|
|
82
|
+
offers: [makeFreeBurgerOffer(options.maxUsesPerCustomer ?? 1)],
|
|
83
|
+
customer: { total_orders: 1, loyalty_points: 0 },
|
|
84
|
+
vouchers: [],
|
|
85
|
+
giftCards: [],
|
|
86
|
+
customerOfferRedemptionCounts: options.counts === undefined ? makeUsedCounts(1) : options.counts,
|
|
87
|
+
redeemed_offers: { [OFFER_ID]: 1 },
|
|
88
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY,
|
|
89
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.$,
|
|
90
|
+
categories: makeCategories(options.orderValue),
|
|
91
|
+
currentItemsPrice: options.orderValue ?? 2000,
|
|
92
|
+
totalDiscountApplied: 0,
|
|
93
|
+
order_discount_details: null,
|
|
94
|
+
isEdit: options.isEdit,
|
|
95
|
+
editedOrderRedeemedOffers: options.editedOrderRedeemedOffers,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
describe('getOffersWithStats — edited-order redemption baseline', () => {
|
|
99
|
+
it('keeps an applied item reward when editing the order that consumed it', () => {
|
|
100
|
+
const result = runStats({
|
|
101
|
+
counts: makeUsedCounts(1),
|
|
102
|
+
isEdit: true,
|
|
103
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
|
|
104
|
+
});
|
|
105
|
+
const { stats } = result.offersWithStats[0];
|
|
106
|
+
expect(stats.redeemed_times).toBe(1);
|
|
107
|
+
expect(stats.applicable_quantity).toBe(1);
|
|
108
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
109
|
+
expect(stats.message).toContain('redeemed');
|
|
110
|
+
expect(stats.message).not.toContain('personal limit');
|
|
111
|
+
});
|
|
112
|
+
it('still exhausts the offer on a new order when the customer already used it', () => {
|
|
113
|
+
const result = runStats({ counts: makeUsedCounts(1) });
|
|
114
|
+
const { stats } = result.offersWithStats[0];
|
|
115
|
+
expect(stats.applicable_quantity).toBe(0);
|
|
116
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
117
|
+
expect(stats.message).toContain('personal limit');
|
|
118
|
+
});
|
|
119
|
+
it('still exhausts the offer when editing an order with no baseline claim for it', () => {
|
|
120
|
+
const result = runStats({
|
|
121
|
+
counts: makeUsedCounts(1),
|
|
122
|
+
isEdit: true,
|
|
123
|
+
editedOrderRedeemedOffers: {},
|
|
124
|
+
});
|
|
125
|
+
const { stats } = result.offersWithStats[0];
|
|
126
|
+
expect(stats.applicable_quantity).toBe(0);
|
|
127
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
128
|
+
expect(stats.message).toContain('personal limit');
|
|
129
|
+
});
|
|
130
|
+
it('keeps the previous behavior when isEdit is set but no baseline snapshot is provided', () => {
|
|
131
|
+
const result = runStats({ counts: makeUsedCounts(1), isEdit: true });
|
|
132
|
+
const { stats } = result.offersWithStats[0];
|
|
133
|
+
expect(stats.applicable_quantity).toBe(0);
|
|
134
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
135
|
+
expect(stats.message).toContain('personal limit');
|
|
136
|
+
});
|
|
137
|
+
it('preserves the claim while counts are unknown if the edited order carried it', () => {
|
|
138
|
+
const result = runStats({
|
|
139
|
+
counts: null,
|
|
140
|
+
isEdit: true,
|
|
141
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
|
|
142
|
+
});
|
|
143
|
+
const { stats } = result.offersWithStats[0];
|
|
144
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
145
|
+
expect(stats.message).not.toContain('personal limit');
|
|
146
|
+
});
|
|
147
|
+
it('stays fail-closed on unknown counts without baseline evidence', () => {
|
|
148
|
+
const result = runStats({
|
|
149
|
+
counts: null,
|
|
150
|
+
isEdit: true,
|
|
151
|
+
editedOrderRedeemedOffers: {},
|
|
152
|
+
});
|
|
153
|
+
const { stats } = result.offersWithStats[0];
|
|
154
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
155
|
+
expect(stats.message).toContain('personal limit');
|
|
156
|
+
});
|
|
157
|
+
it("subtracts only the edited order's own claims from the lifetime count", () => {
|
|
158
|
+
const result = runStats({
|
|
159
|
+
counts: makeUsedCounts(2),
|
|
160
|
+
isEdit: true,
|
|
161
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
|
|
162
|
+
maxUsesPerCustomer: 2,
|
|
163
|
+
});
|
|
164
|
+
const { stats } = result.offersWithStats[0];
|
|
165
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
166
|
+
expect(stats.message).not.toContain('personal limit');
|
|
167
|
+
});
|
|
168
|
+
it('still exhausts when other orders consumed the full lifetime budget', () => {
|
|
169
|
+
const result = runStats({
|
|
170
|
+
counts: makeUsedCounts(2),
|
|
171
|
+
isEdit: true,
|
|
172
|
+
editedOrderRedeemedOffers: {},
|
|
173
|
+
maxUsesPerCustomer: 2,
|
|
174
|
+
});
|
|
175
|
+
const { stats } = result.offersWithStats[0];
|
|
176
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
177
|
+
expect(stats.message).toContain('personal limit');
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe('getOffersWithStats — remaining-budget clamp (Q1)', () => {
|
|
181
|
+
it('caps multi-chunk session claims at the remaining budget (counts known)', () => {
|
|
182
|
+
const result = runStats({
|
|
183
|
+
counts: makeUsedCounts(1),
|
|
184
|
+
isEdit: true,
|
|
185
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
|
|
186
|
+
orderValue: 4000,
|
|
187
|
+
maxUsesPerCustomer: 1,
|
|
188
|
+
});
|
|
189
|
+
// Two spend chunks unlock, but the customer's budget is a single use.
|
|
190
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
191
|
+
expect(result.offersWithStats[0].stats.message).not.toContain('personal limit');
|
|
192
|
+
});
|
|
193
|
+
it('caps multi-chunk session claims while counts are unknown (hold window)', () => {
|
|
194
|
+
const result = runStats({
|
|
195
|
+
counts: null,
|
|
196
|
+
isEdit: true,
|
|
197
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
|
|
198
|
+
orderValue: 4000,
|
|
199
|
+
maxUsesPerCustomer: 1,
|
|
200
|
+
});
|
|
201
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
202
|
+
expect(result.offersWithStats[0].stats.message).not.toContain('personal limit');
|
|
203
|
+
});
|
|
204
|
+
it('reduces multi-chunk claims to the remaining budget', () => {
|
|
205
|
+
const result = runStats({
|
|
206
|
+
counts: makeUsedCounts(1),
|
|
207
|
+
orderValue: 4000,
|
|
208
|
+
maxUsesPerCustomer: 2,
|
|
209
|
+
});
|
|
210
|
+
// Two chunks available, one lifetime use left.
|
|
211
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
212
|
+
});
|
|
213
|
+
it('does not clamp below the per-order claims while budget remains', () => {
|
|
214
|
+
const result = runStats({
|
|
215
|
+
counts: makeUsedCounts(0),
|
|
216
|
+
orderValue: 4000,
|
|
217
|
+
maxUsesPerCustomer: 3,
|
|
218
|
+
});
|
|
219
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(2);
|
|
220
|
+
});
|
|
221
|
+
it('ignores non-numeric baseline counts and stays fail-closed', () => {
|
|
222
|
+
const result = runStats({
|
|
223
|
+
counts: makeUsedCounts(2),
|
|
224
|
+
isEdit: true,
|
|
225
|
+
editedOrderRedeemedOffers: { [OFFER_ID]: 'abc' },
|
|
226
|
+
maxUsesPerCustomer: 2,
|
|
227
|
+
});
|
|
228
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
229
|
+
expect(result.offersWithStats[0].stats.message).toContain('personal limit');
|
|
230
|
+
});
|
|
231
|
+
it('normalizes whitespace-padded baseline keys and string counts', () => {
|
|
232
|
+
const result = runStats({
|
|
233
|
+
counts: makeUsedCounts(2),
|
|
234
|
+
isEdit: true,
|
|
235
|
+
editedOrderRedeemedOffers: { ' offer-free-burger ': '1' },
|
|
236
|
+
maxUsesPerCustomer: 2,
|
|
237
|
+
});
|
|
238
|
+
// Baseline subtracts one use: budget = 2 − (2 − 1) = 1.
|
|
239
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
function makePathwayOffer(pathway) {
|
|
243
|
+
const base = {
|
|
244
|
+
_id: OFFER_ID,
|
|
245
|
+
name: 'Pathway reward',
|
|
246
|
+
active: true,
|
|
247
|
+
auto_apply: true,
|
|
248
|
+
sort_id: 1,
|
|
249
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY],
|
|
250
|
+
pathway_to_unlock_type: pathway,
|
|
251
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
252
|
+
reward_items: {
|
|
253
|
+
num_of_items: 1,
|
|
254
|
+
excluded_refs: [],
|
|
255
|
+
exclusive_refs: [],
|
|
256
|
+
item_ids: [BURGER_ITEM_ID],
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
if (pathway === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS) {
|
|
260
|
+
return {
|
|
261
|
+
...base,
|
|
262
|
+
pathway_to_unlock_type_orders: {
|
|
263
|
+
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
264
|
+
min_num_of_orders: 0,
|
|
265
|
+
max_num_of_orders: null,
|
|
266
|
+
total_amount: 1500,
|
|
267
|
+
max_amount: null,
|
|
268
|
+
orders_between_unlocks: null,
|
|
269
|
+
max_claims: 2,
|
|
270
|
+
max_uses_per_customer: 1,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (pathway === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS) {
|
|
275
|
+
return {
|
|
276
|
+
...base,
|
|
277
|
+
pathway_to_unlock_type_orders: null,
|
|
278
|
+
pathway_to_unlock_type_items: {
|
|
279
|
+
num_of_items: 1,
|
|
280
|
+
max_uses_per_customer: 1,
|
|
281
|
+
max_claims: 2,
|
|
282
|
+
min_same_item_quantity: null,
|
|
283
|
+
max_same_item_quantity: null,
|
|
284
|
+
total_amount: null,
|
|
285
|
+
excluded_refs: [],
|
|
286
|
+
exclusive_refs: [],
|
|
287
|
+
item_ids: ['item-classic'],
|
|
288
|
+
category_ids: [],
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (pathway === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS) {
|
|
293
|
+
return {
|
|
294
|
+
...base,
|
|
295
|
+
pathway_to_unlock_type_orders: null,
|
|
296
|
+
pathway_to_unlock_type_points: {
|
|
297
|
+
num_of_points: 100,
|
|
298
|
+
total_amount: null,
|
|
299
|
+
max_uses_per_customer: 1,
|
|
300
|
+
max_claims: 2,
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
...base,
|
|
306
|
+
pathway_to_unlock_type_orders: null,
|
|
307
|
+
pathway_to_unlock_type_vouchers: {
|
|
308
|
+
total_amount: 1500,
|
|
309
|
+
max_amount: null,
|
|
310
|
+
max_uses_per_customer: 1,
|
|
311
|
+
max_claims: 2,
|
|
312
|
+
voucher_ids: ['voucher-v'],
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const PATHWAY_CASES = [
|
|
317
|
+
{ pathway: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS },
|
|
318
|
+
{ pathway: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS },
|
|
319
|
+
{ pathway: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS, customer: { total_orders: 1, loyalty_points: 500 } },
|
|
320
|
+
{
|
|
321
|
+
pathway: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
322
|
+
customer: { total_orders: 1, loyalty_points: 0, voucher_codes: { VV: 1 } },
|
|
323
|
+
vouchers: [
|
|
324
|
+
{
|
|
325
|
+
_id: 'voucher-v',
|
|
326
|
+
code: 'VV',
|
|
327
|
+
active: true,
|
|
328
|
+
max_uses: 100,
|
|
329
|
+
used_count: 0,
|
|
330
|
+
max_uses_per_customer: null,
|
|
331
|
+
expire_at: null,
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
function runPathwayStats({ pathwayCase, isEdit, baseline, }) {
|
|
337
|
+
return (0, offers_helpers_1.getOffersWithStats)({
|
|
338
|
+
offers: [makePathwayOffer(pathwayCase.pathway)],
|
|
339
|
+
customer: pathwayCase.customer ?? { total_orders: 1, loyalty_points: 0 },
|
|
340
|
+
vouchers: (pathwayCase.vouchers ?? []),
|
|
341
|
+
giftCards: [],
|
|
342
|
+
customerOfferRedemptionCounts: makeUsedCounts(1),
|
|
343
|
+
redeemed_offers: { [OFFER_ID]: 1 },
|
|
344
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY,
|
|
345
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.$,
|
|
346
|
+
categories: makeCategories(),
|
|
347
|
+
currentItemsPrice: 2000,
|
|
348
|
+
totalDiscountApplied: 0,
|
|
349
|
+
order_discount_details: null,
|
|
350
|
+
isEdit,
|
|
351
|
+
editedOrderRedeemedOffers: baseline,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
describe('getOffersWithStats — baseline exemption across all pathway gates', () => {
|
|
355
|
+
test.each(PATHWAY_CASES.map((pathwayCase) => [pathwayCase.pathway, pathwayCase]))('%s pathway keeps the edited order claim with a baseline and blocks it on a new order', (_pathway, pathwayCase) => {
|
|
356
|
+
const edited = runPathwayStats({
|
|
357
|
+
pathwayCase,
|
|
358
|
+
isEdit: true,
|
|
359
|
+
baseline: { [OFFER_ID]: 1 },
|
|
360
|
+
});
|
|
361
|
+
expect(edited.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
362
|
+
expect(edited.offersWithStats[0].stats.message).not.toContain('personal limit');
|
|
363
|
+
const fresh = runPathwayStats({ pathwayCase });
|
|
364
|
+
expect(fresh.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
|
|
365
|
+
expect(fresh.offersWithStats[0].stats.message).toContain('personal limit');
|
|
366
|
+
});
|
|
367
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_order_actions_1 = require("../helpers/store/common-order-actions");
|
|
4
|
+
const ENUMS_1 = require("../constants/ENUMS");
|
|
5
|
+
function makeItem(params) {
|
|
6
|
+
return {
|
|
7
|
+
_id: params._id,
|
|
8
|
+
item_id: `item-${params._id}`,
|
|
9
|
+
name: `Item ${params._id}`,
|
|
10
|
+
price: 100,
|
|
11
|
+
quantity: 1,
|
|
12
|
+
subtotal: 100,
|
|
13
|
+
items_price: 100,
|
|
14
|
+
modifiers: [],
|
|
15
|
+
...(params.void_reason != null ? { void_reason: params.void_reason } : {}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function makeCategory(items) {
|
|
19
|
+
return { category_id: 'c1', name: 'Category', items };
|
|
20
|
+
}
|
|
21
|
+
function getVoidResult(params) {
|
|
22
|
+
return (0, common_order_actions_1.getVoidItemsWithReason)({
|
|
23
|
+
currentCategories: [makeCategory(params.currentItems)],
|
|
24
|
+
previousCategories: [makeCategory(params.previousItems)],
|
|
25
|
+
iterationsFromFrontend: [{ categories: [makeCategory(params.latestIterationItems)] }],
|
|
26
|
+
platform: ENUMS_1.PLATFORMS_ENUM.POS_TAKE_AWAY,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
describe('getVoidItemsWithReason - hasMissingVoidReason', () => {
|
|
30
|
+
it('is false and carries the reason when the latest iteration has one', () => {
|
|
31
|
+
const removedItem = makeItem({ _id: 'removed-1' });
|
|
32
|
+
const keptItem = makeItem({ _id: 'kept-1' });
|
|
33
|
+
const result = getVoidResult({
|
|
34
|
+
currentItems: [keptItem],
|
|
35
|
+
previousItems: [removedItem, keptItem],
|
|
36
|
+
latestIterationItems: [{ ...removedItem, void_reason: 'Wrong order' }, keptItem],
|
|
37
|
+
});
|
|
38
|
+
expect(result.voidOrderItems).toHaveLength(1);
|
|
39
|
+
expect(result.voidOrderItems[0]._id).toBe('removed-1');
|
|
40
|
+
expect(result.voidOrderItems[0].void_reason).toBe('Wrong order');
|
|
41
|
+
expect(result.hasMissingVoidReason).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
it('is true and applies the "-" placeholder when no reason was sent', () => {
|
|
44
|
+
const removedItem = makeItem({ _id: 'removed-1' });
|
|
45
|
+
const keptItem = makeItem({ _id: 'kept-1' });
|
|
46
|
+
const result = getVoidResult({
|
|
47
|
+
currentItems: [keptItem],
|
|
48
|
+
previousItems: [removedItem, keptItem],
|
|
49
|
+
latestIterationItems: [removedItem, keptItem],
|
|
50
|
+
});
|
|
51
|
+
expect(result.voidOrderItems).toHaveLength(1);
|
|
52
|
+
expect(result.voidOrderItems[0].void_reason).toBe('-');
|
|
53
|
+
expect(result.hasMissingVoidReason).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
it('is true when only one of multiple removed items has a reason', () => {
|
|
56
|
+
const removedWithReason = makeItem({ _id: 'removed-1' });
|
|
57
|
+
const removedWithoutReason = makeItem({ _id: 'removed-2' });
|
|
58
|
+
const keptItem = makeItem({ _id: 'kept-1' });
|
|
59
|
+
const result = getVoidResult({
|
|
60
|
+
currentItems: [keptItem],
|
|
61
|
+
previousItems: [removedWithReason, removedWithoutReason, keptItem],
|
|
62
|
+
latestIterationItems: [
|
|
63
|
+
{ ...removedWithReason, void_reason: 'Customer changed mind' },
|
|
64
|
+
removedWithoutReason,
|
|
65
|
+
keptItem,
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
expect(result.voidOrderItems).toHaveLength(2);
|
|
69
|
+
expect(result.hasMissingVoidReason).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
it('is false when nothing was removed', () => {
|
|
72
|
+
const keptItem = makeItem({ _id: 'kept-1' });
|
|
73
|
+
const result = getVoidResult({
|
|
74
|
+
currentItems: [keptItem],
|
|
75
|
+
previousItems: [keptItem],
|
|
76
|
+
latestIterationItems: [keptItem],
|
|
77
|
+
});
|
|
78
|
+
expect(result.voidOrderItems).toHaveLength(0);
|
|
79
|
+
expect(result.hasNewItems).toBe(false);
|
|
80
|
+
expect(result.hasMissingVoidReason).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
});
|