@managesome/eposmatic-toolkit 0.2.343 → 0.2.344
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.
|
@@ -843,10 +843,14 @@ function getReconciledRedeemedOffersMapForOfferSync({ existingRedeemedOffers, ca
|
|
|
843
843
|
delete nextRedeemedOffers[normalizedOfferId];
|
|
844
844
|
continue;
|
|
845
845
|
}
|
|
846
|
+
const hasUnlockContext = unlockedOffersApplicableTimes != null;
|
|
846
847
|
const maxApplicableTimes = toPositiveInteger(unlockedOffersApplicableTimes?.[offer._id], 0);
|
|
847
848
|
if (maxApplicableTimes <= 0) {
|
|
848
|
-
|
|
849
|
-
|
|
849
|
+
if (!hasUnlockContext) {
|
|
850
|
+
nextRedeemedOffers[normalizedOfferId] = existingRedeemedTimes;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
delete nextRedeemedOffers[normalizedOfferId];
|
|
850
854
|
continue;
|
|
851
855
|
}
|
|
852
856
|
nextRedeemedOffers[normalizedOfferId] = Math.min(existingRedeemedTimes, maxApplicableTimes);
|
|
@@ -498,10 +498,14 @@ function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, of
|
|
|
498
498
|
delete nextRedeemedOffers[normalizedOfferId];
|
|
499
499
|
continue;
|
|
500
500
|
}
|
|
501
|
+
const hasUnlockContext = unlockedOffersApplicableTimes != null;
|
|
501
502
|
const maxApplicableTimes = toPositiveInteger(unlockedOffersApplicableTimes?.[offer._id], 0);
|
|
502
503
|
if (maxApplicableTimes <= 0) {
|
|
503
|
-
|
|
504
|
-
|
|
504
|
+
if (!hasUnlockContext) {
|
|
505
|
+
nextRedeemedOffers[normalizedOfferId] = existingRedeemedTimes;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
delete nextRedeemedOffers[normalizedOfferId];
|
|
505
509
|
continue;
|
|
506
510
|
}
|
|
507
511
|
nextRedeemedOffers[normalizedOfferId] = Math.min(existingRedeemedTimes, maxApplicableTimes);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cart_actions_1 = require("../store/cart-actions");
|
|
4
|
+
const offer_apply_helpers_1 = require("./offer-apply-helpers");
|
|
5
|
+
const OFFER_ID = 'offer-reward-threshold';
|
|
6
|
+
const POST_ORDER_REWARD_TYPES = ['POINTS', 'CASHBACK', 'VOUCHER', 'GIFT_CARDS'];
|
|
7
|
+
function makeCategories({ itemDiscountDetails = null, quantity = 1, subtotal = 699, } = {}) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
category_id: 'category-pizza',
|
|
11
|
+
items: [
|
|
12
|
+
{
|
|
13
|
+
_id: 'cart-item-1',
|
|
14
|
+
item_id: 'item-classic-euro',
|
|
15
|
+
name: 'Classic Euro',
|
|
16
|
+
quantity,
|
|
17
|
+
subtotal,
|
|
18
|
+
modifiers: [],
|
|
19
|
+
item_discount_details: itemDiscountDetails,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
function makeOrder(overrides = {}) {
|
|
26
|
+
return {
|
|
27
|
+
categories: makeCategories(),
|
|
28
|
+
order_discount_details: null,
|
|
29
|
+
redeemed_offers: {
|
|
30
|
+
[OFFER_ID]: 1,
|
|
31
|
+
},
|
|
32
|
+
wallet_redemptions: null,
|
|
33
|
+
platform: 'WEB_TAKE-AWAY',
|
|
34
|
+
...overrides,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function makeOffer(rewardType, overrides = {}) {
|
|
38
|
+
const offer = {
|
|
39
|
+
_id: OFFER_ID,
|
|
40
|
+
name: `${rewardType} threshold reward`,
|
|
41
|
+
active: true,
|
|
42
|
+
reward_type: rewardType,
|
|
43
|
+
pathway_to_unlock_type: 'ORDERS',
|
|
44
|
+
pathway_to_unlock_type_orders: {
|
|
45
|
+
total_amount: 1000,
|
|
46
|
+
max_claims: null,
|
|
47
|
+
max_uses_per_customer: null,
|
|
48
|
+
},
|
|
49
|
+
...overrides,
|
|
50
|
+
};
|
|
51
|
+
if (rewardType === 'POINTS') {
|
|
52
|
+
offer.reward_points = { points: 100, once_per_order: true };
|
|
53
|
+
}
|
|
54
|
+
if (rewardType === 'CASHBACK') {
|
|
55
|
+
offer.reward_cashback = { cashback_value: 10, is_cashback_percentage: false };
|
|
56
|
+
}
|
|
57
|
+
if (rewardType === 'VOUCHER') {
|
|
58
|
+
offer.reward_voucher = { voucher_ids: { 'voucher-april28': true } };
|
|
59
|
+
}
|
|
60
|
+
if (rewardType === 'GIFT_CARDS') {
|
|
61
|
+
offer.reward_gift_cards = { gift_card_ids: { 'gift-card-reward': true } };
|
|
62
|
+
}
|
|
63
|
+
if (rewardType === 'ITEMS') {
|
|
64
|
+
offer.reward_items = {
|
|
65
|
+
num_of_items: 1,
|
|
66
|
+
item_ids: ['item-classic-euro'],
|
|
67
|
+
excluded_refs: [],
|
|
68
|
+
exclusive_refs: [],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return offer;
|
|
72
|
+
}
|
|
73
|
+
describe('offer redeemed_offers sync', () => {
|
|
74
|
+
test.each(POST_ORDER_REWARD_TYPES)('getSyncOffersWithCartData clears stale %s reward claims when unlock context reports zero availability', (rewardType) => {
|
|
75
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder(), [], {}, {}, [makeOffer(rewardType)]);
|
|
76
|
+
expect(result.redeemed_offers?.[OFFER_ID]).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
test.each(POST_ORDER_REWARD_TYPES)('calculateCartOrderInfoAndSyncData clears stale %s reward claims when unlock context reports zero availability', (rewardType) => {
|
|
79
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(makeOrder(), [], {}, undefined, {
|
|
80
|
+
unlockedOffersApplicableTimes: {},
|
|
81
|
+
offers: [makeOffer(rewardType)],
|
|
82
|
+
});
|
|
83
|
+
expect(result.redeemed_offers?.[OFFER_ID]).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
it('getSyncOffersWithCartData preserves selected item reward evidence while the item reward remains unlocked', () => {
|
|
86
|
+
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
87
|
+
categories: makeCategories({
|
|
88
|
+
itemDiscountDetails: {
|
|
89
|
+
loyalty_discount_id: OFFER_ID,
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
redeemed_offers: null,
|
|
93
|
+
}), [], {}, { [OFFER_ID]: 1 }, [makeOffer('ITEMS')]);
|
|
94
|
+
expect(result.redeemed_offers?.[OFFER_ID]).toBe(1);
|
|
95
|
+
});
|
|
96
|
+
it('calculateCartOrderInfoAndSyncData preserves selected item reward evidence while the item reward remains unlocked', () => {
|
|
97
|
+
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(makeOrder({
|
|
98
|
+
categories: makeCategories({
|
|
99
|
+
itemDiscountDetails: {
|
|
100
|
+
loyalty_discount_id: OFFER_ID,
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
redeemed_offers: null,
|
|
104
|
+
}), [], {}, undefined, {
|
|
105
|
+
unlockedOffersApplicableTimes: { [OFFER_ID]: 1 },
|
|
106
|
+
offers: [makeOffer('ITEMS')],
|
|
107
|
+
});
|
|
108
|
+
expect(result.redeemed_offers?.[OFFER_ID]).toBe(1);
|
|
109
|
+
});
|
|
110
|
+
});
|