@managesome/eposmatic-toolkit 0.4.32 → 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.
Files changed (46) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +3 -5
  2. package/esm/constants/enums/offers.js +0 -6
  3. package/esm/helpers/materialized-reports/index.js +1 -0
  4. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  5. package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
  6. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +86 -9
  7. package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +613 -0
  8. package/esm/helpers/types/materialized-reports-apis.js +10 -0
  9. package/esm/schemas/models/index.js +0 -1
  10. package/esm/schemas/types/index.js +0 -1
  11. package/lib/constants/MATERIALIZED_REPORTS.d.ts +3 -2
  12. package/lib/constants/MATERIALIZED_REPORTS.js +3 -5
  13. package/lib/constants/enums/offers.d.ts +0 -5
  14. package/lib/constants/enums/offers.js +1 -7
  15. package/lib/helpers/materialized-reports/index.d.ts +1 -0
  16. package/lib/helpers/materialized-reports/index.js +1 -0
  17. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  18. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
  19. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +15 -0
  20. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +86 -8
  21. package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.d.ts +179 -0
  22. package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +639 -0
  23. package/lib/helpers/types/materialized-reports-apis.d.ts +145 -1
  24. package/lib/helpers/types/materialized-reports-apis.js +11 -0
  25. package/lib/schemas/models/index.d.ts +0 -1
  26. package/lib/schemas/models/index.js +0 -1
  27. package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +6 -6
  28. package/lib/schemas/types/index.d.ts +0 -1
  29. package/lib/schemas/types/index.js +0 -1
  30. package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +7 -5
  31. package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +28 -5
  32. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +17 -4
  33. package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +6 -4
  34. package/lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.js +135 -0
  35. package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +71 -3
  36. package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.d.ts +1 -0
  37. package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.js +620 -0
  38. package/lib/tests/offers-matrix.test.d.ts +1 -0
  39. package/lib/tests/offers-matrix.test.js +401 -0
  40. package/package.json +1 -1
  41. package/esm/schemas/models/rewards_usage.js +0 -61
  42. package/lib/schemas/models/rewards_usage.d.ts +0 -53
  43. package/lib/schemas/models/rewards_usage.js +0 -64
  44. package/lib/schemas/types/rewards_usage.d.ts +0 -13
  45. package/lib/schemas/types/rewards_usage.js +0 -2
  46. /package/{esm/schemas/types/rewards_usage.js → lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.d.ts} +0 -0
@@ -0,0 +1,401 @@
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
+ * Pathway x reward contract matrix.
8
+ *
9
+ * An offer is exactly one pathway (what unlocks it) crossed with exactly one
10
+ * reward (what it gives). The admin blocks two cells - POINTS pathway with a
11
+ * POINTS reward, and VOUCHER pathway with a VOUCHER reward (each would make the
12
+ * same resource both the price and the prize) - leaving 26 valid combinations.
13
+ *
14
+ * This file exercises every valid cell in both directions: locked (must not be
15
+ * claimable) and unlocked (must be claimable or already satisfied), and pins the
16
+ * reward preview/action hint that the UI renders from.
17
+ */
18
+ const ITEM_ID = 'item-broast';
19
+ const CATEGORY_ID = 'category-broast';
20
+ const VOUCHER_ID = 'voucher-save10';
21
+ const VOUCHER_CODE = 'SAVE10';
22
+ const GIFT_CARD_ID = 'gift-card-half-broast';
23
+ const PAID_ITEM = {
24
+ _id: 'cart-item-paid',
25
+ item_id: ITEM_ID,
26
+ name: 'Half Broast',
27
+ quantity: 1,
28
+ price: 1000,
29
+ subtotal: 1000,
30
+ tax_rate: 0,
31
+ modifiers: [],
32
+ special_instructions: '',
33
+ item_discount_details: null,
34
+ };
35
+ function makeCategories() {
36
+ return [{ category_id: CATEGORY_ID, name: 'BROAST', items: [PAID_ITEM] }];
37
+ }
38
+ function makeVoucher() {
39
+ const now = new Date('2026-01-01T00:00:00.000Z');
40
+ return {
41
+ _id: VOUCHER_ID, code: VOUCHER_CODE, brand_id: 'brand_1', tenants: ['tenant_1'],
42
+ name: 'SAVE10', description: '', active: true, is_public: true,
43
+ max_uses: null, max_uses_per_customer: null, max_assignments: null, max_assignments_per_customer: null,
44
+ assigned_count: 0, last_assigned_at: null, used_count: 0, last_used_at: null, expire_at: null,
45
+ updatedAt: now, createdAt: now,
46
+ };
47
+ }
48
+ function makeGiftCard() {
49
+ const now = new Date('2026-01-01T00:00:00.000Z');
50
+ return {
51
+ _id: GIFT_CARD_ID, code: 'GC100', brand_id: 'brand_1', tenants: ['tenant_1'],
52
+ name: 'Free Broast', description: '', active: true,
53
+ max_uses: null, max_uses_per_customer: null, max_assignments: null, max_assignments_per_customer: null,
54
+ assigned_count: 0, used_count: 0, expire_at: null,
55
+ reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
56
+ reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: [ITEM_ID], allocation: null },
57
+ updatedAt: now, createdAt: now,
58
+ };
59
+ }
60
+ function pathwayPayload(pathway, unlocked) {
61
+ // A locked configuration simply pushes the threshold out of reach; every other
62
+ // pathway field keeps the offer valid so the reward branch is still reached.
63
+ switch (pathway) {
64
+ case constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS:
65
+ return {
66
+ pathway_to_unlock_type: pathway,
67
+ pathway_to_unlock_type_orders: {
68
+ scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
69
+ max_uses_per_customer: null,
70
+ max_claims: null,
71
+ min_num_of_orders: unlocked ? 1 : 99,
72
+ max_num_of_orders: null,
73
+ total_amount: 0,
74
+ max_amount: null,
75
+ orders_between_unlocks: null,
76
+ },
77
+ };
78
+ case constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS:
79
+ return {
80
+ pathway_to_unlock_type: pathway,
81
+ pathway_to_unlock_type_items: {
82
+ num_of_items: unlocked ? 1 : 99,
83
+ max_uses_per_customer: null,
84
+ max_claims: null,
85
+ min_same_item_quantity: null,
86
+ max_same_item_quantity: null,
87
+ total_amount: 0,
88
+ excluded_refs: [],
89
+ exclusive_refs: [],
90
+ item_ids: [ITEM_ID],
91
+ category_ids: [CATEGORY_ID],
92
+ },
93
+ };
94
+ case constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS:
95
+ return {
96
+ pathway_to_unlock_type: pathway,
97
+ pathway_to_unlock_type_points: {
98
+ num_of_points: unlocked ? 1 : 999,
99
+ total_amount: 0,
100
+ max_uses_per_customer: null,
101
+ max_claims: null,
102
+ },
103
+ };
104
+ case constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER:
105
+ return {
106
+ pathway_to_unlock_type: pathway,
107
+ pathway_to_unlock_type_vouchers: {
108
+ // The voucher pathway unlocks on wallet possession AND cart spend, so
109
+ // locking it means pushing the spend threshold out of reach.
110
+ total_amount: unlocked ? 0 : 99999,
111
+ max_amount: null,
112
+ max_uses_per_customer: null,
113
+ max_claims: null,
114
+ voucher_ids: [VOUCHER_ID],
115
+ },
116
+ };
117
+ default:
118
+ return {};
119
+ }
120
+ }
121
+ function rewardPayload(reward) {
122
+ switch (reward) {
123
+ case constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT:
124
+ return {
125
+ reward_type: reward,
126
+ reward_discount: {
127
+ discount_value: 10,
128
+ is_discount_percentage: false,
129
+ max_discount_amount: null,
130
+ max_discount_percentage: null,
131
+ excluded_refs: [],
132
+ },
133
+ };
134
+ case constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS:
135
+ return {
136
+ reward_type: reward,
137
+ reward_discount_items: {
138
+ num_of_items: 1,
139
+ excluded_refs: [],
140
+ exclusive_refs: [],
141
+ item_ids: [ITEM_ID],
142
+ discount_value: 50,
143
+ is_discount_percentage: true,
144
+ allocation: null,
145
+ },
146
+ };
147
+ case constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS:
148
+ return {
149
+ reward_type: reward,
150
+ reward_items: {
151
+ num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: [ITEM_ID], allocation: null,
152
+ },
153
+ };
154
+ case constants_1.OFFER_REWARD_TYPE_ENUM.POINTS:
155
+ return { reward_type: reward, reward_points: { num_of_points: 1, once_per_order: false } };
156
+ case constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK:
157
+ return {
158
+ reward_type: reward,
159
+ reward_cashback: {
160
+ cashback_value: 5, is_cashback_percentage: false, max_cashback_amount: null, excluded_refs: [],
161
+ },
162
+ };
163
+ case constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS:
164
+ return { reward_type: reward, reward_gift_cards: { gift_card_ids: { [GIFT_CARD_ID]: 1 } } };
165
+ case constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER:
166
+ return { reward_type: reward, reward_voucher: { voucher_ids: { [VOUCHER_ID]: 1 } } };
167
+ default:
168
+ return {};
169
+ }
170
+ }
171
+ function makeOffer(pathway, reward, unlocked) {
172
+ return {
173
+ _id: `offer-${pathway}-${reward}`,
174
+ name: `${pathway} -> ${reward}`,
175
+ active: true,
176
+ auto_apply: false,
177
+ sort_id: 1,
178
+ included_platforms: [constants_1.PLATFORMS_ENUM.WEB_DELIVERY],
179
+ offer_special_hours: null,
180
+ ...pathwayPayload(pathway, unlocked),
181
+ ...rewardPayload(reward),
182
+ };
183
+ }
184
+ function statsFor(offer, { redeemedTimes = 0, totalOrders = 5 } = {}) {
185
+ const result = (0, offers_helpers_1.getOffersWithStats)({
186
+ offers: [offer],
187
+ customer: {
188
+ phone_number: '+923218852198',
189
+ loyalty_points: 10,
190
+ cashback_balance: 0,
191
+ total_orders: totalOrders,
192
+ total_orders_per_platform_type: { [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: totalOrders },
193
+ voucher_codes: { [VOUCHER_CODE]: 2 },
194
+ gift_cards: {},
195
+ },
196
+ vouchers: [makeVoucher()],
197
+ giftCards: [makeGiftCard()],
198
+ customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
199
+ redeemed_offers: redeemedTimes > 0 ? { [offer._id]: redeemedTimes } : null,
200
+ platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
201
+ currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.Rs,
202
+ currentItemsPrice: 1000,
203
+ totalDiscountApplied: 0,
204
+ categories: makeCategories(),
205
+ order_discount_details: null,
206
+ });
207
+ return {
208
+ result,
209
+ stats: result.offersWithStats[0].stats,
210
+ unlockedTimes: result.unlockedOffersApplicableTimes[offer._id],
211
+ };
212
+ }
213
+ const PATHWAYS = [
214
+ constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
215
+ constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
216
+ constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
217
+ constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
218
+ ];
219
+ const REWARDS = [
220
+ constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
221
+ constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS,
222
+ constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
223
+ constants_1.OFFER_REWARD_TYPE_ENUM.POINTS,
224
+ constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
225
+ constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS,
226
+ constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER,
227
+ ];
228
+ // Blocked by the admin form: the same resource would be both price and prize.
229
+ const INVALID_CELLS = new Set([
230
+ `${constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS}:${constants_1.OFFER_REWARD_TYPE_ENUM.POINTS}`,
231
+ `${constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER}:${constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER}`,
232
+ ]);
233
+ const VALID_CELLS = [];
234
+ for (const pathway of PATHWAYS) {
235
+ for (const reward of REWARDS) {
236
+ if (!INVALID_CELLS.has(`${pathway}:${reward}`)) {
237
+ VALID_CELLS.push([pathway, reward]);
238
+ }
239
+ }
240
+ }
241
+ describe('pathway x reward matrix', () => {
242
+ it('enumerates 26 valid combinations out of 28', () => {
243
+ expect(PATHWAYS.length * REWARDS.length).toBe(28);
244
+ expect(INVALID_CELLS.size).toBe(2);
245
+ expect(VALID_CELLS).toHaveLength(26);
246
+ });
247
+ describe.each(VALID_CELLS)('%s + %s', (pathway, reward) => {
248
+ it('is never marked invalid and reaches the reward branch when unlocked', () => {
249
+ const { stats } = statsFor(makeOffer(pathway, reward, true));
250
+ expect(stats.invalid_offer).toBe(false);
251
+ expect(stats.progress).toBe(100);
252
+ expect(stats.reward_preview).not.toBeNull();
253
+ expect(stats.message).not.toMatch(/Unsupported|is empty/);
254
+ });
255
+ it('stays locked (progress < 100, not claimable) when the pathway is unmet', () => {
256
+ const { stats, unlockedTimes } = statsFor(makeOffer(pathway, reward, false));
257
+ expect(stats.invalid_offer).toBe(false);
258
+ expect(stats.progress).toBeLessThan(100);
259
+ expect(stats.claimable).toBe(false);
260
+ expect(unlockedTimes).toBeUndefined();
261
+ });
262
+ it('exposes a claimable quantity of at least one when unlocked', () => {
263
+ const { stats } = statsFor(makeOffer(pathway, reward, true));
264
+ expect(stats.applicable_quantity).toBeGreaterThanOrEqual(1);
265
+ expect(stats.action_hint).not.toBeNull();
266
+ });
267
+ });
268
+ describe('pathway gating modifiers', () => {
269
+ const ordersOffer = (orders, totalOrders = 5) => {
270
+ const offer = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, constants_1.OFFER_REWARD_TYPE_ENUM.POINTS, true);
271
+ const withOrders = {
272
+ ...offer,
273
+ pathway_to_unlock_type_orders: {
274
+ ...offer.pathway_to_unlock_type_orders,
275
+ ...orders,
276
+ },
277
+ };
278
+ return statsFor(withOrders, { totalOrders }).stats;
279
+ };
280
+ it('honours the upper spend cap', () => {
281
+ expect(ordersOffer({ max_amount: 500 }).claimable).toBe(false);
282
+ expect(ordersOffer({ max_amount: 2000 }).claimable).toBe(true);
283
+ });
284
+ it('honours the upper order-count cap', () => {
285
+ const stats = ordersOffer({ min_num_of_orders: 3, max_num_of_orders: 5 }, 6);
286
+ expect(stats.claimable).toBe(false);
287
+ expect(stats.message).toContain('not eligible');
288
+ });
289
+ it('unlocks only on every Nth order when orders_between_unlocks is set', () => {
290
+ // interval = orders_between_unlocks + 1, unlock when totalOrders % interval === 0
291
+ expect(ordersOffer({ orders_between_unlocks: 1 }, 4).claimable).toBe(true);
292
+ expect(ordersOffer({ orders_between_unlocks: 1 }, 5).claimable).toBe(false);
293
+ expect(ordersOffer({ orders_between_unlocks: 2 }, 5).claimable).toBe(false);
294
+ expect(ordersOffer({ orders_between_unlocks: 2 }, 6).claimable).toBe(true);
295
+ });
296
+ });
297
+ describe('claim counting (repeatable vs once-per-order)', () => {
298
+ // cart subtotal is 1000, so a 100 spend threshold yields 10 value chunks.
299
+ const ordersOffer = (reward, override = {}) => {
300
+ const offer = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, reward, true);
301
+ return {
302
+ ...offer,
303
+ pathway_to_unlock_type_orders: {
304
+ ...offer.pathway_to_unlock_type_orders,
305
+ total_amount: 100,
306
+ ...override,
307
+ },
308
+ };
309
+ };
310
+ it('item rewards scale with num_of_items and honour max_claims', () => {
311
+ expect(statsFor(ordersOffer(constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS)).stats.applicable_quantity).toBe(10);
312
+ expect(statsFor(ordersOffer(constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, { max_claims: 2 })).stats.applicable_quantity).toBe(2);
313
+ const twoItems = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, true);
314
+ const scaled = {
315
+ ...twoItems,
316
+ pathway_to_unlock_type_orders: { ...twoItems.pathway_to_unlock_type_orders, total_amount: 100 },
317
+ reward_items: { ...twoItems.reward_items, num_of_items: 2 },
318
+ };
319
+ expect(statsFor(scaled).stats.applicable_quantity).toBe(20);
320
+ });
321
+ it('points rewards repeat per spend chunk unless once_per_order', () => {
322
+ expect(statsFor(ordersOffer(constants_1.OFFER_REWARD_TYPE_ENUM.POINTS)).stats.applicable_quantity).toBe(10);
323
+ const once = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, constants_1.OFFER_REWARD_TYPE_ENUM.POINTS, true);
324
+ const onceOffer = {
325
+ ...once,
326
+ pathway_to_unlock_type_orders: { ...once.pathway_to_unlock_type_orders, total_amount: 100 },
327
+ reward_points: { num_of_points: 1, once_per_order: true },
328
+ };
329
+ expect(statsFor(onceOffer).stats.applicable_quantity).toBe(1);
330
+ });
331
+ it('flat cashback repeats per chunk while percentage cashback is once-per-order', () => {
332
+ expect(statsFor(ordersOffer(constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK)).stats.applicable_quantity).toBe(10);
333
+ const pct = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK, true);
334
+ const pctOffer = {
335
+ ...pct,
336
+ pathway_to_unlock_type_orders: { ...pct.pathway_to_unlock_type_orders, total_amount: 100 },
337
+ reward_cashback: {
338
+ cashback_value: 5, is_cashback_percentage: true, max_cashback_amount: null, excluded_refs: [],
339
+ },
340
+ };
341
+ expect(statsFor(pctOffer).stats.applicable_quantity).toBe(1);
342
+ });
343
+ it('once-per-order rewards never exceed one claim', () => {
344
+ for (const reward of [constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT, constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS, constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER]) {
345
+ expect(statsFor(ordersOffer(reward)).stats.applicable_quantity).toBe(1);
346
+ }
347
+ });
348
+ it('clamps the session claims to the remaining lifetime budget', () => {
349
+ expect(statsFor(ordersOffer(constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, { max_uses_per_customer: 2 })).stats.applicable_quantity).toBe(2);
350
+ });
351
+ it('caps a voucher-pathway item reward by the vouchers actually held', () => {
352
+ // The fixture wallet holds two SAVE10 codes. That cap must beat the spend
353
+ // chunk count (1000 / 1) that would otherwise apply to this pathway.
354
+ const { stats } = statsFor(makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER, constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, true));
355
+ expect(stats.claimable).toBe(true);
356
+ expect(stats.applicable_quantity).toBe(2);
357
+ });
358
+ });
359
+ describe('apply builders accept exactly their own reward type', () => {
360
+ const applyBuilders = [
361
+ { reward: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT, kind: 'discount' },
362
+ { reward: constants_1.OFFER_REWARD_TYPE_ENUM.POINTS, kind: 'points' },
363
+ { reward: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK, kind: 'cashback' },
364
+ { reward: constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS, kind: 'reward' },
365
+ { reward: constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER, kind: 'reward' },
366
+ ];
367
+ it.each(applyBuilders)('$reward is applied only by the $kind builder', ({ reward, kind }) => {
368
+ const offer = makeOffer(constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS, reward, true);
369
+ const results = {
370
+ discount: (0, offer_apply_helpers_1.buildOfferDiscountUpdate)({ offer, orderDiscountDetails: null, categories: makeCategories() }),
371
+ points: (0, offer_apply_helpers_1.buildOfferPointsUpdate)({ offer, orderDiscountDetails: null }),
372
+ cashback: (0, offer_apply_helpers_1.buildOfferCashbackUpdate)({ offer, orderDiscountDetails: null, categories: makeCategories() }),
373
+ reward: (0, offer_apply_helpers_1.buildOfferRewardUpdate)({ offer, orderDiscountDetails: null }),
374
+ };
375
+ for (const [key, result] of Object.entries(results)) {
376
+ expect({ reward, builder: key, success: result.success }).toEqual({
377
+ reward,
378
+ builder: key,
379
+ success: key === kind,
380
+ });
381
+ }
382
+ });
383
+ });
384
+ describe.each(VALID_CELLS)('%s + %s (already claimed)', (pathway, reward) => {
385
+ it('reports the claim and does not offer a duplicate', () => {
386
+ const offer = makeOffer(pathway, reward, true);
387
+ const { stats } = statsFor(offer, { redeemedTimes: 1 });
388
+ // A once-per-order reward is spent; repeatable ones keep a claim slot open.
389
+ const repeatedRewards = new Set([
390
+ constants_1.OFFER_REWARD_TYPE_ENUM.POINTS,
391
+ constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
392
+ constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
393
+ constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS,
394
+ ]);
395
+ if (!repeatedRewards.has(reward)) {
396
+ expect(stats.claimable).toBe(false);
397
+ expect(stats.message).toMatch(/redeemed/);
398
+ }
399
+ });
400
+ });
401
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.32",
3
+ "version": "0.4.34",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -1,61 +0,0 @@
1
- import { Schema } from 'mongoose';
2
- import { ALL_REWARDS_USAGE_REF_TYPES } from '../../constants';
3
- export const RewardsUsageSchema = new Schema({
4
- _id: {
5
- type: Schema.Types.ObjectId,
6
- required: true,
7
- immutable: true,
8
- },
9
- ref_id: {
10
- type: Schema.Types.ObjectId,
11
- required: true,
12
- immutable: true,
13
- },
14
- ref_type: {
15
- type: String,
16
- enum: ALL_REWARDS_USAGE_REF_TYPES,
17
- required: true,
18
- immutable: true,
19
- },
20
- customer_phone: {
21
- type: String,
22
- required: true,
23
- immutable: true,
24
- },
25
- assigned_count: {
26
- type: Number,
27
- required: true,
28
- default: 0,
29
- },
30
- last_assigned_at: {
31
- type: Schema.Types.Date,
32
- required: true,
33
- default: null,
34
- },
35
- used_count: {
36
- type: Number,
37
- required: true,
38
- default: 0,
39
- },
40
- last_used_at: {
41
- type: Schema.Types.Date,
42
- required: true,
43
- default: null,
44
- },
45
- createdAt: {
46
- type: Schema.Types.Date,
47
- required: true,
48
- default: () => new Date(),
49
- immutable: true,
50
- },
51
- updatedAt: {
52
- type: Schema.Types.Date,
53
- required: true,
54
- default: () => new Date(),
55
- },
56
- }, {
57
- timestamps: true,
58
- versionKey: false,
59
- minimize: false,
60
- });
61
- export const REWARDS_USAGE_COLLECTION_NAME = 'rewards_usage';
@@ -1,53 +0,0 @@
1
- import { Schema } from 'mongoose';
2
- export declare const RewardsUsageSchema: 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
- createdAt: NativeDate;
12
- updatedAt: NativeDate;
13
- ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
14
- ref_id: import("mongoose").Types.ObjectId;
15
- customer_phone: string;
16
- last_used_at: NativeDate;
17
- used_count: number;
18
- assigned_count: number;
19
- last_assigned_at: NativeDate;
20
- }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
21
- createdAt: NativeDate;
22
- updatedAt: NativeDate;
23
- } & {
24
- _id: import("mongoose").Types.ObjectId;
25
- createdAt: NativeDate;
26
- updatedAt: NativeDate;
27
- ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
28
- ref_id: import("mongoose").Types.ObjectId;
29
- customer_phone: string;
30
- last_used_at: NativeDate;
31
- used_count: number;
32
- assigned_count: number;
33
- last_assigned_at: NativeDate;
34
- }>> & import("mongoose").FlatRecord<{
35
- createdAt: NativeDate;
36
- updatedAt: NativeDate;
37
- } & {
38
- _id: import("mongoose").Types.ObjectId;
39
- createdAt: NativeDate;
40
- updatedAt: NativeDate;
41
- ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
42
- ref_id: import("mongoose").Types.ObjectId;
43
- customer_phone: string;
44
- last_used_at: NativeDate;
45
- used_count: number;
46
- assigned_count: number;
47
- last_assigned_at: NativeDate;
48
- }> & Required<{
49
- _id: import("mongoose").Types.ObjectId;
50
- }> & {
51
- __v: number;
52
- }>;
53
- export declare const REWARDS_USAGE_COLLECTION_NAME = "rewards_usage";
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REWARDS_USAGE_COLLECTION_NAME = exports.RewardsUsageSchema = void 0;
4
- const mongoose_1 = require("mongoose");
5
- const constants_1 = require("../../constants");
6
- exports.RewardsUsageSchema = new mongoose_1.Schema({
7
- _id: {
8
- type: mongoose_1.Schema.Types.ObjectId,
9
- required: true,
10
- immutable: true,
11
- },
12
- ref_id: {
13
- type: mongoose_1.Schema.Types.ObjectId,
14
- required: true,
15
- immutable: true,
16
- },
17
- ref_type: {
18
- type: String,
19
- enum: constants_1.ALL_REWARDS_USAGE_REF_TYPES,
20
- required: true,
21
- immutable: true,
22
- },
23
- customer_phone: {
24
- type: String,
25
- required: true,
26
- immutable: true,
27
- },
28
- assigned_count: {
29
- type: Number,
30
- required: true,
31
- default: 0,
32
- },
33
- last_assigned_at: {
34
- type: mongoose_1.Schema.Types.Date,
35
- required: true,
36
- default: null,
37
- },
38
- used_count: {
39
- type: Number,
40
- required: true,
41
- default: 0,
42
- },
43
- last_used_at: {
44
- type: mongoose_1.Schema.Types.Date,
45
- required: true,
46
- default: null,
47
- },
48
- createdAt: {
49
- type: mongoose_1.Schema.Types.Date,
50
- required: true,
51
- default: () => new Date(),
52
- immutable: true,
53
- },
54
- updatedAt: {
55
- type: mongoose_1.Schema.Types.Date,
56
- required: true,
57
- default: () => new Date(),
58
- },
59
- }, {
60
- timestamps: true,
61
- versionKey: false,
62
- minimize: false,
63
- });
64
- exports.REWARDS_USAGE_COLLECTION_NAME = 'rewards_usage';
@@ -1,13 +0,0 @@
1
- import { REWARDS_USAGE_REF_TYPE_ENUM } from '../../constants';
2
- export interface IRewardsUsage {
3
- _id: string;
4
- ref_id: string;
5
- ref_type: REWARDS_USAGE_REF_TYPE_ENUM;
6
- customer_phone: string;
7
- assigned_count: number;
8
- last_assigned_at: Date | null;
9
- used_count: number;
10
- last_used_at: Date | null;
11
- createdAt: Date;
12
- updatedAt: Date;
13
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });