@managesome/eposmatic-toolkit 0.4.40 → 0.4.41
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.
|
@@ -3567,8 +3567,16 @@ export function getRemoveAllOffersFromCartData(data, courses, listnerSettings, o
|
|
|
3567
3567
|
return newData;
|
|
3568
3568
|
}
|
|
3569
3569
|
export function getClearVoucherCodeAndOffersFromCartData(data, courses, listnerSettings, offerIds) {
|
|
3570
|
+
// The voucher slot belongs to ONE offer. Clearing a specific offer must not
|
|
3571
|
+
// wipe a different offer that currently holds that slot (it would leave that
|
|
3572
|
+
// offer's claim in the ledger with no discount on the cart). With no offerIds
|
|
3573
|
+
// the caller means "clear the voucher code entirely", which still clears it.
|
|
3574
|
+
const voucherSlotOfferId = data.order_discount_details?.voucher_discount_id;
|
|
3575
|
+
const shouldClearVoucherSlot = offerIds === undefined || voucherSlotOfferId == null || offerIds.includes(String(voucherSlotOfferId));
|
|
3570
3576
|
const orderWithoutOffers = getRemoveAllOffersFromCartData(data, courses, listnerSettings, offerIds);
|
|
3571
|
-
const nextOrderDiscountDetails =
|
|
3577
|
+
const nextOrderDiscountDetails = shouldClearVoucherSlot
|
|
3578
|
+
? buildClearVoucherDiscountDetails(orderWithoutOffers.order_discount_details)
|
|
3579
|
+
: orderWithoutOffers.order_discount_details;
|
|
3572
3580
|
return getUpdateCartInfoData(orderWithoutOffers, {
|
|
3573
3581
|
order_discount_details: nextOrderDiscountDetails,
|
|
3574
3582
|
}, courses, listnerSettings);
|
|
@@ -219,8 +219,11 @@ function calculatePointsRedeemedForOffer(redeemedOffer, totalOrderPrice, categor
|
|
|
219
219
|
// must NOT be read as "one claim per currency unit", which would multiply the
|
|
220
220
|
// reward by the cart total.
|
|
221
221
|
const getUnlockTimesByOrderAmount = (orderValue, totalAmount) => {
|
|
222
|
+
// Below one currency unit a threshold is not a meaningful chunk size: it
|
|
223
|
+
// multiplies claims by the cart value (0.5 on a 1500 cart = 3000 claims).
|
|
224
|
+
// Treat anything < 1 as "no threshold".
|
|
222
225
|
const requiredAmount = Number(totalAmount);
|
|
223
|
-
if (!Number.isFinite(requiredAmount) || requiredAmount
|
|
226
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount < 1)
|
|
224
227
|
return 1;
|
|
225
228
|
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
226
229
|
};
|
|
@@ -1942,7 +1945,7 @@ export function getOffersWithStats({ offers, customer, vouchers, giftCards, cust
|
|
|
1942
1945
|
// `floor(orderValue / 1)` claims.
|
|
1943
1946
|
const getOrderValueClaimTimes = (orderValue, minAmount) => {
|
|
1944
1947
|
const requiredAmount = Number(minAmount);
|
|
1945
|
-
if (!Number.isFinite(requiredAmount) || requiredAmount
|
|
1948
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount < 1)
|
|
1946
1949
|
return 1;
|
|
1947
1950
|
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
1948
1951
|
};
|
|
@@ -3602,8 +3602,16 @@ function getRemoveAllOffersFromCartData(data, courses, listnerSettings, offerIds
|
|
|
3602
3602
|
return newData;
|
|
3603
3603
|
}
|
|
3604
3604
|
function getClearVoucherCodeAndOffersFromCartData(data, courses, listnerSettings, offerIds) {
|
|
3605
|
+
// The voucher slot belongs to ONE offer. Clearing a specific offer must not
|
|
3606
|
+
// wipe a different offer that currently holds that slot (it would leave that
|
|
3607
|
+
// offer's claim in the ledger with no discount on the cart). With no offerIds
|
|
3608
|
+
// the caller means "clear the voucher code entirely", which still clears it.
|
|
3609
|
+
const voucherSlotOfferId = data.order_discount_details?.voucher_discount_id;
|
|
3610
|
+
const shouldClearVoucherSlot = offerIds === undefined || voucherSlotOfferId == null || offerIds.includes(String(voucherSlotOfferId));
|
|
3605
3611
|
const orderWithoutOffers = getRemoveAllOffersFromCartData(data, courses, listnerSettings, offerIds);
|
|
3606
|
-
const nextOrderDiscountDetails =
|
|
3612
|
+
const nextOrderDiscountDetails = shouldClearVoucherSlot
|
|
3613
|
+
? (0, offers_helpers_1.buildClearVoucherDiscountDetails)(orderWithoutOffers.order_discount_details)
|
|
3614
|
+
: orderWithoutOffers.order_discount_details;
|
|
3607
3615
|
return getUpdateCartInfoData(orderWithoutOffers, {
|
|
3608
3616
|
order_discount_details: nextOrderDiscountDetails,
|
|
3609
3617
|
}, courses, listnerSettings);
|
|
@@ -256,8 +256,11 @@ function calculatePointsRedeemedForOffer(redeemedOffer, totalOrderPrice, categor
|
|
|
256
256
|
// must NOT be read as "one claim per currency unit", which would multiply the
|
|
257
257
|
// reward by the cart total.
|
|
258
258
|
const getUnlockTimesByOrderAmount = (orderValue, totalAmount) => {
|
|
259
|
+
// Below one currency unit a threshold is not a meaningful chunk size: it
|
|
260
|
+
// multiplies claims by the cart value (0.5 on a 1500 cart = 3000 claims).
|
|
261
|
+
// Treat anything < 1 as "no threshold".
|
|
259
262
|
const requiredAmount = Number(totalAmount);
|
|
260
|
-
if (!Number.isFinite(requiredAmount) || requiredAmount
|
|
263
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount < 1)
|
|
261
264
|
return 1;
|
|
262
265
|
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
263
266
|
};
|
|
@@ -1980,7 +1983,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1980
1983
|
// `floor(orderValue / 1)` claims.
|
|
1981
1984
|
const getOrderValueClaimTimes = (orderValue, minAmount) => {
|
|
1982
1985
|
const requiredAmount = Number(minAmount);
|
|
1983
|
-
if (!Number.isFinite(requiredAmount) || requiredAmount
|
|
1986
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount < 1)
|
|
1984
1987
|
return 1;
|
|
1985
1988
|
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
1986
1989
|
};
|
|
@@ -179,6 +179,11 @@ describe('F-02: a zero spend threshold must not multiply claims', () => {
|
|
|
179
179
|
// Was floor(points / 1) = every point the customer holds.
|
|
180
180
|
expect(statsResult.applicable_quantity).toBe(1);
|
|
181
181
|
});
|
|
182
|
+
it('treats a sub-unit threshold as "no threshold" instead of multiplying claims', () => {
|
|
183
|
+
// 0.5 used to mean floor(1500 / 0.5) = 3000 claims.
|
|
184
|
+
expect(statsFor(offer({ ...ordersPathway(0.5), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
185
|
+
expect(statsFor(offer({ ...ordersPathway(0.1), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
186
|
+
});
|
|
182
187
|
it('still lets the vouchers held drive a voucher-pathway claim', () => {
|
|
183
188
|
const { stats } = statsFor(offer({
|
|
184
189
|
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
@@ -196,6 +201,66 @@ describe('F-02: a zero spend threshold must not multiply claims', () => {
|
|
|
196
201
|
expect(stats.applicable_quantity).toBe(2);
|
|
197
202
|
});
|
|
198
203
|
});
|
|
204
|
+
describe('clearing one offer must not wipe another offer\'s voucher slot', () => {
|
|
205
|
+
it('keeps the slot when a different offer holds it', () => {
|
|
206
|
+
const data = {
|
|
207
|
+
categories: [
|
|
208
|
+
{
|
|
209
|
+
category_id: 'c',
|
|
210
|
+
name: 'C',
|
|
211
|
+
items: [
|
|
212
|
+
{ _id: 'p1', item_id: 'i1', name: 'A', quantity: 1, price: 1000, subtotal: 1000, tax_rate: 0, modifiers: [], special_instructions: '', item_discount_details: null },
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
order_discount_details: {
|
|
217
|
+
voucher_discount_id: 'B',
|
|
218
|
+
voucher_reference_number: 'SAVE-B',
|
|
219
|
+
voucher_discount: 10,
|
|
220
|
+
total_discount: 10,
|
|
221
|
+
},
|
|
222
|
+
redeemed_offers: { A: 1, B: 1 },
|
|
223
|
+
wallet_redemptions: null,
|
|
224
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
225
|
+
price: 1000,
|
|
226
|
+
total_discount_applied: 10,
|
|
227
|
+
};
|
|
228
|
+
const after = (0, cart_actions_1.getClearVoucherCodeAndOffersFromCartData)(data, [], {}, ['A']);
|
|
229
|
+
const details = (after.order_discount_details ?? {});
|
|
230
|
+
// B is untouched: its slot, its reference and its claim all survive.
|
|
231
|
+
expect(details.voucher_discount_id).toBe('B');
|
|
232
|
+
expect(details.voucher_reference_number).toBe('SAVE-B');
|
|
233
|
+
expect(after.redeemed_offers).toEqual({ B: 1 });
|
|
234
|
+
});
|
|
235
|
+
it('still clears the slot when the target offer is the one holding it', () => {
|
|
236
|
+
const data = {
|
|
237
|
+
categories: [
|
|
238
|
+
{
|
|
239
|
+
category_id: 'c',
|
|
240
|
+
name: 'C',
|
|
241
|
+
items: [
|
|
242
|
+
{ _id: 'p1', item_id: 'i1', name: 'A', quantity: 1, price: 1000, subtotal: 1000, tax_rate: 0, modifiers: [], special_instructions: '', item_discount_details: null },
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
order_discount_details: {
|
|
247
|
+
voucher_discount_id: 'A',
|
|
248
|
+
voucher_reference_number: 'SAVE-A',
|
|
249
|
+
voucher_discount: 10,
|
|
250
|
+
total_discount: 10,
|
|
251
|
+
},
|
|
252
|
+
redeemed_offers: { A: 1 },
|
|
253
|
+
wallet_redemptions: null,
|
|
254
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
255
|
+
price: 1000,
|
|
256
|
+
total_discount_applied: 10,
|
|
257
|
+
};
|
|
258
|
+
const after = (0, cart_actions_1.getClearVoucherCodeAndOffersFromCartData)(data, [], {}, ['A']);
|
|
259
|
+
const details = (after.order_discount_details ?? {});
|
|
260
|
+
expect(details.voucher_discount_id).toBeUndefined();
|
|
261
|
+
expect(details.voucher_reference_number).toBeUndefined();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
199
264
|
describe('F-05: removing a reward item releases its claim', () => {
|
|
200
265
|
const paid = (id) => ({
|
|
201
266
|
_id: id,
|
|
@@ -243,6 +308,12 @@ describe('F-05: removing a reward item releases its claim', () => {
|
|
|
243
308
|
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), rewardItem('rw'), rewardItem('rw2')]), { _id: 'rw' }, [], {});
|
|
244
309
|
expect(result.redeemed_offers).toEqual({ o2: 1 });
|
|
245
310
|
});
|
|
311
|
+
it('also releases the claim on the update-item path', () => {
|
|
312
|
+
// The same removal can arrive as "update this item's quantity to 0" rather
|
|
313
|
+
// than as an explicit remove; both paths must reconcile the ledger.
|
|
314
|
+
const result = (0, cart_actions_1.getUpdateItemInCartData)(cartWith([paid('p1'), rewardItem('rw')]), { _id: 'rw', quantity: 0 }, [], {});
|
|
315
|
+
expect(result.redeemed_offers ?? null).toBeNull();
|
|
316
|
+
});
|
|
246
317
|
it('never touches the claim when a non-reward item is removed', () => {
|
|
247
318
|
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), paid('p2'), rewardItem('rw')]), { _id: 'p2' }, [], {});
|
|
248
319
|
expect(result.redeemed_offers).toEqual({ o2: 1 });
|