@managesome/eposmatic-toolkit 0.4.31 → 0.4.34
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/esm/constants/MATERIALIZED_REPORTS.js +3 -5
- package/esm/constants/enums/offers.js +0 -6
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +86 -9
- package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +613 -0
- package/esm/helpers/store/cart-actions.js +3 -12
- package/esm/helpers/types/materialized-reports-apis.js +10 -0
- package/esm/helpers/utils/offer-apply-helpers.js +2 -10
- package/esm/helpers/utils/offers-helpers.js +117 -2
- package/esm/schemas/models/index.js +0 -1
- package/esm/schemas/types/index.js +0 -1
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +3 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +3 -5
- package/lib/constants/enums/offers.d.ts +0 -5
- package/lib/constants/enums/offers.js +1 -7
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +15 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +86 -8
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.d.ts +179 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +639 -0
- package/lib/helpers/store/cart-actions.js +1 -10
- package/lib/helpers/types/materialized-reports-apis.d.ts +145 -1
- package/lib/helpers/types/materialized-reports-apis.js +11 -0
- package/lib/helpers/utils/offer-apply-helpers.js +2 -10
- package/lib/helpers/utils/offers-helpers.d.ts +50 -0
- package/lib/helpers/utils/offers-helpers.js +120 -2
- package/lib/schemas/models/index.d.ts +0 -1
- package/lib/schemas/models/index.js +0 -1
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +6 -6
- package/lib/schemas/types/index.d.ts +0 -1
- package/lib/schemas/types/index.js +0 -1
- package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +7 -5
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +28 -5
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +17 -4
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +6 -4
- package/lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.js +135 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +71 -3
- package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.js +620 -0
- package/lib/tests/offers-helpers-points-evidence.test.d.ts +1 -0
- package/lib/tests/offers-helpers-points-evidence.test.js +338 -0
- package/lib/tests/offers-matrix.test.d.ts +1 -0
- package/lib/tests/offers-matrix.test.js +401 -0
- package/package.json +1 -1
- package/esm/schemas/models/rewards_usage.js +0 -61
- package/lib/schemas/models/rewards_usage.d.ts +0 -53
- package/lib/schemas/models/rewards_usage.js +0 -64
- package/lib/schemas/types/rewards_usage.d.ts +0 -13
- package/lib/schemas/types/rewards_usage.js +0 -2
- /package/{esm/schemas/types/rewards_usage.js → lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.d.ts} +0 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const offer_apply_helpers_1 = require("../helpers/utils/offer-apply-helpers");
|
|
5
|
+
const offers_helpers_1 = require("../helpers/utils/offers-helpers");
|
|
6
|
+
/**
|
|
7
|
+
* A POINTS-pathway offer pays for its reward with the customer's points. The
|
|
8
|
+
* claim is evidenced by the stamped cart item (ITEMS / DISCOUNT_ITEMS rewards)
|
|
9
|
+
* and only folded into `redeemed_offers` later, by the cart reconcile.
|
|
10
|
+
*
|
|
11
|
+
* Eligibility used to read only `redeemed_offers` when crediting the claim back,
|
|
12
|
+
* while `calculateCustomerLoyaltyPoints` did count the cart-item evidence when
|
|
13
|
+
* deducting it. The points were therefore deducted twice-ish (once from the
|
|
14
|
+
* balance, once ignored on the way back), the offer read unaffordable, and the
|
|
15
|
+
* cart reconcile stripped the reward item that had just been claimed.
|
|
16
|
+
*
|
|
17
|
+
* These tests pin the boundary: the reward must survive as soon as the customer
|
|
18
|
+
* can actually afford it (balance >= num_of_points), not at 2x that.
|
|
19
|
+
*/
|
|
20
|
+
const PAID_ITEM_ID = 'item-half-broast';
|
|
21
|
+
const CATEGORY_ID = 'category-broast';
|
|
22
|
+
const REWARD_OFFER_ID = 'offer-redeem-points';
|
|
23
|
+
const EARN_OFFER_ID = 'offer-buy-one-earn-point';
|
|
24
|
+
const PAID_ITEM = {
|
|
25
|
+
_id: 'cart-item-paid',
|
|
26
|
+
item_id: PAID_ITEM_ID,
|
|
27
|
+
name: 'Half Broast Mix',
|
|
28
|
+
quantity: 1,
|
|
29
|
+
price: 1206.03,
|
|
30
|
+
subtotal: 1025.13,
|
|
31
|
+
tax_rate: 0,
|
|
32
|
+
modifiers: [],
|
|
33
|
+
special_instructions: '',
|
|
34
|
+
item_discount_details: {
|
|
35
|
+
special_discount: 15,
|
|
36
|
+
special_discount_id: PAID_ITEM_ID,
|
|
37
|
+
special_discount_name: 'Special Discount',
|
|
38
|
+
is_special_discount_percentage: true,
|
|
39
|
+
total_discount: 180.9,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
function makeRewardItem() {
|
|
43
|
+
return {
|
|
44
|
+
_id: 'cart-item-reward',
|
|
45
|
+
item_id: PAID_ITEM_ID,
|
|
46
|
+
name: 'Half Broast Mix',
|
|
47
|
+
quantity: 1,
|
|
48
|
+
price: 1206.03,
|
|
49
|
+
subtotal: 0,
|
|
50
|
+
tax_rate: 0,
|
|
51
|
+
modifiers: [],
|
|
52
|
+
special_instructions: '',
|
|
53
|
+
item_discount_details: {
|
|
54
|
+
loyalty_discount: 100,
|
|
55
|
+
loyalty_discount_id: REWARD_OFFER_ID,
|
|
56
|
+
loyalty_discount_name: 'Redeem 7 Loyalty Points & Get 1 Half Broast Free',
|
|
57
|
+
is_loyalty_discount_percentage: true,
|
|
58
|
+
total_discount: 1206.03,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function makeCategories(items) {
|
|
63
|
+
return [{ category_id: CATEGORY_ID, name: 'BROAST', items }];
|
|
64
|
+
}
|
|
65
|
+
function makeEarnOffer() {
|
|
66
|
+
return {
|
|
67
|
+
_id: EARN_OFFER_ID,
|
|
68
|
+
name: 'Buy 1 Broast & Get 1 Loyalty Point',
|
|
69
|
+
active: true,
|
|
70
|
+
auto_apply: true,
|
|
71
|
+
sort_id: 7,
|
|
72
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.APP_DELIVERY],
|
|
73
|
+
offer_special_hours: null,
|
|
74
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
|
|
75
|
+
pathway_to_unlock_type_items: {
|
|
76
|
+
num_of_items: 1,
|
|
77
|
+
max_uses_per_customer: null,
|
|
78
|
+
max_claims: 10000,
|
|
79
|
+
min_same_item_quantity: null,
|
|
80
|
+
max_same_item_quantity: null,
|
|
81
|
+
total_amount: 1,
|
|
82
|
+
excluded_refs: [],
|
|
83
|
+
exclusive_refs: [],
|
|
84
|
+
item_ids: [PAID_ITEM_ID],
|
|
85
|
+
category_ids: [CATEGORY_ID],
|
|
86
|
+
},
|
|
87
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.POINTS,
|
|
88
|
+
reward_points: { num_of_points: 1, once_per_order: false },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function makeRewardOffer({ rewardType = constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, numOfPoints = 7, } = {}) {
|
|
92
|
+
const base = {
|
|
93
|
+
_id: REWARD_OFFER_ID,
|
|
94
|
+
name: 'Redeem 7 Loyalty Points & Get 1 Half Broast Free',
|
|
95
|
+
active: true,
|
|
96
|
+
auto_apply: false,
|
|
97
|
+
sort_id: 8,
|
|
98
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.APP_DELIVERY],
|
|
99
|
+
offer_special_hours: null,
|
|
100
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
|
|
101
|
+
pathway_to_unlock_type_points: {
|
|
102
|
+
num_of_points: numOfPoints,
|
|
103
|
+
total_amount: 0,
|
|
104
|
+
max_uses_per_customer: null,
|
|
105
|
+
max_claims: 1,
|
|
106
|
+
},
|
|
107
|
+
reward_type: rewardType,
|
|
108
|
+
};
|
|
109
|
+
if (rewardType === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS) {
|
|
110
|
+
base.reward_items = {
|
|
111
|
+
num_of_items: 1,
|
|
112
|
+
excluded_refs: [],
|
|
113
|
+
exclusive_refs: [],
|
|
114
|
+
item_ids: [PAID_ITEM_ID],
|
|
115
|
+
allocation: null,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else if (rewardType === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK) {
|
|
119
|
+
base.reward_cashback = {
|
|
120
|
+
cashback_value: 10,
|
|
121
|
+
is_cashback_percentage: false,
|
|
122
|
+
max_cashback_amount: null,
|
|
123
|
+
excluded_refs: [],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return base;
|
|
127
|
+
}
|
|
128
|
+
function makeCustomer(loyaltyPoints) {
|
|
129
|
+
return {
|
|
130
|
+
phone_number: '+923218852198',
|
|
131
|
+
loyalty_points: loyaltyPoints,
|
|
132
|
+
cashback_balance: 0,
|
|
133
|
+
total_orders: 13,
|
|
134
|
+
total_orders_per_platform_type: { [constants_1.PLATFORMS_ENUM.APP_DELIVERY]: 6 },
|
|
135
|
+
voucher_codes: {},
|
|
136
|
+
gift_cards: {},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function runStats({ loyaltyPoints, items, redeemedOffers = { [EARN_OFFER_ID]: 1 }, offers = [makeEarnOffer(), makeRewardOffer()], isEdit = false, editedOrderRedeemedOffers = null, }) {
|
|
140
|
+
const result = (0, offers_helpers_1.getOffersWithStats)({
|
|
141
|
+
offers,
|
|
142
|
+
customer: makeCustomer(loyaltyPoints),
|
|
143
|
+
vouchers: [],
|
|
144
|
+
giftCards: [],
|
|
145
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: { [EARN_OFFER_ID]: 9 } },
|
|
146
|
+
redeemed_offers: redeemedOffers,
|
|
147
|
+
platform: constants_1.PLATFORMS_ENUM.APP_DELIVERY,
|
|
148
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.Rs,
|
|
149
|
+
currentItemsPrice: 1206.03,
|
|
150
|
+
totalDiscountApplied: 180.9,
|
|
151
|
+
categories: makeCategories(items),
|
|
152
|
+
order_discount_details: null,
|
|
153
|
+
...(isEdit ? { isEdit, editedOrderRedeemedOffers } : {}),
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
result,
|
|
157
|
+
stats: result.offersWithStats.find((entry) => entry.offer._id === REWARD_OFFER_ID).stats,
|
|
158
|
+
unlocked: result.unlockedOffersApplicableTimes[REWARD_OFFER_ID],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
describe('item-reward claim evidence', () => {
|
|
162
|
+
it('reports one claim per num_of_items for item rewards and null otherwise', () => {
|
|
163
|
+
expect((0, offers_helpers_1.getOfferRewardApplicableQuantity)(makeRewardOffer())).toBe(1);
|
|
164
|
+
expect((0, offers_helpers_1.getOfferRewardApplicableQuantity)(makeEarnOffer())).toBeNull();
|
|
165
|
+
expect((0, offers_helpers_1.getOfferRewardApplicableQuantity)(makeRewardOffer({ rewardType: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK }))).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
it('counts stamped cart items as claims, rounding partial usage up', () => {
|
|
168
|
+
expect((0, offers_helpers_1.getOfferItemEvidenceClaims)({ offer: makeRewardOffer(), categories: makeCategories([PAID_ITEM]) })).toBe(0);
|
|
169
|
+
expect((0, offers_helpers_1.getOfferItemEvidenceClaims)({ offer: makeRewardOffer(), categories: makeCategories([makeRewardItem()]) })).toBe(1);
|
|
170
|
+
expect((0, offers_helpers_1.getOfferItemEvidenceClaims)({
|
|
171
|
+
offer: makeRewardOffer(),
|
|
172
|
+
categories: makeCategories([{ ...makeRewardItem(), quantity: 2 }]),
|
|
173
|
+
})).toBe(2);
|
|
174
|
+
});
|
|
175
|
+
it('ignores cart items for a reward that is not an item reward', () => {
|
|
176
|
+
expect((0, offers_helpers_1.getOfferItemEvidenceClaims)({
|
|
177
|
+
offer: makeRewardOffer({ rewardType: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK }),
|
|
178
|
+
categories: makeCategories([makeRewardItem()]),
|
|
179
|
+
})).toBe(0);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('POINTS-pathway eligibility with a claimed item reward', () => {
|
|
183
|
+
it('keeps the reward unlocked once the customer can afford it, before the ledger is written', () => {
|
|
184
|
+
const { stats, unlocked } = runStats({ loyaltyPoints: 7, items: [PAID_ITEM, makeRewardItem()] });
|
|
185
|
+
expect(unlocked).toBe(1);
|
|
186
|
+
expect(stats.message).not.toContain('away from unlocking');
|
|
187
|
+
});
|
|
188
|
+
it('regression: the claim no longer self-destructs at balance == num_of_points (was: required 2x)', () => {
|
|
189
|
+
for (const loyaltyPoints of [7, 8, 13, 14]) {
|
|
190
|
+
const { unlocked } = runStats({ loyaltyPoints, items: [PAID_ITEM, makeRewardItem()] });
|
|
191
|
+
expect(unlocked).toBe(1);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
it('still strips the reward when the customer genuinely cannot afford it', () => {
|
|
195
|
+
const { stats, unlocked } = runStats({ loyaltyPoints: 6, items: [PAID_ITEM, makeRewardItem()] });
|
|
196
|
+
expect(unlocked).toBeUndefined();
|
|
197
|
+
expect(stats.message).toBe('You are 1 points away from unlocking this offer');
|
|
198
|
+
});
|
|
199
|
+
it('does not double-credit when the claim is already in the ledger', () => {
|
|
200
|
+
const { unlocked } = runStats({
|
|
201
|
+
loyaltyPoints: 7,
|
|
202
|
+
items: [PAID_ITEM, makeRewardItem()],
|
|
203
|
+
redeemedOffers: { [EARN_OFFER_ID]: 1, [REWARD_OFFER_ID]: 1 },
|
|
204
|
+
});
|
|
205
|
+
expect(unlocked).toBe(1);
|
|
206
|
+
});
|
|
207
|
+
it('leaves a non-item reward on the POS-pathway driven by the ledger only', () => {
|
|
208
|
+
const offers = [makeEarnOffer(), makeRewardOffer({ rewardType: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK })];
|
|
209
|
+
const { stats } = runStats({
|
|
210
|
+
loyaltyPoints: 7,
|
|
211
|
+
items: [PAID_ITEM, makeRewardItem()],
|
|
212
|
+
offers,
|
|
213
|
+
});
|
|
214
|
+
expect(stats.invalid_offer).toBe(false);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
describe('getRedeemedOffersFromAppliedState (repair / validation)', () => {
|
|
218
|
+
it('adds a missing item-reward claim derived from the stamped items', () => {
|
|
219
|
+
const result = (0, offers_helpers_1.getRedeemedOffersFromAppliedState)({
|
|
220
|
+
categories: makeCategories([PAID_ITEM, makeRewardItem()]),
|
|
221
|
+
orderDiscountDetails: null,
|
|
222
|
+
offers: [makeEarnOffer(), makeRewardOffer()],
|
|
223
|
+
existingRedeemedOffers: { [EARN_OFFER_ID]: 1 },
|
|
224
|
+
});
|
|
225
|
+
expect(result.redeemed_offers).toEqual({ [EARN_OFFER_ID]: 1, [REWARD_OFFER_ID]: 1 });
|
|
226
|
+
expect(result.missingOfferIds).toEqual([REWARD_OFFER_ID]);
|
|
227
|
+
});
|
|
228
|
+
it('adds the claim held by an order-level discount slot', () => {
|
|
229
|
+
const result = (0, offers_helpers_1.getRedeemedOffersFromAppliedState)({
|
|
230
|
+
categories: makeCategories([PAID_ITEM]),
|
|
231
|
+
orderDiscountDetails: { total_discount: 5, loyalty_discount_id: EARN_OFFER_ID },
|
|
232
|
+
offers: [makeEarnOffer(), makeRewardOffer()],
|
|
233
|
+
existingRedeemedOffers: null,
|
|
234
|
+
});
|
|
235
|
+
expect(result.redeemed_offers).toEqual({ [EARN_OFFER_ID]: 1 });
|
|
236
|
+
expect(result.missingOfferIds).toEqual([EARN_OFFER_ID]);
|
|
237
|
+
});
|
|
238
|
+
it('keeps ledger-only claims it cannot derive from applied state', () => {
|
|
239
|
+
const result = (0, offers_helpers_1.getRedeemedOffersFromAppliedState)({
|
|
240
|
+
categories: makeCategories([PAID_ITEM]),
|
|
241
|
+
orderDiscountDetails: null,
|
|
242
|
+
offers: [makeEarnOffer(), makeRewardOffer()],
|
|
243
|
+
existingRedeemedOffers: { [REWARD_OFFER_ID]: 2 },
|
|
244
|
+
});
|
|
245
|
+
expect(result.redeemed_offers).toEqual({ [REWARD_OFFER_ID]: 2 });
|
|
246
|
+
expect(result.missingOfferIds).toEqual([]);
|
|
247
|
+
});
|
|
248
|
+
it('never lowers an existing count', () => {
|
|
249
|
+
const result = (0, offers_helpers_1.getRedeemedOffersFromAppliedState)({
|
|
250
|
+
categories: makeCategories([PAID_ITEM, makeRewardItem()]),
|
|
251
|
+
orderDiscountDetails: null,
|
|
252
|
+
offers: [makeRewardOffer()],
|
|
253
|
+
existingRedeemedOffers: { [REWARD_OFFER_ID]: 3 },
|
|
254
|
+
});
|
|
255
|
+
expect(result.redeemed_offers).toEqual({ [REWARD_OFFER_ID]: 3 });
|
|
256
|
+
});
|
|
257
|
+
it('ignores the wallet-cashback sentinel discount id', () => {
|
|
258
|
+
const result = (0, offers_helpers_1.getRedeemedOffersFromAppliedState)({
|
|
259
|
+
categories: makeCategories([PAID_ITEM]),
|
|
260
|
+
orderDiscountDetails: {
|
|
261
|
+
total_discount: 5,
|
|
262
|
+
loyalty_discount_id: constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID,
|
|
263
|
+
},
|
|
264
|
+
offers: [],
|
|
265
|
+
existingRedeemedOffers: null,
|
|
266
|
+
});
|
|
267
|
+
expect(result.redeemed_offers).toBeNull();
|
|
268
|
+
expect(result.missingOfferIds).toEqual([]);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
describe('editing an order whose points were already debited', () => {
|
|
272
|
+
const fullLedger = { [EARN_OFFER_ID]: 1, [REWARD_OFFER_ID]: 1 };
|
|
273
|
+
it('keeps the already-paid reward when the net balance alone cannot cover it', () => {
|
|
274
|
+
const { stats, unlocked } = runStats({
|
|
275
|
+
loyaltyPoints: 1,
|
|
276
|
+
items: [PAID_ITEM, makeRewardItem()],
|
|
277
|
+
redeemedOffers: fullLedger,
|
|
278
|
+
isEdit: true,
|
|
279
|
+
editedOrderRedeemedOffers: fullLedger,
|
|
280
|
+
});
|
|
281
|
+
expect(unlocked).toBe(1);
|
|
282
|
+
expect(stats.message).not.toContain('away from unlocking');
|
|
283
|
+
});
|
|
284
|
+
it('does not mint points when the reward was removed from the cart mid-edit', () => {
|
|
285
|
+
const { unlocked, stats } = runStats({
|
|
286
|
+
loyaltyPoints: 1,
|
|
287
|
+
items: [PAID_ITEM],
|
|
288
|
+
redeemedOffers: fullLedger,
|
|
289
|
+
isEdit: true,
|
|
290
|
+
editedOrderRedeemedOffers: fullLedger,
|
|
291
|
+
});
|
|
292
|
+
expect(unlocked).toBeUndefined();
|
|
293
|
+
expect(stats.message).toContain('away from unlocking');
|
|
294
|
+
});
|
|
295
|
+
it('is unchanged for a new order (no baseline exemption)', () => {
|
|
296
|
+
const { unlocked } = runStats({
|
|
297
|
+
loyaltyPoints: 1,
|
|
298
|
+
items: [PAID_ITEM, makeRewardItem()],
|
|
299
|
+
redeemedOffers: fullLedger,
|
|
300
|
+
isEdit: false,
|
|
301
|
+
});
|
|
302
|
+
expect(unlocked).toBeUndefined();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe('end-to-end: claim then sync must not remove the reward', () => {
|
|
306
|
+
it('keeps both items and records the claim in redeemed_offers', () => {
|
|
307
|
+
const items = [PAID_ITEM, makeRewardItem()];
|
|
308
|
+
const offers = [makeEarnOffer(), makeRewardOffer()];
|
|
309
|
+
const { result } = runStats({ loyaltyPoints: 7, items, offers });
|
|
310
|
+
const synced = (0, offer_apply_helpers_1.getSyncOffersWithCartData)({
|
|
311
|
+
categories: makeCategories(items),
|
|
312
|
+
redeemed_offers: { [EARN_OFFER_ID]: 1 },
|
|
313
|
+
order_discount_details: null,
|
|
314
|
+
price: 2412.06,
|
|
315
|
+
total_discount_applied: 1386.93,
|
|
316
|
+
wallet_redemptions: null,
|
|
317
|
+
platform: constants_1.PLATFORMS_ENUM.APP_DELIVERY,
|
|
318
|
+
}, [], {}, result.unlockedOffersApplicableTimes, offers);
|
|
319
|
+
expect((synced.categories ?? []).flatMap((category) => category.items ?? [])).toHaveLength(2);
|
|
320
|
+
expect(synced.redeemed_offers).toEqual({ [EARN_OFFER_ID]: 1, [REWARD_OFFER_ID]: 1 });
|
|
321
|
+
});
|
|
322
|
+
it('drops the claim with the reward when the customer cannot afford it', () => {
|
|
323
|
+
const items = [PAID_ITEM, makeRewardItem()];
|
|
324
|
+
const offers = [makeEarnOffer(), makeRewardOffer()];
|
|
325
|
+
const { result } = runStats({ loyaltyPoints: 6, items, offers });
|
|
326
|
+
const synced = (0, offer_apply_helpers_1.getSyncOffersWithCartData)({
|
|
327
|
+
categories: makeCategories(items),
|
|
328
|
+
redeemed_offers: { [EARN_OFFER_ID]: 1 },
|
|
329
|
+
order_discount_details: null,
|
|
330
|
+
price: 2412.06,
|
|
331
|
+
total_discount_applied: 1386.93,
|
|
332
|
+
wallet_redemptions: null,
|
|
333
|
+
platform: constants_1.PLATFORMS_ENUM.APP_DELIVERY,
|
|
334
|
+
}, [], {}, result.unlockedOffersApplicableTimes, offers);
|
|
335
|
+
expect((synced.categories ?? []).flatMap((category) => category.items ?? [])).toHaveLength(1);
|
|
336
|
+
expect(synced.redeemed_offers).toEqual({ [EARN_OFFER_ID]: 1 });
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|