@managesome/eposmatic-toolkit 0.2.755 → 0.2.756
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.d.ts +0 -7
- package/lib/helpers/store/cart-actions.js +2 -30
- package/lib/helpers/utils/common.d.ts +11 -0
- package/lib/helpers/utils/common.js +30 -0
- package/lib/helpers/utils/offer-apply-helpers.js +4 -4
- package/lib/helpers/utils/offers-helpers.js +55 -11
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/tenant_order_item_instructions.d.ts +62 -0
- package/lib/schemas/models/tenant_order_item_instructions.js +69 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/tenant_order_item_instructions.d.ts +10 -0
- package/lib/schemas/types/tenant_order_item_instructions.js +2 -0
- package/lib/tests/offers-helpers.test.js +601 -2
- package/package.json +1 -1
|
@@ -230,11 +230,4 @@ export declare function getClearVoucherCodeAndOffersFromCartData(data: Partial<I
|
|
|
230
230
|
* `order_discount_details`.
|
|
231
231
|
*/
|
|
232
232
|
export declare function getResetRewardStateForNewCustomer(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
233
|
-
/**
|
|
234
|
-
* Calculate the eligible subtotal by excluding items/categories in excluded_refs
|
|
235
|
-
*/
|
|
236
|
-
export declare function calculateEligibleOfferDiscountDetails(categories: IOrderCategory[] | undefined, excluded_refs: string[]): {
|
|
237
|
-
subtotal: number;
|
|
238
|
-
hasExcludedRefs: boolean;
|
|
239
|
-
};
|
|
240
233
|
export {};
|
|
@@ -31,7 +31,6 @@ exports.getRemoveOfferFromCartData = getRemoveOfferFromCartData;
|
|
|
31
31
|
exports.getRemoveAllOffersFromCartData = getRemoveAllOffersFromCartData;
|
|
32
32
|
exports.getClearVoucherCodeAndOffersFromCartData = getClearVoucherCodeAndOffersFromCartData;
|
|
33
33
|
exports.getResetRewardStateForNewCustomer = getResetRewardStateForNewCustomer;
|
|
34
|
-
exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
|
|
35
34
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
36
35
|
const lodash_1 = require("lodash");
|
|
37
36
|
const constants_1 = require("../../constants");
|
|
@@ -1025,7 +1024,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1025
1024
|
if (loyaltyOffer.reward_discount != null) {
|
|
1026
1025
|
const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = loyaltyOffer.reward_discount;
|
|
1027
1026
|
const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
|
|
1028
|
-
? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
|
|
1027
|
+
? (0, utils_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
|
|
1029
1028
|
: {
|
|
1030
1029
|
subtotal: orderLevelDiscountBaseAmount,
|
|
1031
1030
|
hasExcludedRefs: false,
|
|
@@ -1160,7 +1159,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1160
1159
|
if (voucherOffer?.reward_discount != null) {
|
|
1161
1160
|
const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = voucherOffer.reward_discount;
|
|
1162
1161
|
const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
|
|
1163
|
-
? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
|
|
1162
|
+
? (0, utils_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
|
|
1164
1163
|
: {
|
|
1165
1164
|
subtotal: orderLevelDiscountBaseAmount,
|
|
1166
1165
|
hasExcludedRefs: false,
|
|
@@ -3515,30 +3514,3 @@ function getResetRewardStateForNewCustomer(data, courses, listnerSettings) {
|
|
|
3515
3514
|
wallet_redemptions: null,
|
|
3516
3515
|
}, courses, listnerSettings);
|
|
3517
3516
|
}
|
|
3518
|
-
// ================================><================================= //
|
|
3519
|
-
/**
|
|
3520
|
-
* Calculate the eligible subtotal by excluding items/categories in excluded_refs
|
|
3521
|
-
*/
|
|
3522
|
-
function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
|
|
3523
|
-
if (!categories?.length)
|
|
3524
|
-
return { subtotal: 0, hasExcludedRefs: false };
|
|
3525
|
-
let eligibleSubtotal = 0;
|
|
3526
|
-
let hasExcludedRefs = false;
|
|
3527
|
-
for (const category of categories) {
|
|
3528
|
-
// Skip entire category if it's in excluded_refs
|
|
3529
|
-
if (excluded_refs.includes(category.category_id)) {
|
|
3530
|
-
hasExcludedRefs = true;
|
|
3531
|
-
continue;
|
|
3532
|
-
}
|
|
3533
|
-
// Otherwise, check each item
|
|
3534
|
-
for (const item of category.items ?? []) {
|
|
3535
|
-
if (excluded_refs.includes(item.item_id)) {
|
|
3536
|
-
hasExcludedRefs = true;
|
|
3537
|
-
}
|
|
3538
|
-
else {
|
|
3539
|
-
eligibleSubtotal += item.subtotal ?? 0;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
}
|
|
3543
|
-
return { subtotal: eligibleSubtotal, hasExcludedRefs };
|
|
3544
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PhoneNumberUtil } from 'google-libphonenumber';
|
|
2
2
|
import { COUNTRY_ALPHA_2_ENUM, CURRENCY_SYMBOL_ENUM, SUBSCRIPTION_STATUS_ENUM, TAX_INVOICE_PROVIDER_ENUM } from '../../constants';
|
|
3
|
+
import { IOrderCategory } from '../../schemas';
|
|
3
4
|
export declare const phoneUtil: PhoneNumberUtil;
|
|
4
5
|
export declare function getNationalNumberFromPhone(phoneNumber: string, region?: string): string | null | undefined;
|
|
5
6
|
export declare function getIntNumberFromPhone(phoneNumber: string, region?: string): string | null;
|
|
@@ -43,4 +44,14 @@ interface IGetCappedOfferDiscountAmount {
|
|
|
43
44
|
maxDiscountPercentage?: number | null;
|
|
44
45
|
}
|
|
45
46
|
export declare function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPercentage, maxDiscountAmount, maxDiscountPercentage, }: IGetCappedOfferDiscountAmount): number;
|
|
47
|
+
/**
|
|
48
|
+
* Calculate the eligible subtotal by excluding items/categories in excluded_refs.
|
|
49
|
+
*
|
|
50
|
+
* Shared by the cart engine (discount application/re-sync) and the offer-stats
|
|
51
|
+
* engine (spend qualification) so both use the exact same exclusion math.
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateEligibleOfferDiscountDetails(categories: IOrderCategory[] | undefined, excluded_refs: string[]): {
|
|
54
|
+
subtotal: number;
|
|
55
|
+
hasExcludedRefs: boolean;
|
|
56
|
+
};
|
|
46
57
|
export {};
|
|
@@ -30,6 +30,7 @@ exports.formattedStoreName = formattedStoreName;
|
|
|
30
30
|
exports.getPercentage = getPercentage;
|
|
31
31
|
exports.getPercentageAmount = getPercentageAmount;
|
|
32
32
|
exports.getCappedOfferDiscountAmount = getCappedOfferDiscountAmount;
|
|
33
|
+
exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
|
|
33
34
|
const google_libphonenumber_1 = require("google-libphonenumber");
|
|
34
35
|
const moment_1 = __importDefault(require("moment"));
|
|
35
36
|
const constants_1 = require("../../constants");
|
|
@@ -373,3 +374,32 @@ function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPer
|
|
|
373
374
|
}
|
|
374
375
|
return Math.min(amount, normalizedBaseAmount);
|
|
375
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Calculate the eligible subtotal by excluding items/categories in excluded_refs.
|
|
379
|
+
*
|
|
380
|
+
* Shared by the cart engine (discount application/re-sync) and the offer-stats
|
|
381
|
+
* engine (spend qualification) so both use the exact same exclusion math.
|
|
382
|
+
*/
|
|
383
|
+
function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
|
|
384
|
+
if (!categories?.length)
|
|
385
|
+
return { subtotal: 0, hasExcludedRefs: false };
|
|
386
|
+
let eligibleSubtotal = 0;
|
|
387
|
+
let hasExcludedRefs = false;
|
|
388
|
+
for (const category of categories) {
|
|
389
|
+
// Skip entire category if it's in excluded_refs
|
|
390
|
+
if (excluded_refs.includes(category.category_id)) {
|
|
391
|
+
hasExcludedRefs = true;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
// Otherwise, check each item
|
|
395
|
+
for (const item of category.items ?? []) {
|
|
396
|
+
if (excluded_refs.includes(item.item_id)) {
|
|
397
|
+
hasExcludedRefs = true;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
eligibleSubtotal += item.subtotal ?? 0;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return { subtotal: eligibleSubtotal, hasExcludedRefs };
|
|
405
|
+
}
|
|
@@ -94,7 +94,7 @@ function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, })
|
|
|
94
94
|
const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
|
|
95
95
|
// Handle excluded_refs
|
|
96
96
|
if (excluded_refs != null && excluded_refs.length > 0) {
|
|
97
|
-
const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0,
|
|
97
|
+
const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
|
|
98
98
|
if (hasExcludedRefs) {
|
|
99
99
|
if (!is_discount_percentage) {
|
|
100
100
|
return { success: false, discountDetails: null, errorMessage: null };
|
|
@@ -191,7 +191,7 @@ function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, })
|
|
|
191
191
|
// Validate excluded_refs
|
|
192
192
|
const excluded_refs = offer.reward_cashback.excluded_refs ?? [];
|
|
193
193
|
if (excluded_refs.length > 0) {
|
|
194
|
-
const { subtotal: eligibleSubtotal } = (0,
|
|
194
|
+
const { subtotal: eligibleSubtotal } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
|
|
195
195
|
if (eligibleSubtotal <= 0) {
|
|
196
196
|
return {
|
|
197
197
|
success: false,
|
|
@@ -270,7 +270,7 @@ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categorie
|
|
|
270
270
|
const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage } = reward;
|
|
271
271
|
const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
|
|
272
272
|
const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
|
|
273
|
-
? (0,
|
|
273
|
+
? (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
|
|
274
274
|
: { subtotal: orderLevelDiscountBaseAmount, hasExcludedRefs: false };
|
|
275
275
|
const hasRelevantCap = is_discount_percentage &&
|
|
276
276
|
max_discount_amount != null &&
|
|
@@ -320,7 +320,7 @@ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categorie
|
|
|
320
320
|
}
|
|
321
321
|
const excluded_refs = giftCard.reward_cashback.excluded_refs ?? [];
|
|
322
322
|
if (excluded_refs.length > 0) {
|
|
323
|
-
const { subtotal: eligibleSubtotal } = (0,
|
|
323
|
+
const { subtotal: eligibleSubtotal } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
|
|
324
324
|
if (eligibleSubtotal <= 0) {
|
|
325
325
|
return {
|
|
326
326
|
success: false,
|
|
@@ -1168,14 +1168,40 @@ function getOwnOfferOrderLevelDiscountAmount({ offer, orderDiscountDetails, orde
|
|
|
1168
1168
|
});
|
|
1169
1169
|
return (0, common_1.parseNum)(Math.min(orderLevelDiscountAmount, discountSlotAmounts[discountSlot]));
|
|
1170
1170
|
}
|
|
1171
|
-
|
|
1171
|
+
/**
|
|
1172
|
+
* Discount-eligibility refs whose cart amounts must not count toward the
|
|
1173
|
+
* offer's spend qualification. Mirrors the refs used to compute the eligible
|
|
1174
|
+
* discount base (`calculateEligibleOfferDiscountDetails`) and to gate
|
|
1175
|
+
* "no eligible items" in the stats engine.
|
|
1176
|
+
*/
|
|
1177
|
+
function getOfferOrderValueExcludedRefs(offer) {
|
|
1178
|
+
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
1179
|
+
return offer.reward_discount?.excluded_refs ?? [];
|
|
1180
|
+
}
|
|
1181
|
+
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
1182
|
+
return offer.reward_discount_items?.excluded_refs ?? [];
|
|
1183
|
+
}
|
|
1184
|
+
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK) {
|
|
1185
|
+
return offer.reward_cashback?.excluded_refs ?? [];
|
|
1186
|
+
}
|
|
1187
|
+
return [];
|
|
1188
|
+
}
|
|
1189
|
+
function getOfferQualifyingOrderValue({ offer, categories, orderLevelDiscountBaseAmount, orderLevelDiscountAmount, orderDiscountDetails, }) {
|
|
1190
|
+
// Spend thresholds measure only the eligible (non-excluded) portion of the
|
|
1191
|
+
// cart — excluded categories/items never count toward unlock amounts. When
|
|
1192
|
+
// the cart has no matching excluded refs, keep the original base untouched.
|
|
1193
|
+
const excludedRefs = getOfferOrderValueExcludedRefs(offer);
|
|
1194
|
+
const eligibleSubtotalResult = excludedRefs.length > 0 && categories != null
|
|
1195
|
+
? (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excludedRefs)
|
|
1196
|
+
: null;
|
|
1197
|
+
const effectiveBaseAmount = eligibleSubtotalResult?.hasExcludedRefs === true ? eligibleSubtotalResult.subtotal : orderLevelDiscountBaseAmount;
|
|
1172
1198
|
const ownOrderLevelDiscountAmount = getOwnOfferOrderLevelDiscountAmount({
|
|
1173
1199
|
offer,
|
|
1174
1200
|
orderDiscountDetails,
|
|
1175
|
-
orderLevelDiscountBaseAmount,
|
|
1201
|
+
orderLevelDiscountBaseAmount: effectiveBaseAmount,
|
|
1176
1202
|
orderLevelDiscountAmount,
|
|
1177
1203
|
});
|
|
1178
|
-
return (0, common_1.parseNum)(Math.max(0,
|
|
1204
|
+
return (0, common_1.parseNum)(Math.max(0, effectiveBaseAmount - orderLevelDiscountAmount + ownOrderLevelDiscountAmount));
|
|
1179
1205
|
}
|
|
1180
1206
|
function getMaxApplicableWalletCashback({ cashbackBalance, itemsPrice, totalDiscountApplied, orderLevelDiscount, }) {
|
|
1181
1207
|
const safeCashbackBalance = Number.isFinite(cashbackBalance) ? Math.max(0, Number(cashbackBalance)) : 0;
|
|
@@ -1480,8 +1506,20 @@ function getProgressPercentage(currentValue, requiredValue) {
|
|
|
1480
1506
|
return 100;
|
|
1481
1507
|
return Math.max(0, Math.min(100, Math.round((safeCurrentValue / safeRequiredValue) * 100)));
|
|
1482
1508
|
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Progress that stays below 100% while a pathway requirement is still unmet.
|
|
1511
|
+
*
|
|
1512
|
+
* A requirement that is absent, zero or negative counts as already satisfied
|
|
1513
|
+
* (`getProgressPercentage` returns 100 for it), so callers must pass the RAW
|
|
1514
|
+
* requirement. The old `requirement || 1` fallbacks turned a satisfied minimum
|
|
1515
|
+
* (e.g. `min_num_of_orders: 0`, `num_of_items: 0`, `num_of_points: 0`,
|
|
1516
|
+
* `total_amount: 0`) into 0%, which then zeroed the `Math.min(...)` combined
|
|
1517
|
+
* progress for the whole pre-unlock range. Unlocking is never decided by this
|
|
1518
|
+
* progress value — the pathway comparisons (`orderValue >= total_amount` etc.)
|
|
1519
|
+
* and the explicit `stats.progress = 100` branches decide it.
|
|
1520
|
+
*/
|
|
1483
1521
|
function getPreUnlockProgressPercentage(currentValue, requiredValue) {
|
|
1484
|
-
return Math.min(99, getProgressPercentage(currentValue, requiredValue));
|
|
1522
|
+
return Math.min(99, getProgressPercentage(currentValue, requiredValue ?? 0));
|
|
1485
1523
|
}
|
|
1486
1524
|
function getUnlockedOffersApplicableTimesHashKey(map, isEdit) {
|
|
1487
1525
|
const keys = Object.keys(map).sort();
|
|
@@ -1886,6 +1924,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1886
1924
|
}
|
|
1887
1925
|
const orderValue = getOfferQualifyingOrderValue({
|
|
1888
1926
|
offer,
|
|
1927
|
+
categories,
|
|
1889
1928
|
orderLevelDiscountBaseAmount,
|
|
1890
1929
|
orderLevelDiscountAmount,
|
|
1891
1930
|
orderDiscountDetails: order_discount_details,
|
|
@@ -1908,8 +1947,10 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1908
1947
|
continue;
|
|
1909
1948
|
}
|
|
1910
1949
|
const { totalOrders, totalAmount } = scopedStats;
|
|
1911
|
-
|
|
1912
|
-
|
|
1950
|
+
// Raw requirements: a zero minimum is already satisfied, so it must not
|
|
1951
|
+
// drag `Math.min(ordersProgress, amountProgress)` down to 0%.
|
|
1952
|
+
const ordersProgress = getPreUnlockProgressPercentage(totalOrders, min_num_of_orders);
|
|
1953
|
+
const amountProgress = getPreUnlockProgressPercentage(totalAmount, total_amount);
|
|
1913
1954
|
const combinedProgress = Math.min(ordersProgress, amountProgress);
|
|
1914
1955
|
const ordersBetweenUnlocksStats = getOrdersBetweenUnlocksStats({
|
|
1915
1956
|
totalOrders,
|
|
@@ -2212,6 +2253,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2212
2253
|
}
|
|
2213
2254
|
const orderValue = getOfferQualifyingOrderValue({
|
|
2214
2255
|
offer,
|
|
2256
|
+
categories,
|
|
2215
2257
|
orderLevelDiscountBaseAmount,
|
|
2216
2258
|
orderLevelDiscountAmount,
|
|
2217
2259
|
orderDiscountDetails: order_discount_details,
|
|
@@ -2232,8 +2274,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2232
2274
|
const unlockTimesForItems = Math.floor(totalItemsSelected / (num_of_items || 1));
|
|
2233
2275
|
const unlockTimesForAmount = total_amount != null && total_amount > 0 ? Math.floor(orderValue / total_amount) : unlockTimesForItems;
|
|
2234
2276
|
const totalUnlockableClaims = Math.min(unlockTimesForItems, unlockTimesForAmount, maxClaimsPerOrder);
|
|
2235
|
-
const itemsProgress = getPreUnlockProgressPercentage(bachelorItems, num_of_items
|
|
2236
|
-
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount
|
|
2277
|
+
const itemsProgress = getPreUnlockProgressPercentage(bachelorItems, num_of_items);
|
|
2278
|
+
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
|
|
2237
2279
|
const combinedProgress = Math.min(itemsProgress, amountProgress);
|
|
2238
2280
|
if (totalItemsSelected >= num_of_items) {
|
|
2239
2281
|
if (orderValue >= total_amount) {
|
|
@@ -2485,6 +2527,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2485
2527
|
}
|
|
2486
2528
|
const orderValue = getOfferQualifyingOrderValue({
|
|
2487
2529
|
offer,
|
|
2530
|
+
categories,
|
|
2488
2531
|
orderLevelDiscountBaseAmount,
|
|
2489
2532
|
orderLevelDiscountAmount,
|
|
2490
2533
|
orderDiscountDetails: order_discount_details,
|
|
@@ -2507,8 +2550,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2507
2550
|
const orderLevelClaimSignal = order_discount_details?.loyalty_discount_id === offer._id ? 1 : 0;
|
|
2508
2551
|
const redeemedTimesForCurrentOffer = Math.max(getOfferRedeemedTimes(offer._id), orderLevelClaimSignal);
|
|
2509
2552
|
const effectiveLoyaltyPointsForCurrentOffer = (totalLoyaltyPointsOfCustomer ?? 0) + redeemedTimesForCurrentOffer * (num_of_points ?? 0);
|
|
2510
|
-
const pointsProgress = getPreUnlockProgressPercentage(effectiveLoyaltyPointsForCurrentOffer, num_of_points
|
|
2511
|
-
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount
|
|
2553
|
+
const pointsProgress = getPreUnlockProgressPercentage(effectiveLoyaltyPointsForCurrentOffer, num_of_points);
|
|
2554
|
+
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
|
|
2512
2555
|
const combinedProgress = Math.min(pointsProgress, amountProgress);
|
|
2513
2556
|
if (effectiveLoyaltyPointsForCurrentOffer >= num_of_points) {
|
|
2514
2557
|
if (orderValue >= total_amount) {
|
|
@@ -2763,6 +2806,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2763
2806
|
}
|
|
2764
2807
|
const orderValue = getOfferQualifyingOrderValue({
|
|
2765
2808
|
offer,
|
|
2809
|
+
categories,
|
|
2766
2810
|
orderLevelDiscountBaseAmount,
|
|
2767
2811
|
orderLevelDiscountAmount,
|
|
2768
2812
|
orderDiscountDetails: order_discount_details,
|
|
@@ -2816,7 +2860,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2816
2860
|
const normalizedMatchedVoucherCode = matchingVoucherContext != null ? getVoucherCode(matchingVoucherContext) : null;
|
|
2817
2861
|
const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
|
|
2818
2862
|
const hasVoucherAccess = matchedVoucher != null || (redeemedTimesForOffer > 0 && matchingVoucherContext != null);
|
|
2819
|
-
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount
|
|
2863
|
+
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
|
|
2820
2864
|
if (!hasMatchingVoucher) {
|
|
2821
2865
|
stats.progress = 0;
|
|
2822
2866
|
stats.message = `Enter a matching voucher code to unlock this offer`;
|
|
@@ -64,6 +64,7 @@ export * from './tenant_inventory_department_utilities';
|
|
|
64
64
|
export * from './tenant_inventory_departments';
|
|
65
65
|
export * from './tenant_inventory_entries';
|
|
66
66
|
export * from './tenant_metadata';
|
|
67
|
+
export * from './tenant_order_item_instructions';
|
|
67
68
|
export * from './tenant_purchase_order_vendor_returns';
|
|
68
69
|
export * from './tenant_purchase_orders';
|
|
69
70
|
export * from './tenant_shifts';
|
|
@@ -80,6 +80,7 @@ __exportStar(require("./tenant_inventory_department_utilities"), exports);
|
|
|
80
80
|
__exportStar(require("./tenant_inventory_departments"), exports);
|
|
81
81
|
__exportStar(require("./tenant_inventory_entries"), exports);
|
|
82
82
|
__exportStar(require("./tenant_metadata"), exports);
|
|
83
|
+
__exportStar(require("./tenant_order_item_instructions"), exports);
|
|
83
84
|
__exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
|
|
84
85
|
__exportStar(require("./tenant_purchase_orders"), exports);
|
|
85
86
|
__exportStar(require("./tenant_shifts"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
export declare const TenantOrderItemInstructionSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
3
|
+
timestamps: true;
|
|
4
|
+
versionKey: false;
|
|
5
|
+
minimize: false;
|
|
6
|
+
}, {
|
|
7
|
+
createdAt: NativeDate;
|
|
8
|
+
updatedAt: NativeDate;
|
|
9
|
+
} & {
|
|
10
|
+
_id: import("mongoose").Types.ObjectId;
|
|
11
|
+
tenant_id: string;
|
|
12
|
+
createdAt: NativeDate;
|
|
13
|
+
updatedAt: NativeDate;
|
|
14
|
+
sort_id: number;
|
|
15
|
+
item_ids: import("mongoose").Types.ObjectId[];
|
|
16
|
+
is_public: boolean;
|
|
17
|
+
instruction: string;
|
|
18
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
19
|
+
createdAt: NativeDate;
|
|
20
|
+
updatedAt: NativeDate;
|
|
21
|
+
} & {
|
|
22
|
+
_id: import("mongoose").Types.ObjectId;
|
|
23
|
+
tenant_id: string;
|
|
24
|
+
createdAt: NativeDate;
|
|
25
|
+
updatedAt: NativeDate;
|
|
26
|
+
sort_id: number;
|
|
27
|
+
item_ids: import("mongoose").Types.ObjectId[];
|
|
28
|
+
is_public: boolean;
|
|
29
|
+
instruction: string;
|
|
30
|
+
}>> & import("mongoose").FlatRecord<{
|
|
31
|
+
createdAt: NativeDate;
|
|
32
|
+
updatedAt: NativeDate;
|
|
33
|
+
} & {
|
|
34
|
+
_id: import("mongoose").Types.ObjectId;
|
|
35
|
+
tenant_id: string;
|
|
36
|
+
createdAt: NativeDate;
|
|
37
|
+
updatedAt: NativeDate;
|
|
38
|
+
sort_id: number;
|
|
39
|
+
item_ids: import("mongoose").Types.ObjectId[];
|
|
40
|
+
is_public: boolean;
|
|
41
|
+
instruction: string;
|
|
42
|
+
}> & Required<{
|
|
43
|
+
_id: import("mongoose").Types.ObjectId;
|
|
44
|
+
}> & {
|
|
45
|
+
__v: number;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = "tenant_order_item_instructions";
|
|
48
|
+
/**
|
|
49
|
+
* Describes the indexes for `tenant_order_item_instructions`. Values are Mongo key patterns
|
|
50
|
+
* that can be passed straight to `.hint()`.
|
|
51
|
+
* - `_id`: unique primary key.
|
|
52
|
+
* - `tenant_id__sort_id`: per-tenant lookup ordered by `sort_id`.
|
|
53
|
+
*/
|
|
54
|
+
export declare const TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES: {
|
|
55
|
+
_id: {
|
|
56
|
+
_id: number;
|
|
57
|
+
};
|
|
58
|
+
tenant_id__sort_id: {
|
|
59
|
+
tenant_id: number;
|
|
60
|
+
sort_id: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES = exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = exports.TenantOrderItemInstructionSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
exports.TenantOrderItemInstructionSchema = new mongoose_1.Schema({
|
|
6
|
+
_id: {
|
|
7
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
8
|
+
required: true,
|
|
9
|
+
immutable: true,
|
|
10
|
+
},
|
|
11
|
+
tenant_id: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
immutable: true,
|
|
15
|
+
ref: 'tenants',
|
|
16
|
+
},
|
|
17
|
+
item_ids: {
|
|
18
|
+
type: [
|
|
19
|
+
{
|
|
20
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
21
|
+
ref: 'items',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
required: true,
|
|
25
|
+
default: [],
|
|
26
|
+
},
|
|
27
|
+
sort_id: {
|
|
28
|
+
type: Number,
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
instruction: {
|
|
32
|
+
type: String,
|
|
33
|
+
required: true,
|
|
34
|
+
trim: true,
|
|
35
|
+
},
|
|
36
|
+
is_public: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false,
|
|
39
|
+
},
|
|
40
|
+
createdAt: {
|
|
41
|
+
type: mongoose_1.Schema.Types.Date,
|
|
42
|
+
required: true,
|
|
43
|
+
default: () => new Date(),
|
|
44
|
+
immutable: true,
|
|
45
|
+
},
|
|
46
|
+
updatedAt: {
|
|
47
|
+
type: mongoose_1.Schema.Types.Date,
|
|
48
|
+
required: true,
|
|
49
|
+
default: () => new Date(),
|
|
50
|
+
},
|
|
51
|
+
}, {
|
|
52
|
+
timestamps: true,
|
|
53
|
+
versionKey: false,
|
|
54
|
+
minimize: false,
|
|
55
|
+
});
|
|
56
|
+
exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = 'tenant_order_item_instructions';
|
|
57
|
+
/**
|
|
58
|
+
* Describes the indexes for `tenant_order_item_instructions`. Values are Mongo key patterns
|
|
59
|
+
* that can be passed straight to `.hint()`.
|
|
60
|
+
* - `_id`: unique primary key.
|
|
61
|
+
* - `tenant_id__sort_id`: per-tenant lookup ordered by `sort_id`.
|
|
62
|
+
*/
|
|
63
|
+
exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES = {
|
|
64
|
+
_id: { _id: 1 }, // Unique Index
|
|
65
|
+
tenant_id__sort_id: {
|
|
66
|
+
tenant_id: 1,
|
|
67
|
+
sort_id: 1,
|
|
68
|
+
}, // compound index
|
|
69
|
+
};
|
|
@@ -68,6 +68,7 @@ export * from './tenant_instore_shift_sessions';
|
|
|
68
68
|
export * from './tenant_instore_shifts';
|
|
69
69
|
export * from './tenant_inventory_entries';
|
|
70
70
|
export * from './tenant_metadata';
|
|
71
|
+
export * from './tenant_order_item_instructions';
|
|
71
72
|
export * from './tenant_purchase_order_vendor_returns';
|
|
72
73
|
export * from './tenant_purchase_orders';
|
|
73
74
|
export * from './tenant_shifts';
|
|
@@ -84,6 +84,7 @@ __exportStar(require("./tenant_instore_shift_sessions"), exports);
|
|
|
84
84
|
__exportStar(require("./tenant_instore_shifts"), exports);
|
|
85
85
|
__exportStar(require("./tenant_inventory_entries"), exports);
|
|
86
86
|
__exportStar(require("./tenant_metadata"), exports);
|
|
87
|
+
__exportStar(require("./tenant_order_item_instructions"), exports);
|
|
87
88
|
__exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
|
|
88
89
|
__exportStar(require("./tenant_purchase_orders"), exports);
|
|
89
90
|
__exportStar(require("./tenant_shifts"), exports);
|
|
@@ -63,9 +63,11 @@ function getSingleOfferStats(options = {}) {
|
|
|
63
63
|
return (0, offers_helpers_1.getOffersWithStats)({
|
|
64
64
|
offers: [offer],
|
|
65
65
|
customer: {
|
|
66
|
-
total_orders: 1,
|
|
66
|
+
total_orders: options.totalOrders ?? 1,
|
|
67
|
+
loyalty_points: options.customerLoyaltyPoints ?? 0,
|
|
68
|
+
voucher_codes: options.customerVoucherCodes,
|
|
67
69
|
},
|
|
68
|
-
vouchers:
|
|
70
|
+
vouchers: options.vouchers,
|
|
69
71
|
giftCards: undefined,
|
|
70
72
|
customerOfferRedemptionCounts: undefined,
|
|
71
73
|
redeemed_offers: redeemedOffers,
|
|
@@ -154,4 +156,601 @@ describe('getOffersWithStats spend qualification', () => {
|
|
|
154
156
|
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}200`);
|
|
155
157
|
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
156
158
|
});
|
|
159
|
+
it('removes excluded item amounts from the orders spend threshold', () => {
|
|
160
|
+
const categories = [
|
|
161
|
+
{
|
|
162
|
+
category_id: 'category-salads',
|
|
163
|
+
items: [
|
|
164
|
+
{
|
|
165
|
+
_id: 'cart-salad',
|
|
166
|
+
item_id: 'item-salad',
|
|
167
|
+
name: 'Salad',
|
|
168
|
+
quantity: 2,
|
|
169
|
+
subtotal: 1398,
|
|
170
|
+
modifiers: [],
|
|
171
|
+
item_discount_details: null,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
category_id: 'category-deals',
|
|
177
|
+
items: [
|
|
178
|
+
{
|
|
179
|
+
_id: 'cart-deal',
|
|
180
|
+
item_id: 'item-deal',
|
|
181
|
+
name: 'Deal',
|
|
182
|
+
quantity: 1,
|
|
183
|
+
subtotal: 1799,
|
|
184
|
+
modifiers: [],
|
|
185
|
+
item_discount_details: null,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
const offer = makeOrdersDiscountOffer({
|
|
191
|
+
pathway_to_unlock_type_orders: {
|
|
192
|
+
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
193
|
+
min_num_of_orders: 0,
|
|
194
|
+
max_num_of_orders: null,
|
|
195
|
+
total_amount: 2500,
|
|
196
|
+
max_amount: null,
|
|
197
|
+
orders_between_unlocks: null,
|
|
198
|
+
max_claims: null,
|
|
199
|
+
max_uses_per_customer: null,
|
|
200
|
+
},
|
|
201
|
+
reward_discount: {
|
|
202
|
+
discount_value: 10,
|
|
203
|
+
is_discount_percentage: true,
|
|
204
|
+
max_discount_amount: null,
|
|
205
|
+
max_discount_percentage: null,
|
|
206
|
+
excluded_refs: ['item-deal'],
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
const result = getSingleOfferStats({
|
|
210
|
+
offer,
|
|
211
|
+
categories,
|
|
212
|
+
currentItemsPrice: 3197,
|
|
213
|
+
totalDiscountApplied: 0,
|
|
214
|
+
totalOrders: 0,
|
|
215
|
+
});
|
|
216
|
+
const stats = result.offersWithStats[0].stats;
|
|
217
|
+
expect(stats.claimable).toBe(false);
|
|
218
|
+
// 1398 / 2500 — also guards the zero-minimum orders progress fix
|
|
219
|
+
expect(stats.progress).toBe(56);
|
|
220
|
+
// 2500 - 1398 (deal amount no longer counts toward the threshold)
|
|
221
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
222
|
+
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
223
|
+
});
|
|
224
|
+
it('keeps the full cart when excluded refs are not present in the cart', () => {
|
|
225
|
+
const result = getSingleOfferStats({
|
|
226
|
+
categories: makeCategories(1000),
|
|
227
|
+
currentItemsPrice: 1000,
|
|
228
|
+
totalDiscountApplied: 0,
|
|
229
|
+
offer: makeOrdersDiscountOffer({
|
|
230
|
+
reward_discount: {
|
|
231
|
+
discount_value: 20,
|
|
232
|
+
is_discount_percentage: true,
|
|
233
|
+
max_discount_amount: null,
|
|
234
|
+
max_discount_percentage: null,
|
|
235
|
+
excluded_refs: ['item-not-in-cart'],
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
});
|
|
239
|
+
const stats = result.offersWithStats[0].stats;
|
|
240
|
+
expect(stats.claimable).toBe(true);
|
|
241
|
+
expect(stats.progress).toBe(100);
|
|
242
|
+
expect(result.totalClaimableOffers).toContain(OFFER_ID);
|
|
243
|
+
});
|
|
244
|
+
it('removes an entirely excluded category from the orders spend threshold', () => {
|
|
245
|
+
const categories = [
|
|
246
|
+
{
|
|
247
|
+
category_id: 'category-salads',
|
|
248
|
+
items: [
|
|
249
|
+
{
|
|
250
|
+
_id: 'cart-salad',
|
|
251
|
+
item_id: 'item-salad',
|
|
252
|
+
name: 'Salad',
|
|
253
|
+
quantity: 1,
|
|
254
|
+
subtotal: 500,
|
|
255
|
+
modifiers: [],
|
|
256
|
+
item_discount_details: null,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
category_id: 'category-deals',
|
|
262
|
+
items: [
|
|
263
|
+
{
|
|
264
|
+
_id: 'cart-deal',
|
|
265
|
+
item_id: 'item-deal',
|
|
266
|
+
name: 'Deal',
|
|
267
|
+
quantity: 1,
|
|
268
|
+
subtotal: 500,
|
|
269
|
+
modifiers: [],
|
|
270
|
+
item_discount_details: null,
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
const offer = makeOrdersDiscountOffer({
|
|
276
|
+
reward_discount: {
|
|
277
|
+
discount_value: 20,
|
|
278
|
+
is_discount_percentage: true,
|
|
279
|
+
max_discount_amount: null,
|
|
280
|
+
max_discount_percentage: null,
|
|
281
|
+
excluded_refs: ['category-deals'],
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
const result = getSingleOfferStats({
|
|
285
|
+
offer,
|
|
286
|
+
categories,
|
|
287
|
+
currentItemsPrice: 1000,
|
|
288
|
+
totalDiscountApplied: 0,
|
|
289
|
+
});
|
|
290
|
+
const stats = result.offersWithStats[0].stats;
|
|
291
|
+
expect(stats.claimable).toBe(false);
|
|
292
|
+
// 1000 - 500 excludes the whole category
|
|
293
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}500`);
|
|
294
|
+
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
295
|
+
});
|
|
296
|
+
it('still adds back the applied offer discount when excluded items are present', () => {
|
|
297
|
+
const categories = [
|
|
298
|
+
{
|
|
299
|
+
category_id: 'category-salads',
|
|
300
|
+
items: [
|
|
301
|
+
{
|
|
302
|
+
_id: 'cart-salad',
|
|
303
|
+
item_id: 'item-salad',
|
|
304
|
+
name: 'Salad',
|
|
305
|
+
quantity: 1,
|
|
306
|
+
subtotal: 2600,
|
|
307
|
+
modifiers: [],
|
|
308
|
+
item_discount_details: null,
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
category_id: 'category-deals',
|
|
314
|
+
items: [
|
|
315
|
+
{
|
|
316
|
+
_id: 'cart-deal',
|
|
317
|
+
item_id: 'item-deal',
|
|
318
|
+
name: 'Deal',
|
|
319
|
+
quantity: 1,
|
|
320
|
+
subtotal: 1000,
|
|
321
|
+
modifiers: [],
|
|
322
|
+
item_discount_details: null,
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
];
|
|
327
|
+
const offer = makeOrdersDiscountOffer({
|
|
328
|
+
pathway_to_unlock_type_orders: {
|
|
329
|
+
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
330
|
+
min_num_of_orders: 0,
|
|
331
|
+
max_num_of_orders: null,
|
|
332
|
+
total_amount: 2500,
|
|
333
|
+
max_amount: null,
|
|
334
|
+
orders_between_unlocks: null,
|
|
335
|
+
max_claims: null,
|
|
336
|
+
max_uses_per_customer: null,
|
|
337
|
+
},
|
|
338
|
+
reward_discount: {
|
|
339
|
+
discount_value: 10,
|
|
340
|
+
is_discount_percentage: true,
|
|
341
|
+
max_discount_amount: null,
|
|
342
|
+
max_discount_percentage: null,
|
|
343
|
+
excluded_refs: ['item-deal'],
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
const result = getSingleOfferStats({
|
|
347
|
+
offer,
|
|
348
|
+
categories,
|
|
349
|
+
currentItemsPrice: 3600,
|
|
350
|
+
totalDiscountApplied: 260,
|
|
351
|
+
redeemedOffers: { [OFFER_ID]: 1 },
|
|
352
|
+
orderDiscountDetails: {
|
|
353
|
+
loyalty_discount_id: OFFER_ID,
|
|
354
|
+
loyalty_discount_name: 'Spend threshold discount',
|
|
355
|
+
loyalty_discount: 260,
|
|
356
|
+
is_loyalty_discount_percentage: false,
|
|
357
|
+
total_discount: 260,
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
const stats = result.offersWithStats[0].stats;
|
|
361
|
+
expect(stats.redeemed_times).toBe(1);
|
|
362
|
+
expect(stats.message).toContain('redeemed');
|
|
363
|
+
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
364
|
+
});
|
|
365
|
+
it('applies discount-items and cashback exclusion refs to the spend threshold', () => {
|
|
366
|
+
const categories = [
|
|
367
|
+
{
|
|
368
|
+
category_id: 'category-salads',
|
|
369
|
+
items: [
|
|
370
|
+
{
|
|
371
|
+
_id: 'cart-salad',
|
|
372
|
+
item_id: 'item-salad',
|
|
373
|
+
name: 'Salad',
|
|
374
|
+
quantity: 2,
|
|
375
|
+
subtotal: 1398,
|
|
376
|
+
modifiers: [],
|
|
377
|
+
item_discount_details: null,
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
category_id: 'category-deals',
|
|
383
|
+
items: [
|
|
384
|
+
{
|
|
385
|
+
_id: 'cart-deal',
|
|
386
|
+
item_id: 'item-deal',
|
|
387
|
+
name: 'Deal',
|
|
388
|
+
quantity: 1,
|
|
389
|
+
subtotal: 1799,
|
|
390
|
+
modifiers: [],
|
|
391
|
+
item_discount_details: null,
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
];
|
|
396
|
+
const ordersThreshold = {
|
|
397
|
+
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
398
|
+
min_num_of_orders: 0,
|
|
399
|
+
max_num_of_orders: null,
|
|
400
|
+
total_amount: 2500,
|
|
401
|
+
max_amount: null,
|
|
402
|
+
orders_between_unlocks: null,
|
|
403
|
+
max_claims: null,
|
|
404
|
+
max_uses_per_customer: null,
|
|
405
|
+
};
|
|
406
|
+
const discountItemsResult = getSingleOfferStats({
|
|
407
|
+
offer: makeOrdersDiscountOffer({
|
|
408
|
+
pathway_to_unlock_type_orders: ordersThreshold,
|
|
409
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS,
|
|
410
|
+
reward_discount: null,
|
|
411
|
+
reward_discount_items: {
|
|
412
|
+
num_of_items: 1,
|
|
413
|
+
excluded_refs: ['item-deal'],
|
|
414
|
+
exclusive_refs: [],
|
|
415
|
+
item_ids: ['item-salad'],
|
|
416
|
+
discount_value: 10,
|
|
417
|
+
is_discount_percentage: true,
|
|
418
|
+
allocation: null,
|
|
419
|
+
},
|
|
420
|
+
}),
|
|
421
|
+
categories,
|
|
422
|
+
currentItemsPrice: 3197,
|
|
423
|
+
totalDiscountApplied: 0,
|
|
424
|
+
});
|
|
425
|
+
expect(discountItemsResult.offersWithStats[0].stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
426
|
+
const cashbackResult = getSingleOfferStats({
|
|
427
|
+
offer: makeOrdersDiscountOffer({
|
|
428
|
+
pathway_to_unlock_type_orders: ordersThreshold,
|
|
429
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
|
|
430
|
+
reward_discount: null,
|
|
431
|
+
reward_cashback: {
|
|
432
|
+
cashback_value: 10,
|
|
433
|
+
is_cashback_percentage: true,
|
|
434
|
+
max_cashback_amount: null,
|
|
435
|
+
excluded_refs: ['item-deal'],
|
|
436
|
+
},
|
|
437
|
+
}),
|
|
438
|
+
categories,
|
|
439
|
+
currentItemsPrice: 3197,
|
|
440
|
+
totalDiscountApplied: 0,
|
|
441
|
+
});
|
|
442
|
+
expect(cashbackResult.offersWithStats[0].stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
443
|
+
});
|
|
444
|
+
it('reduces the spend threshold for the points pathway', () => {
|
|
445
|
+
const categories = [
|
|
446
|
+
{
|
|
447
|
+
category_id: 'category-salads',
|
|
448
|
+
items: [
|
|
449
|
+
{
|
|
450
|
+
_id: 'cart-salad',
|
|
451
|
+
item_id: 'item-salad',
|
|
452
|
+
name: 'Salad',
|
|
453
|
+
quantity: 2,
|
|
454
|
+
subtotal: 1398,
|
|
455
|
+
modifiers: [],
|
|
456
|
+
item_discount_details: null,
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
category_id: 'category-deals',
|
|
462
|
+
items: [
|
|
463
|
+
{
|
|
464
|
+
_id: 'cart-deal',
|
|
465
|
+
item_id: 'item-deal',
|
|
466
|
+
name: 'Deal',
|
|
467
|
+
quantity: 1,
|
|
468
|
+
subtotal: 1799,
|
|
469
|
+
modifiers: [],
|
|
470
|
+
item_discount_details: null,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
},
|
|
474
|
+
];
|
|
475
|
+
const offer = makeOrdersDiscountOffer({
|
|
476
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
|
|
477
|
+
pathway_to_unlock_type_orders: null,
|
|
478
|
+
pathway_to_unlock_type_points: {
|
|
479
|
+
num_of_points: 1000,
|
|
480
|
+
total_amount: 2500,
|
|
481
|
+
max_uses_per_customer: null,
|
|
482
|
+
max_claims: null,
|
|
483
|
+
},
|
|
484
|
+
reward_discount: {
|
|
485
|
+
discount_value: 10,
|
|
486
|
+
is_discount_percentage: true,
|
|
487
|
+
max_discount_amount: null,
|
|
488
|
+
max_discount_percentage: null,
|
|
489
|
+
excluded_refs: ['item-deal'],
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
const result = getSingleOfferStats({
|
|
493
|
+
offer,
|
|
494
|
+
categories,
|
|
495
|
+
currentItemsPrice: 3197,
|
|
496
|
+
totalDiscountApplied: 0,
|
|
497
|
+
customerLoyaltyPoints: 1000,
|
|
498
|
+
});
|
|
499
|
+
const stats = result.offersWithStats[0].stats;
|
|
500
|
+
expect(stats.claimable).toBe(false);
|
|
501
|
+
expect(stats.progress).toBe(56); // 1398 / 2500
|
|
502
|
+
// 2500 - 1398 — the deal no longer counts toward the threshold
|
|
503
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
504
|
+
});
|
|
505
|
+
it('reduces the spend threshold for the voucher pathway', () => {
|
|
506
|
+
const categories = [
|
|
507
|
+
{
|
|
508
|
+
category_id: 'category-salads',
|
|
509
|
+
items: [
|
|
510
|
+
{
|
|
511
|
+
_id: 'cart-salad',
|
|
512
|
+
item_id: 'item-salad',
|
|
513
|
+
name: 'Salad',
|
|
514
|
+
quantity: 2,
|
|
515
|
+
subtotal: 1398,
|
|
516
|
+
modifiers: [],
|
|
517
|
+
item_discount_details: null,
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
category_id: 'category-deals',
|
|
523
|
+
items: [
|
|
524
|
+
{
|
|
525
|
+
_id: 'cart-deal',
|
|
526
|
+
item_id: 'item-deal',
|
|
527
|
+
name: 'Deal',
|
|
528
|
+
quantity: 1,
|
|
529
|
+
subtotal: 1799,
|
|
530
|
+
modifiers: [],
|
|
531
|
+
item_discount_details: null,
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
},
|
|
535
|
+
];
|
|
536
|
+
const voucher = {
|
|
537
|
+
_id: 'voucher-party',
|
|
538
|
+
code: 'PARTY10',
|
|
539
|
+
active: true,
|
|
540
|
+
max_uses: 100,
|
|
541
|
+
used_count: 0,
|
|
542
|
+
max_uses_per_customer: null,
|
|
543
|
+
expire_at: null,
|
|
544
|
+
};
|
|
545
|
+
const offer = makeOrdersDiscountOffer({
|
|
546
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
547
|
+
pathway_to_unlock_type_orders: null,
|
|
548
|
+
pathway_to_unlock_type_vouchers: {
|
|
549
|
+
total_amount: 2500,
|
|
550
|
+
max_amount: null,
|
|
551
|
+
max_uses_per_customer: null,
|
|
552
|
+
max_claims: null,
|
|
553
|
+
voucher_ids: ['voucher-party'],
|
|
554
|
+
},
|
|
555
|
+
reward_discount: {
|
|
556
|
+
discount_value: 10,
|
|
557
|
+
is_discount_percentage: true,
|
|
558
|
+
max_discount_amount: null,
|
|
559
|
+
max_discount_percentage: null,
|
|
560
|
+
excluded_refs: ['item-deal'],
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
const result = getSingleOfferStats({
|
|
564
|
+
offer,
|
|
565
|
+
categories,
|
|
566
|
+
currentItemsPrice: 3197,
|
|
567
|
+
totalDiscountApplied: 0,
|
|
568
|
+
vouchers: [voucher],
|
|
569
|
+
customerVoucherCodes: { PARTY10: 1 },
|
|
570
|
+
});
|
|
571
|
+
const stats = result.offersWithStats[0].stats;
|
|
572
|
+
expect(stats.claimable).toBe(false);
|
|
573
|
+
expect(stats.progress).toBe(56); // 1398 / 2500
|
|
574
|
+
// 2500 - 1398 — the deal no longer counts toward the threshold
|
|
575
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
576
|
+
});
|
|
577
|
+
it('does not let a zero items minimum mask the amount progress', () => {
|
|
578
|
+
const categories = [
|
|
579
|
+
{
|
|
580
|
+
category_id: 'category-salads',
|
|
581
|
+
items: [
|
|
582
|
+
{
|
|
583
|
+
_id: 'cart-salad',
|
|
584
|
+
item_id: 'item-salad',
|
|
585
|
+
name: 'Salad',
|
|
586
|
+
quantity: 2,
|
|
587
|
+
subtotal: 1398,
|
|
588
|
+
modifiers: [],
|
|
589
|
+
item_discount_details: null,
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
category_id: 'category-deals',
|
|
595
|
+
items: [
|
|
596
|
+
{
|
|
597
|
+
_id: 'cart-deal',
|
|
598
|
+
item_id: 'item-deal',
|
|
599
|
+
name: 'Deal',
|
|
600
|
+
quantity: 1,
|
|
601
|
+
subtotal: 1799,
|
|
602
|
+
modifiers: [],
|
|
603
|
+
item_discount_details: null,
|
|
604
|
+
},
|
|
605
|
+
],
|
|
606
|
+
},
|
|
607
|
+
];
|
|
608
|
+
const offer = makeOrdersDiscountOffer({
|
|
609
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
|
|
610
|
+
pathway_to_unlock_type_orders: null,
|
|
611
|
+
pathway_to_unlock_type_items: {
|
|
612
|
+
num_of_items: 0,
|
|
613
|
+
max_uses_per_customer: null,
|
|
614
|
+
max_claims: null,
|
|
615
|
+
min_same_item_quantity: null,
|
|
616
|
+
max_same_item_quantity: null,
|
|
617
|
+
total_amount: 5000,
|
|
618
|
+
excluded_refs: [],
|
|
619
|
+
exclusive_refs: [],
|
|
620
|
+
item_ids: ['item-not-in-cart'],
|
|
621
|
+
category_ids: [],
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
const result = getSingleOfferStats({
|
|
625
|
+
offer,
|
|
626
|
+
categories,
|
|
627
|
+
currentItemsPrice: 3197,
|
|
628
|
+
totalDiscountApplied: 0,
|
|
629
|
+
});
|
|
630
|
+
const stats = result.offersWithStats[0].stats;
|
|
631
|
+
expect(stats.claimable).toBe(false);
|
|
632
|
+
// 3197 / 5000 — the satisfied zero minimum must count as 100%, not 0%
|
|
633
|
+
expect(stats.progress).toBe(64);
|
|
634
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1803`);
|
|
635
|
+
});
|
|
636
|
+
it('removes excluded item amounts from the items pathway spend threshold', () => {
|
|
637
|
+
const categories = [
|
|
638
|
+
{
|
|
639
|
+
category_id: 'category-salads',
|
|
640
|
+
items: [
|
|
641
|
+
{
|
|
642
|
+
_id: 'cart-salad',
|
|
643
|
+
item_id: 'item-salad',
|
|
644
|
+
name: 'Salad',
|
|
645
|
+
quantity: 2,
|
|
646
|
+
subtotal: 1398,
|
|
647
|
+
modifiers: [],
|
|
648
|
+
item_discount_details: null,
|
|
649
|
+
},
|
|
650
|
+
],
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
category_id: 'category-deals',
|
|
654
|
+
items: [
|
|
655
|
+
{
|
|
656
|
+
_id: 'cart-deal',
|
|
657
|
+
item_id: 'item-deal',
|
|
658
|
+
name: 'Deal',
|
|
659
|
+
quantity: 1,
|
|
660
|
+
subtotal: 1799,
|
|
661
|
+
modifiers: [],
|
|
662
|
+
item_discount_details: null,
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
},
|
|
666
|
+
];
|
|
667
|
+
const offer = makeOrdersDiscountOffer({
|
|
668
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
|
|
669
|
+
pathway_to_unlock_type_orders: null,
|
|
670
|
+
pathway_to_unlock_type_items: {
|
|
671
|
+
num_of_items: 1,
|
|
672
|
+
max_uses_per_customer: null,
|
|
673
|
+
max_claims: null,
|
|
674
|
+
min_same_item_quantity: null,
|
|
675
|
+
max_same_item_quantity: null,
|
|
676
|
+
total_amount: 2500,
|
|
677
|
+
excluded_refs: [],
|
|
678
|
+
exclusive_refs: [],
|
|
679
|
+
item_ids: ['item-salad'],
|
|
680
|
+
category_ids: [],
|
|
681
|
+
},
|
|
682
|
+
reward_discount: {
|
|
683
|
+
discount_value: 10,
|
|
684
|
+
is_discount_percentage: true,
|
|
685
|
+
max_discount_amount: null,
|
|
686
|
+
max_discount_percentage: null,
|
|
687
|
+
excluded_refs: ['item-deal'],
|
|
688
|
+
},
|
|
689
|
+
});
|
|
690
|
+
const result = getSingleOfferStats({
|
|
691
|
+
offer,
|
|
692
|
+
categories,
|
|
693
|
+
currentItemsPrice: 3197,
|
|
694
|
+
totalDiscountApplied: 0,
|
|
695
|
+
});
|
|
696
|
+
const stats = result.offersWithStats[0].stats;
|
|
697
|
+
// Without the exclusion the 3197 cart would satisfy the 2500 threshold
|
|
698
|
+
expect(stats.claimable).toBe(false);
|
|
699
|
+
expect(stats.progress).toBe(56); // 1398 / 2500
|
|
700
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
|
|
701
|
+
});
|
|
702
|
+
it('does not let a zero points minimum mask the amount progress', () => {
|
|
703
|
+
const categories = [
|
|
704
|
+
{
|
|
705
|
+
category_id: 'category-salads',
|
|
706
|
+
items: [
|
|
707
|
+
{
|
|
708
|
+
_id: 'cart-salad',
|
|
709
|
+
item_id: 'item-salad',
|
|
710
|
+
name: 'Salad',
|
|
711
|
+
quantity: 2,
|
|
712
|
+
subtotal: 1398,
|
|
713
|
+
modifiers: [],
|
|
714
|
+
item_discount_details: null,
|
|
715
|
+
},
|
|
716
|
+
],
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
category_id: 'category-deals',
|
|
720
|
+
items: [
|
|
721
|
+
{
|
|
722
|
+
_id: 'cart-deal',
|
|
723
|
+
item_id: 'item-deal',
|
|
724
|
+
name: 'Deal',
|
|
725
|
+
quantity: 1,
|
|
726
|
+
subtotal: 1799,
|
|
727
|
+
modifiers: [],
|
|
728
|
+
item_discount_details: null,
|
|
729
|
+
},
|
|
730
|
+
],
|
|
731
|
+
},
|
|
732
|
+
];
|
|
733
|
+
const offer = makeOrdersDiscountOffer({
|
|
734
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
|
|
735
|
+
pathway_to_unlock_type_orders: null,
|
|
736
|
+
pathway_to_unlock_type_points: {
|
|
737
|
+
num_of_points: 0,
|
|
738
|
+
total_amount: 5000,
|
|
739
|
+
max_uses_per_customer: null,
|
|
740
|
+
max_claims: null,
|
|
741
|
+
},
|
|
742
|
+
});
|
|
743
|
+
const result = getSingleOfferStats({
|
|
744
|
+
offer,
|
|
745
|
+
categories,
|
|
746
|
+
currentItemsPrice: 3197,
|
|
747
|
+
totalDiscountApplied: 0,
|
|
748
|
+
customerLoyaltyPoints: 0,
|
|
749
|
+
});
|
|
750
|
+
const stats = result.offersWithStats[0].stats;
|
|
751
|
+
expect(stats.claimable).toBe(false);
|
|
752
|
+
// 3197 / 5000 — points balance must not zero out the amount progress
|
|
753
|
+
expect(stats.progress).toBe(64);
|
|
754
|
+
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1803`);
|
|
755
|
+
});
|
|
157
756
|
});
|