@managesome/eposmatic-toolkit 0.4.37 → 0.4.39
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/accounting-templates.js +431 -0
- package/esm/constants/index.js +1 -0
- package/esm/helpers/store/cart-actions.js +54 -6
- package/esm/helpers/utils/cart-helpers.js +19 -5
- package/esm/helpers/utils/common.js +18 -1
- package/esm/helpers/utils/offer-apply-helpers.js +5 -3
- package/esm/helpers/utils/offers-helpers.js +92 -63
- package/lib/constants/accounting-templates.d.ts +8 -0
- package/lib/constants/accounting-templates.js +434 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/helpers/store/cart-actions.js +54 -6
- package/lib/helpers/utils/cart-helpers.js +19 -5
- package/lib/helpers/utils/common.d.ts +15 -0
- package/lib/helpers/utils/common.js +19 -1
- package/lib/helpers/utils/offer-apply-helpers.js +5 -3
- package/lib/helpers/utils/offers-helpers.d.ts +15 -4
- package/lib/helpers/utils/offers-helpers.js +92 -62
- package/lib/schemas/models/expense_categories.d.ts +3 -3
- package/lib/schemas/models/expense_details.d.ts +3 -3
- package/lib/schemas/models/gift_cards.d.ts +3 -3
- package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
- package/lib/schemas/models/internal_invoices.d.ts +3 -3
- package/lib/schemas/models/items.d.ts +12 -12
- package/lib/schemas/models/marketing_fingerprints.d.ts +3 -3
- package/lib/schemas/models/modifier_extras.d.ts +3 -3
- package/lib/schemas/models/offers.d.ts +3 -3
- package/lib/schemas/models/public_holidays.d.ts +3 -3
- package/lib/schemas/models/specials.d.ts +3 -3
- package/lib/schemas/models/tenant_chart_of_accounts.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_departments.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_policies.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_positions.d.ts +3 -3
- package/lib/schemas/models/tenant_journal_entries.d.ts +3 -3
- package/lib/schemas/models/void_order_items.d.ts +3 -3
- package/lib/schemas/models/vouchers.d.ts +3 -3
- package/lib/schemas/models/warehouse_communications.d.ts +3 -3
- package/lib/schemas/models/warehouse_items.d.ts +3 -3
- package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +3 -3
- package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +3 -3
- package/lib/schemas/types/tenant_chart_of_accounts.d.ts +7 -0
- package/lib/tests/cart-helpers-edit-item-refs.test.d.ts +1 -0
- package/lib/tests/cart-helpers-edit-item-refs.test.js +99 -0
- package/lib/tests/code-redemption-helpers.test.d.ts +1 -0
- package/lib/tests/code-redemption-helpers.test.js +246 -0
- package/lib/tests/gift-card-helpers.test.d.ts +1 -0
- package/lib/tests/gift-card-helpers.test.js +100 -0
- package/lib/tests/offer-claim-regressions.test.d.ts +1 -0
- package/lib/tests/offer-claim-regressions.test.js +367 -0
- package/lib/tests/offers-helpers.test.js +24 -4
- package/lib/tests/offers-matrix.test.js +248 -20
- package/lib/tests/ref-exclusion-matching.test.d.ts +1 -0
- package/lib/tests/ref-exclusion-matching.test.js +168 -0
- package/lib/tests/wallet-cashback-helpers.test.d.ts +1 -0
- package/lib/tests/wallet-cashback-helpers.test.js +108 -0
- package/package.json +1 -1
|
@@ -0,0 +1,367 @@
|
|
|
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
|
+
const cart_actions_1 = require("../helpers/store/cart-actions");
|
|
7
|
+
/**
|
|
8
|
+
* Regressions for two defects found in an external audit:
|
|
9
|
+
*
|
|
10
|
+
* F-02 An ORDERS-pathway offer with `total_amount: 0` ("no minimum spend") was
|
|
11
|
+
* granted `floor(cartValue / 1)` claims - thousands of free items.
|
|
12
|
+
* F-01 A FIXED discount with `excluded_refs` was accepted by the builder and then
|
|
13
|
+
* silently deleted, together with its claim, by the cart sync.
|
|
14
|
+
*/
|
|
15
|
+
const categories = () => [
|
|
16
|
+
{
|
|
17
|
+
category_id: 'c',
|
|
18
|
+
name: 'C',
|
|
19
|
+
items: [
|
|
20
|
+
{
|
|
21
|
+
_id: 'ci1',
|
|
22
|
+
item_id: 'i1',
|
|
23
|
+
name: 'A',
|
|
24
|
+
quantity: 1,
|
|
25
|
+
price: 1000,
|
|
26
|
+
subtotal: 1000,
|
|
27
|
+
tax_rate: 0,
|
|
28
|
+
modifiers: [],
|
|
29
|
+
special_instructions: '',
|
|
30
|
+
item_discount_details: null,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
_id: 'ci2',
|
|
34
|
+
item_id: 'i2',
|
|
35
|
+
name: 'B',
|
|
36
|
+
quantity: 1,
|
|
37
|
+
price: 500,
|
|
38
|
+
subtotal: 500,
|
|
39
|
+
tax_rate: 0,
|
|
40
|
+
modifiers: [],
|
|
41
|
+
special_instructions: '',
|
|
42
|
+
item_discount_details: null,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
function offer(overrides) {
|
|
48
|
+
return {
|
|
49
|
+
_id: 'o',
|
|
50
|
+
name: 'Offer',
|
|
51
|
+
active: true,
|
|
52
|
+
auto_apply: false,
|
|
53
|
+
sort_id: 1,
|
|
54
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_DELIVERY],
|
|
55
|
+
offer_special_hours: null,
|
|
56
|
+
...overrides,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function ordersPathway(totalAmount) {
|
|
60
|
+
return {
|
|
61
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
62
|
+
pathway_to_unlock_type_orders: {
|
|
63
|
+
scope: 'OVERALL',
|
|
64
|
+
min_num_of_orders: 0,
|
|
65
|
+
max_num_of_orders: null,
|
|
66
|
+
total_amount: totalAmount,
|
|
67
|
+
max_amount: null,
|
|
68
|
+
orders_between_unlocks: null,
|
|
69
|
+
max_claims: null,
|
|
70
|
+
max_uses_per_customer: null,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function statsFor(offerToCheck, extra = {}) {
|
|
75
|
+
const result = (0, offers_helpers_1.getOffersWithStats)({
|
|
76
|
+
offers: [offerToCheck],
|
|
77
|
+
customer: {
|
|
78
|
+
total_orders: 3,
|
|
79
|
+
loyalty_points: 50,
|
|
80
|
+
total_orders_per_platform_type: { [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 3 },
|
|
81
|
+
voucher_codes: { SAVE: 2 },
|
|
82
|
+
...(extra.customer ?? {}),
|
|
83
|
+
},
|
|
84
|
+
vouchers: [
|
|
85
|
+
{
|
|
86
|
+
_id: 'v1',
|
|
87
|
+
code: 'SAVE',
|
|
88
|
+
active: true,
|
|
89
|
+
max_uses: null,
|
|
90
|
+
max_assignments: null,
|
|
91
|
+
assigned_count: 0,
|
|
92
|
+
used_count: 0,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
giftCards: [],
|
|
96
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
97
|
+
redeemed_offers: extra.redeemed ?? null,
|
|
98
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
99
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.Rs,
|
|
100
|
+
currentItemsPrice: 1500,
|
|
101
|
+
totalDiscountApplied: extra.discount ?? 0,
|
|
102
|
+
categories: extra.categories ?? categories(),
|
|
103
|
+
order_discount_details: extra.orderDiscountDetails ?? null,
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
stats: result.offersWithStats[0].stats,
|
|
107
|
+
unlocked: result.unlockedOffersApplicableTimes.o,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const twoFreeItems = {
|
|
111
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
112
|
+
reward_items: { num_of_items: 2, excluded_refs: [], exclusive_refs: [], item_ids: ['i1', 'i2'], allocation: null },
|
|
113
|
+
};
|
|
114
|
+
describe('F-02: a zero spend threshold must not multiply claims', () => {
|
|
115
|
+
it('grants one claim (not one per currency unit) for an item reward', () => {
|
|
116
|
+
const { stats } = statsFor(offer({ ...ordersPathway(0), ...twoFreeItems }));
|
|
117
|
+
// One claim x 2 items per claim.
|
|
118
|
+
expect(stats.applicable_quantity).toBe(2);
|
|
119
|
+
expect(stats.claimable).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
it('keeps chunking when the threshold is real', () => {
|
|
122
|
+
const { stats } = statsFor(offer({ ...ordersPathway(100), ...twoFreeItems }));
|
|
123
|
+
// floor(1500 / 100) = 15 claims x 2 items.
|
|
124
|
+
expect(stats.applicable_quantity).toBe(30);
|
|
125
|
+
});
|
|
126
|
+
it('grants one claim for points and cashback rewards', () => {
|
|
127
|
+
expect(statsFor(offer({
|
|
128
|
+
...ordersPathway(0),
|
|
129
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.POINTS,
|
|
130
|
+
reward_points: { num_of_points: 1, once_per_order: false },
|
|
131
|
+
})).stats.applicable_quantity).toBe(1);
|
|
132
|
+
expect(statsFor(offer({
|
|
133
|
+
...ordersPathway(0),
|
|
134
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
|
|
135
|
+
reward_cashback: {
|
|
136
|
+
cashback_value: 5,
|
|
137
|
+
is_cashback_percentage: false,
|
|
138
|
+
max_cashback_amount: null,
|
|
139
|
+
excluded_refs: [],
|
|
140
|
+
},
|
|
141
|
+
})).stats.applicable_quantity).toBe(1);
|
|
142
|
+
});
|
|
143
|
+
it('treats a negative or absent threshold as "no minimum spend"', () => {
|
|
144
|
+
expect(statsFor(offer({ ...ordersPathway(-50), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
145
|
+
expect(statsFor(offer({ ...ordersPathway(null), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
146
|
+
});
|
|
147
|
+
it('still honours max_claims and the lifetime budget', () => {
|
|
148
|
+
const withMaxClaims = (maxClaims) => offer({
|
|
149
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
150
|
+
pathway_to_unlock_type_orders: {
|
|
151
|
+
scope: 'OVERALL',
|
|
152
|
+
min_num_of_orders: 0,
|
|
153
|
+
max_num_of_orders: null,
|
|
154
|
+
total_amount: 100,
|
|
155
|
+
max_amount: null,
|
|
156
|
+
orders_between_unlocks: null,
|
|
157
|
+
max_claims: maxClaims,
|
|
158
|
+
max_uses_per_customer: null,
|
|
159
|
+
},
|
|
160
|
+
...twoFreeItems,
|
|
161
|
+
});
|
|
162
|
+
// threshold 100 on a 1500 cart = 15 chunks, capped by max_claims (x2 items per claim)
|
|
163
|
+
expect(statsFor(withMaxClaims(1)).stats.applicable_quantity).toBe(2);
|
|
164
|
+
expect(statsFor(withMaxClaims(3)).stats.applicable_quantity).toBe(6);
|
|
165
|
+
expect(statsFor(withMaxClaims(null)).stats.applicable_quantity).toBe(30);
|
|
166
|
+
});
|
|
167
|
+
it('does not multiply claims when a POINTS reward costs zero points', () => {
|
|
168
|
+
const { stats: statsResult } = statsFor(offer({
|
|
169
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
|
|
170
|
+
pathway_to_unlock_type_points: {
|
|
171
|
+
num_of_points: 0,
|
|
172
|
+
total_amount: 0,
|
|
173
|
+
max_uses_per_customer: null,
|
|
174
|
+
max_claims: null,
|
|
175
|
+
},
|
|
176
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
177
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['i1'], allocation: null },
|
|
178
|
+
}));
|
|
179
|
+
// Was floor(points / 1) = every point the customer holds.
|
|
180
|
+
expect(statsResult.applicable_quantity).toBe(1);
|
|
181
|
+
});
|
|
182
|
+
it('still lets the vouchers held drive a voucher-pathway claim', () => {
|
|
183
|
+
const { stats } = statsFor(offer({
|
|
184
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
185
|
+
pathway_to_unlock_type_vouchers: {
|
|
186
|
+
total_amount: 0,
|
|
187
|
+
max_amount: null,
|
|
188
|
+
max_uses_per_customer: null,
|
|
189
|
+
max_claims: null,
|
|
190
|
+
voucher_ids: ['v1'],
|
|
191
|
+
},
|
|
192
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
193
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['i1'], allocation: null },
|
|
194
|
+
}));
|
|
195
|
+
// Two codes held -> two claims -> two items.
|
|
196
|
+
expect(stats.applicable_quantity).toBe(2);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('F-05: removing a reward item releases its claim', () => {
|
|
200
|
+
const paid = (id) => ({
|
|
201
|
+
_id: id,
|
|
202
|
+
item_id: 'i1',
|
|
203
|
+
name: 'A',
|
|
204
|
+
quantity: 1,
|
|
205
|
+
price: 1000,
|
|
206
|
+
subtotal: 1000,
|
|
207
|
+
tax_rate: 0,
|
|
208
|
+
modifiers: [],
|
|
209
|
+
special_instructions: '',
|
|
210
|
+
item_discount_details: null,
|
|
211
|
+
});
|
|
212
|
+
const rewardItem = (id) => ({
|
|
213
|
+
_id: id,
|
|
214
|
+
item_id: 'i1',
|
|
215
|
+
name: 'A',
|
|
216
|
+
quantity: 1,
|
|
217
|
+
price: 1000,
|
|
218
|
+
subtotal: 0,
|
|
219
|
+
tax_rate: 0,
|
|
220
|
+
modifiers: [],
|
|
221
|
+
special_instructions: '',
|
|
222
|
+
item_discount_details: {
|
|
223
|
+
loyalty_discount: 100,
|
|
224
|
+
loyalty_discount_id: 'o2',
|
|
225
|
+
is_loyalty_discount_percentage: true,
|
|
226
|
+
total_discount: 1000,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
const cartWith = (items) => ({
|
|
230
|
+
categories: [{ category_id: 'c', name: 'C', items }],
|
|
231
|
+
order_discount_details: null,
|
|
232
|
+
redeemed_offers: { o2: 1 },
|
|
233
|
+
wallet_redemptions: null,
|
|
234
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
235
|
+
price: 1000,
|
|
236
|
+
total_discount_applied: 0,
|
|
237
|
+
});
|
|
238
|
+
it('clears the claim when the last stamped item goes', () => {
|
|
239
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), rewardItem('rw')]), { _id: 'rw' }, [], {});
|
|
240
|
+
expect(result.redeemed_offers ?? null).toBeNull();
|
|
241
|
+
});
|
|
242
|
+
it('keeps the claim while another reward item is still stamped', () => {
|
|
243
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), rewardItem('rw'), rewardItem('rw2')]), { _id: 'rw' }, [], {});
|
|
244
|
+
expect(result.redeemed_offers).toEqual({ o2: 1 });
|
|
245
|
+
});
|
|
246
|
+
it('never touches the claim when a non-reward item is removed', () => {
|
|
247
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), paid('p2'), rewardItem('rw')]), { _id: 'p2' }, [], {});
|
|
248
|
+
expect(result.redeemed_offers).toEqual({ o2: 1 });
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe('F-01 (voucher slot): the same rule must hold there', () => {
|
|
252
|
+
const voucherOffer = (excludedRefs, discountValue = 10) => offer({
|
|
253
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
254
|
+
pathway_to_unlock_type_vouchers: {
|
|
255
|
+
total_amount: 0,
|
|
256
|
+
max_amount: null,
|
|
257
|
+
max_uses_per_customer: null,
|
|
258
|
+
max_claims: null,
|
|
259
|
+
voucher_ids: ['v1'],
|
|
260
|
+
},
|
|
261
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
262
|
+
reward_discount: {
|
|
263
|
+
discount_value: discountValue,
|
|
264
|
+
is_discount_percentage: false,
|
|
265
|
+
max_discount_amount: null,
|
|
266
|
+
max_discount_percentage: null,
|
|
267
|
+
excluded_refs: excludedRefs,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
const applyAndSync = (offerToCheck) => {
|
|
271
|
+
const built = (0, offer_apply_helpers_1.buildOfferDiscountUpdate)({
|
|
272
|
+
offer: offerToCheck,
|
|
273
|
+
orderDiscountDetails: null,
|
|
274
|
+
categories: categories(),
|
|
275
|
+
});
|
|
276
|
+
const withReference = { ...built.discountDetails, voucher_reference_number: 'SAVE' };
|
|
277
|
+
const applied = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)({
|
|
278
|
+
categories: categories(),
|
|
279
|
+
order_discount_details: withReference,
|
|
280
|
+
redeemed_offers: { o: 1 },
|
|
281
|
+
wallet_redemptions: null,
|
|
282
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
283
|
+
price: 1500,
|
|
284
|
+
total_discount_applied: 0,
|
|
285
|
+
}, [], {});
|
|
286
|
+
const { unlocked } = statsFor(offerToCheck, {
|
|
287
|
+
redeemed: applied.redeemed_offers,
|
|
288
|
+
orderDiscountDetails: applied.order_discount_details,
|
|
289
|
+
categories: applied.categories,
|
|
290
|
+
discount: applied.total_discount_applied,
|
|
291
|
+
});
|
|
292
|
+
return {
|
|
293
|
+
applied,
|
|
294
|
+
synced: (0, offer_apply_helpers_1.getSyncOffersWithCartData)(applied, [], {}, { o: unlocked ?? 0 }, [offerToCheck]),
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
it('keeps a fixed discount with exclusions in the voucher slot', () => {
|
|
298
|
+
const { synced } = applyAndSync(voucherOffer(['i2']));
|
|
299
|
+
expect(synced.order_discount_details?.voucher_discount).toBe(10);
|
|
300
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
301
|
+
});
|
|
302
|
+
it('clamps it to the eligible subtotal', () => {
|
|
303
|
+
const { synced } = applyAndSync(voucherOffer(['i2'], 5000));
|
|
304
|
+
expect(synced.order_discount_details?.voucher_discount).toBe(1000);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
describe('F-01: a fixed discount with exclusions survives the cart sync', () => {
|
|
308
|
+
const discountOffer = (excludedRefs, discountValue = 10) => offer({
|
|
309
|
+
...ordersPathway(1000),
|
|
310
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
311
|
+
reward_discount: {
|
|
312
|
+
discount_value: discountValue,
|
|
313
|
+
is_discount_percentage: false,
|
|
314
|
+
max_discount_amount: null,
|
|
315
|
+
max_discount_percentage: null,
|
|
316
|
+
excluded_refs: excludedRefs,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
const applyAndSync = (offerToCheck) => {
|
|
320
|
+
const built = (0, offer_apply_helpers_1.buildOfferDiscountUpdate)({
|
|
321
|
+
offer: offerToCheck,
|
|
322
|
+
orderDiscountDetails: null,
|
|
323
|
+
categories: categories(),
|
|
324
|
+
});
|
|
325
|
+
if (!built.success)
|
|
326
|
+
return { built, synced: null };
|
|
327
|
+
const applied = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)({
|
|
328
|
+
categories: categories(),
|
|
329
|
+
order_discount_details: built.discountDetails,
|
|
330
|
+
redeemed_offers: { o: 1 },
|
|
331
|
+
wallet_redemptions: null,
|
|
332
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
333
|
+
price: 1500,
|
|
334
|
+
total_discount_applied: 0,
|
|
335
|
+
}, [], {});
|
|
336
|
+
const { unlocked } = statsFor(offerToCheck, {
|
|
337
|
+
redeemed: applied.redeemed_offers,
|
|
338
|
+
orderDiscountDetails: applied.order_discount_details,
|
|
339
|
+
categories: applied.categories,
|
|
340
|
+
discount: applied.total_discount_applied,
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
built,
|
|
344
|
+
applied,
|
|
345
|
+
synced: (0, offer_apply_helpers_1.getSyncOffersWithCartData)(applied, [], {}, { o: unlocked ?? 0 }, [offerToCheck]),
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
it('keeps the discount and its claim', () => {
|
|
349
|
+
const { synced } = applyAndSync(discountOffer(['i2']));
|
|
350
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(10);
|
|
351
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
352
|
+
});
|
|
353
|
+
it('clamps a fixed value larger than the eligible subtotal', () => {
|
|
354
|
+
const { synced } = applyAndSync(discountOffer(['i2'], 5000));
|
|
355
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(1000);
|
|
356
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
357
|
+
});
|
|
358
|
+
it('still refuses when every item is excluded', () => {
|
|
359
|
+
const { built } = applyAndSync(discountOffer(['i1', 'i2']));
|
|
360
|
+
expect(built.success).toBe(false);
|
|
361
|
+
});
|
|
362
|
+
it('is unchanged without exclusions', () => {
|
|
363
|
+
const { synced } = applyAndSync(discountOffer([]));
|
|
364
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(10);
|
|
365
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
366
|
+
});
|
|
367
|
+
});
|
|
@@ -362,7 +362,7 @@ describe('getOffersWithStats spend qualification', () => {
|
|
|
362
362
|
expect(stats.message).toContain('redeemed');
|
|
363
363
|
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
364
364
|
});
|
|
365
|
-
it('applies
|
|
365
|
+
it('applies cashback item exclusions to the spend threshold but not DISCOUNT_ITEMS option refs', () => {
|
|
366
366
|
const categories = [
|
|
367
367
|
{
|
|
368
368
|
category_id: 'category-salads',
|
|
@@ -387,7 +387,25 @@ describe('getOffersWithStats spend qualification', () => {
|
|
|
387
387
|
name: 'Deal',
|
|
388
388
|
quantity: 1,
|
|
389
389
|
subtotal: 1799,
|
|
390
|
-
|
|
390
|
+
// DISCOUNT_ITEMS exclusion refs are modifier/option refs ("Hide
|
|
391
|
+
// Options"), so the fixture carries a real option to point at.
|
|
392
|
+
modifiers: [
|
|
393
|
+
{
|
|
394
|
+
_id: 'modifier-deal-1',
|
|
395
|
+
ref: 'modifier-deal-extra',
|
|
396
|
+
name: 'Extra',
|
|
397
|
+
options: [
|
|
398
|
+
{
|
|
399
|
+
_id: 'option-deal-1',
|
|
400
|
+
ref: 'option-deal-sauce',
|
|
401
|
+
name: 'Sauce',
|
|
402
|
+
price: 100,
|
|
403
|
+
quantity: 1,
|
|
404
|
+
modifiers: [],
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
391
409
|
item_discount_details: null,
|
|
392
410
|
},
|
|
393
411
|
],
|
|
@@ -410,7 +428,7 @@ describe('getOffersWithStats spend qualification', () => {
|
|
|
410
428
|
reward_discount: null,
|
|
411
429
|
reward_discount_items: {
|
|
412
430
|
num_of_items: 1,
|
|
413
|
-
excluded_refs: ['
|
|
431
|
+
excluded_refs: ['option-deal-sauce'],
|
|
414
432
|
exclusive_refs: [],
|
|
415
433
|
item_ids: ['item-salad'],
|
|
416
434
|
discount_value: 10,
|
|
@@ -422,7 +440,9 @@ describe('getOffersWithStats spend qualification', () => {
|
|
|
422
440
|
currentItemsPrice: 3197,
|
|
423
441
|
totalDiscountApplied: 0,
|
|
424
442
|
});
|
|
425
|
-
|
|
443
|
+
// DISCOUNT_ITEMS refs are option-level ("Hide Options"), so they do not touch
|
|
444
|
+
// the spend-qualification base: the threshold is met by the full cart.
|
|
445
|
+
expect(discountItemsResult.offersWithStats[0].stats.message).toContain('unlocked');
|
|
426
446
|
const cashbackResult = getSingleOfferStats({
|
|
427
447
|
offer: makeOrdersDiscountOffer({
|
|
428
448
|
pathway_to_unlock_type_orders: ordersThreshold,
|