@managesome/eposmatic-toolkit 0.4.36 → 0.4.38
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/materialized-reports/materialized-prep-time-classification-helpers.js +1 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +5 -14
- 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/materialized-reports/materialized-prep-time-classification-helpers.js +1 -3
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +5 -14
- 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 +96 -0
- package/lib/tests/code-redemption-helpers.test.d.ts +1 -0
- package/lib/tests/code-redemption-helpers.test.js +205 -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/materialized-reports/materialized-prep-time-close-day.test.js +1 -5
- package/lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.js +7 -5
- package/lib/tests/materialized-reports/materialized-prep-time-identity.test.js +2 -10
- package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.js +8 -13
- package/lib/tests/materialized-reports/materialized-report-drilldown-rows.test.js +1 -4
- package/lib/tests/offer-claim-regressions.test.d.ts +1 -0
- package/lib/tests/offer-claim-regressions.test.js +299 -0
- package/lib/tests/offers-matrix.test.js +53 -14
- package/lib/tests/ref-exclusion-matching.test.d.ts +1 -0
- package/lib/tests/ref-exclusion-matching.test.js +150 -0
- package/lib/tests/wallet-cashback-helpers.test.d.ts +1 -0
- package/lib/tests/wallet-cashback-helpers.test.js +95 -0
- package/package.json +1 -1
|
@@ -111,16 +111,8 @@ describe('prep time catalogue identity and coverage population', () => {
|
|
|
111
111
|
const { compiled } = readRows([first, second]);
|
|
112
112
|
const dayEntry = compiled.entries.find((entry) => entry.scope_context === 'localDate');
|
|
113
113
|
const events = Object.values(dayEntry.prep_time_entries ?? {}).flatMap((section) => section.rows);
|
|
114
|
-
expect(events.map((event) => event.item_id)).toEqual([
|
|
115
|
-
|
|
116
|
-
'menu-burger',
|
|
117
|
-
'menu-burger',
|
|
118
|
-
]);
|
|
119
|
-
expect(events.map((event) => event.order_id)).toEqual([
|
|
120
|
-
'order-a',
|
|
121
|
-
'order-a',
|
|
122
|
-
'order-b',
|
|
123
|
-
]);
|
|
114
|
+
expect(events.map((event) => event.item_id)).toEqual(['menu-burger', 'menu-burger', 'menu-burger']);
|
|
115
|
+
expect(events.map((event) => event.order_id)).toEqual(['order-a', 'order-a', 'order-b']);
|
|
124
116
|
expect(new Set(events.map((event) => event.entry_key)).size).toBe(3);
|
|
125
117
|
expect(events.map((event) => event.line_id)).toEqual(['line-a', 'line-b', 'line-c']);
|
|
126
118
|
});
|
|
@@ -432,12 +432,12 @@ describe('prep time item sorting + cursor paging', () => {
|
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
434
|
it('breaks exact sort-value ties by item_id ascending', () => {
|
|
435
|
-
const tied = [
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
435
|
+
const tied = [items()[0], { ...items()[0], item_id: 'i-0' }, { ...items()[0], item_id: 'i-z' }];
|
|
436
|
+
expect((0, materialized_prep_time_read_helpers_1.sortMaterializedPrepTimeItemRows)(tied, 'late_desc').map((item) => item.item_id)).toEqual([
|
|
437
|
+
'i-0',
|
|
438
|
+
'i-a',
|
|
439
|
+
'i-z',
|
|
440
|
+
]);
|
|
441
441
|
});
|
|
442
442
|
it('never mutates the input rows when sorting', () => {
|
|
443
443
|
const input = items();
|
|
@@ -527,9 +527,7 @@ describe('prep time categories', () => {
|
|
|
527
527
|
});
|
|
528
528
|
it('returns null stats for a measured-empty category', () => {
|
|
529
529
|
const result = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeCategoriesResult)({
|
|
530
|
-
rows: [
|
|
531
|
-
row({ anchor: 'UNMEASURED', duration_minutes: null, category_name: 'Cold' }),
|
|
532
|
-
],
|
|
530
|
+
rows: [row({ anchor: 'UNMEASURED', duration_minutes: null, category_name: 'Cold' })],
|
|
533
531
|
});
|
|
534
532
|
expect(result.rows[0].avg_minutes).toBeNull();
|
|
535
533
|
expect(result.rows[0].median_minutes).toBeNull();
|
|
@@ -568,10 +566,7 @@ describe('prep time series', () => {
|
|
|
568
566
|
];
|
|
569
567
|
it('groups by source local date ascending and never emits empty dates', () => {
|
|
570
568
|
const result = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeSeriesResult)({ rows });
|
|
571
|
-
expect(result.points.map((point) => point.local_date)).toEqual([
|
|
572
|
-
'2026-09-10',
|
|
573
|
-
'2026-09-11',
|
|
574
|
-
]);
|
|
569
|
+
expect(result.points.map((point) => point.local_date)).toEqual(['2026-09-10', '2026-09-11']);
|
|
575
570
|
expect(result.points[0]).toMatchObject({
|
|
576
571
|
served_count: 2,
|
|
577
572
|
measured_count: 1,
|
|
@@ -55,10 +55,7 @@ describe('flat drill-down row projection', () => {
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
|
-
expect(result.rows.map((entry) => entry.cursor_id)).toEqual([
|
|
59
|
-
'item:menu-1:line-a',
|
|
60
|
-
'item:menu-1:line-b',
|
|
61
|
-
]);
|
|
58
|
+
expect(result.rows.map((entry) => entry.cursor_id)).toEqual(['item:menu-1:line-a', 'item:menu-1:line-b']);
|
|
62
59
|
});
|
|
63
60
|
test('projects cash rows as drawer-ledger rows (no order id)', () => {
|
|
64
61
|
const result = (0, materialized_report_drilldown_rows_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,299 @@
|
|
|
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
|
+
{ _id: 'ci1', item_id: 'i1', name: 'A', quantity: 1, price: 1000, subtotal: 1000, tax_rate: 0, modifiers: [], special_instructions: '', item_discount_details: null },
|
|
21
|
+
{ _id: 'ci2', item_id: 'i2', name: 'B', quantity: 1, price: 500, subtotal: 500, tax_rate: 0, modifiers: [], special_instructions: '', item_discount_details: null },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
function offer(overrides) {
|
|
26
|
+
return {
|
|
27
|
+
_id: 'o',
|
|
28
|
+
name: 'Offer',
|
|
29
|
+
active: true,
|
|
30
|
+
auto_apply: false,
|
|
31
|
+
sort_id: 1,
|
|
32
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_DELIVERY],
|
|
33
|
+
offer_special_hours: null,
|
|
34
|
+
...overrides,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function ordersPathway(totalAmount) {
|
|
38
|
+
return {
|
|
39
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
40
|
+
pathway_to_unlock_type_orders: {
|
|
41
|
+
scope: 'OVERALL',
|
|
42
|
+
min_num_of_orders: 0,
|
|
43
|
+
max_num_of_orders: null,
|
|
44
|
+
total_amount: totalAmount,
|
|
45
|
+
max_amount: null,
|
|
46
|
+
orders_between_unlocks: null,
|
|
47
|
+
max_claims: null,
|
|
48
|
+
max_uses_per_customer: null,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function statsFor(offerToCheck, extra = {}) {
|
|
53
|
+
const result = (0, offers_helpers_1.getOffersWithStats)({
|
|
54
|
+
offers: [offerToCheck],
|
|
55
|
+
customer: {
|
|
56
|
+
total_orders: 3,
|
|
57
|
+
loyalty_points: 50,
|
|
58
|
+
total_orders_per_platform_type: { [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 3 },
|
|
59
|
+
voucher_codes: { SAVE: 2 },
|
|
60
|
+
...(extra.customer ?? {}),
|
|
61
|
+
},
|
|
62
|
+
vouchers: [
|
|
63
|
+
{ _id: 'v1', code: 'SAVE', active: true, max_uses: null, max_assignments: null, assigned_count: 0, used_count: 0 },
|
|
64
|
+
],
|
|
65
|
+
giftCards: [],
|
|
66
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
67
|
+
redeemed_offers: extra.redeemed ?? null,
|
|
68
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
69
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.Rs,
|
|
70
|
+
currentItemsPrice: 1500,
|
|
71
|
+
totalDiscountApplied: extra.discount ?? 0,
|
|
72
|
+
categories: extra.categories ?? categories(),
|
|
73
|
+
order_discount_details: extra.orderDiscountDetails ?? null,
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
stats: result.offersWithStats[0].stats,
|
|
77
|
+
unlocked: result.unlockedOffersApplicableTimes.o,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const twoFreeItems = {
|
|
81
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
82
|
+
reward_items: { num_of_items: 2, excluded_refs: [], exclusive_refs: [], item_ids: ['i1', 'i2'], allocation: null },
|
|
83
|
+
};
|
|
84
|
+
describe('F-02: a zero spend threshold must not multiply claims', () => {
|
|
85
|
+
it('grants one claim (not one per currency unit) for an item reward', () => {
|
|
86
|
+
const { stats } = statsFor(offer({ ...ordersPathway(0), ...twoFreeItems }));
|
|
87
|
+
// One claim x 2 items per claim.
|
|
88
|
+
expect(stats.applicable_quantity).toBe(2);
|
|
89
|
+
expect(stats.claimable).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it('keeps chunking when the threshold is real', () => {
|
|
92
|
+
const { stats } = statsFor(offer({ ...ordersPathway(100), ...twoFreeItems }));
|
|
93
|
+
// floor(1500 / 100) = 15 claims x 2 items.
|
|
94
|
+
expect(stats.applicable_quantity).toBe(30);
|
|
95
|
+
});
|
|
96
|
+
it('grants one claim for points and cashback rewards', () => {
|
|
97
|
+
expect(statsFor(offer({
|
|
98
|
+
...ordersPathway(0),
|
|
99
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.POINTS,
|
|
100
|
+
reward_points: { num_of_points: 1, once_per_order: false },
|
|
101
|
+
})).stats.applicable_quantity).toBe(1);
|
|
102
|
+
expect(statsFor(offer({
|
|
103
|
+
...ordersPathway(0),
|
|
104
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
|
|
105
|
+
reward_cashback: { cashback_value: 5, is_cashback_percentage: false, max_cashback_amount: null, excluded_refs: [] },
|
|
106
|
+
})).stats.applicable_quantity).toBe(1);
|
|
107
|
+
});
|
|
108
|
+
it('treats a negative or absent threshold as "no minimum spend"', () => {
|
|
109
|
+
expect(statsFor(offer({ ...ordersPathway(-50), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
110
|
+
expect(statsFor(offer({ ...ordersPathway(null), ...twoFreeItems })).stats.applicable_quantity).toBe(2);
|
|
111
|
+
});
|
|
112
|
+
it('still honours max_claims and the lifetime budget', () => {
|
|
113
|
+
const withMaxClaims = (maxClaims) => offer({
|
|
114
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
115
|
+
pathway_to_unlock_type_orders: {
|
|
116
|
+
scope: 'OVERALL', min_num_of_orders: 0, max_num_of_orders: null, total_amount: 100,
|
|
117
|
+
max_amount: null, orders_between_unlocks: null, max_claims: maxClaims, max_uses_per_customer: null,
|
|
118
|
+
},
|
|
119
|
+
...twoFreeItems,
|
|
120
|
+
});
|
|
121
|
+
// threshold 100 on a 1500 cart = 15 chunks, capped by max_claims (x2 items per claim)
|
|
122
|
+
expect(statsFor(withMaxClaims(1)).stats.applicable_quantity).toBe(2);
|
|
123
|
+
expect(statsFor(withMaxClaims(3)).stats.applicable_quantity).toBe(6);
|
|
124
|
+
expect(statsFor(withMaxClaims(null)).stats.applicable_quantity).toBe(30);
|
|
125
|
+
});
|
|
126
|
+
it('does not multiply claims when a POINTS reward costs zero points', () => {
|
|
127
|
+
const { stats: statsResult } = statsFor(offer({
|
|
128
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
|
|
129
|
+
pathway_to_unlock_type_points: { num_of_points: 0, total_amount: 0, max_uses_per_customer: null, max_claims: null },
|
|
130
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
131
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['i1'], allocation: null },
|
|
132
|
+
}));
|
|
133
|
+
// Was floor(points / 1) = every point the customer holds.
|
|
134
|
+
expect(statsResult.applicable_quantity).toBe(1);
|
|
135
|
+
});
|
|
136
|
+
it('still lets the vouchers held drive a voucher-pathway claim', () => {
|
|
137
|
+
const { stats } = statsFor(offer({
|
|
138
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
139
|
+
pathway_to_unlock_type_vouchers: {
|
|
140
|
+
total_amount: 0,
|
|
141
|
+
max_amount: null,
|
|
142
|
+
max_uses_per_customer: null,
|
|
143
|
+
max_claims: null,
|
|
144
|
+
voucher_ids: ['v1'],
|
|
145
|
+
},
|
|
146
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
147
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['i1'], allocation: null },
|
|
148
|
+
}));
|
|
149
|
+
// Two codes held -> two claims -> two items.
|
|
150
|
+
expect(stats.applicable_quantity).toBe(2);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('F-05: removing a reward item releases its claim', () => {
|
|
154
|
+
const paid = (id) => ({
|
|
155
|
+
_id: id, item_id: 'i1', name: 'A', quantity: 1, price: 1000, subtotal: 1000, tax_rate: 0,
|
|
156
|
+
modifiers: [], special_instructions: '', item_discount_details: null,
|
|
157
|
+
});
|
|
158
|
+
const rewardItem = (id) => ({
|
|
159
|
+
_id: id, item_id: 'i1', name: 'A', quantity: 1, price: 1000, subtotal: 0, tax_rate: 0,
|
|
160
|
+
modifiers: [], special_instructions: '',
|
|
161
|
+
item_discount_details: {
|
|
162
|
+
loyalty_discount: 100, loyalty_discount_id: 'o2', is_loyalty_discount_percentage: true, total_discount: 1000,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const cartWith = (items) => ({
|
|
166
|
+
categories: [{ category_id: 'c', name: 'C', items }],
|
|
167
|
+
order_discount_details: null,
|
|
168
|
+
redeemed_offers: { o2: 1 },
|
|
169
|
+
wallet_redemptions: null,
|
|
170
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
171
|
+
price: 1000,
|
|
172
|
+
total_discount_applied: 0,
|
|
173
|
+
});
|
|
174
|
+
it('clears the claim when the last stamped item goes', () => {
|
|
175
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), rewardItem('rw')]), { _id: 'rw' }, [], {});
|
|
176
|
+
expect(result.redeemed_offers ?? null).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
it('keeps the claim while another reward item is still stamped', () => {
|
|
179
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), rewardItem('rw'), rewardItem('rw2')]), { _id: 'rw' }, [], {});
|
|
180
|
+
expect(result.redeemed_offers).toEqual({ o2: 1 });
|
|
181
|
+
});
|
|
182
|
+
it('never touches the claim when a non-reward item is removed', () => {
|
|
183
|
+
const result = (0, cart_actions_1.getRemoveItemFromCartData)(cartWith([paid('p1'), paid('p2'), rewardItem('rw')]), { _id: 'p2' }, [], {});
|
|
184
|
+
expect(result.redeemed_offers).toEqual({ o2: 1 });
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
describe('F-01 (voucher slot): the same rule must hold there', () => {
|
|
188
|
+
const voucherOffer = (excludedRefs, discountValue = 10) => offer({
|
|
189
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
190
|
+
pathway_to_unlock_type_vouchers: {
|
|
191
|
+
total_amount: 0, max_amount: null, max_uses_per_customer: null, max_claims: null, voucher_ids: ['v1'],
|
|
192
|
+
},
|
|
193
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
194
|
+
reward_discount: {
|
|
195
|
+
discount_value: discountValue,
|
|
196
|
+
is_discount_percentage: false,
|
|
197
|
+
max_discount_amount: null,
|
|
198
|
+
max_discount_percentage: null,
|
|
199
|
+
excluded_refs: excludedRefs,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const applyAndSync = (offerToCheck) => {
|
|
203
|
+
const built = (0, offer_apply_helpers_1.buildOfferDiscountUpdate)({
|
|
204
|
+
offer: offerToCheck,
|
|
205
|
+
orderDiscountDetails: null,
|
|
206
|
+
categories: categories(),
|
|
207
|
+
});
|
|
208
|
+
const withReference = { ...built.discountDetails, voucher_reference_number: 'SAVE' };
|
|
209
|
+
const applied = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)({
|
|
210
|
+
categories: categories(),
|
|
211
|
+
order_discount_details: withReference,
|
|
212
|
+
redeemed_offers: { o: 1 },
|
|
213
|
+
wallet_redemptions: null,
|
|
214
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
215
|
+
price: 1500,
|
|
216
|
+
total_discount_applied: 0,
|
|
217
|
+
}, [], {});
|
|
218
|
+
const { unlocked } = statsFor(offerToCheck, {
|
|
219
|
+
redeemed: applied.redeemed_offers,
|
|
220
|
+
orderDiscountDetails: applied.order_discount_details,
|
|
221
|
+
categories: applied.categories,
|
|
222
|
+
discount: applied.total_discount_applied,
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
applied,
|
|
226
|
+
synced: (0, offer_apply_helpers_1.getSyncOffersWithCartData)(applied, [], {}, { o: unlocked ?? 0 }, [offerToCheck]),
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
it('keeps a fixed discount with exclusions in the voucher slot', () => {
|
|
230
|
+
const { synced } = applyAndSync(voucherOffer(['i2']));
|
|
231
|
+
expect(synced.order_discount_details?.voucher_discount).toBe(10);
|
|
232
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
233
|
+
});
|
|
234
|
+
it('clamps it to the eligible subtotal', () => {
|
|
235
|
+
const { synced } = applyAndSync(voucherOffer(['i2'], 5000));
|
|
236
|
+
expect(synced.order_discount_details?.voucher_discount).toBe(1000);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
describe('F-01: a fixed discount with exclusions survives the cart sync', () => {
|
|
240
|
+
const discountOffer = (excludedRefs, discountValue = 10) => offer({
|
|
241
|
+
...ordersPathway(1000),
|
|
242
|
+
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
243
|
+
reward_discount: {
|
|
244
|
+
discount_value: discountValue,
|
|
245
|
+
is_discount_percentage: false,
|
|
246
|
+
max_discount_amount: null,
|
|
247
|
+
max_discount_percentage: null,
|
|
248
|
+
excluded_refs: excludedRefs,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
const applyAndSync = (offerToCheck) => {
|
|
252
|
+
const built = (0, offer_apply_helpers_1.buildOfferDiscountUpdate)({
|
|
253
|
+
offer: offerToCheck,
|
|
254
|
+
orderDiscountDetails: null,
|
|
255
|
+
categories: categories(),
|
|
256
|
+
});
|
|
257
|
+
if (!built.success)
|
|
258
|
+
return { built, synced: null };
|
|
259
|
+
const applied = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)({
|
|
260
|
+
categories: categories(),
|
|
261
|
+
order_discount_details: built.discountDetails,
|
|
262
|
+
redeemed_offers: { o: 1 },
|
|
263
|
+
wallet_redemptions: null,
|
|
264
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
265
|
+
price: 1500,
|
|
266
|
+
total_discount_applied: 0,
|
|
267
|
+
}, [], {});
|
|
268
|
+
const { unlocked } = statsFor(offerToCheck, {
|
|
269
|
+
redeemed: applied.redeemed_offers,
|
|
270
|
+
orderDiscountDetails: applied.order_discount_details,
|
|
271
|
+
categories: applied.categories,
|
|
272
|
+
discount: applied.total_discount_applied,
|
|
273
|
+
});
|
|
274
|
+
return {
|
|
275
|
+
built,
|
|
276
|
+
applied,
|
|
277
|
+
synced: (0, offer_apply_helpers_1.getSyncOffersWithCartData)(applied, [], {}, { o: unlocked ?? 0 }, [offerToCheck]),
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
it('keeps the discount and its claim', () => {
|
|
281
|
+
const { synced } = applyAndSync(discountOffer(['i2']));
|
|
282
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(10);
|
|
283
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
284
|
+
});
|
|
285
|
+
it('clamps a fixed value larger than the eligible subtotal', () => {
|
|
286
|
+
const { synced } = applyAndSync(discountOffer(['i2'], 5000));
|
|
287
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(1000);
|
|
288
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
289
|
+
});
|
|
290
|
+
it('still refuses when every item is excluded', () => {
|
|
291
|
+
const { built } = applyAndSync(discountOffer(['i1', 'i2']));
|
|
292
|
+
expect(built.success).toBe(false);
|
|
293
|
+
});
|
|
294
|
+
it('is unchanged without exclusions', () => {
|
|
295
|
+
const { synced } = applyAndSync(discountOffer([]));
|
|
296
|
+
expect(synced.order_discount_details?.loyalty_discount).toBe(10);
|
|
297
|
+
expect(synced.redeemed_offers).toEqual({ o: 1 });
|
|
298
|
+
});
|
|
299
|
+
});
|
|
@@ -38,23 +38,48 @@ function makeCategories() {
|
|
|
38
38
|
function makeVoucher() {
|
|
39
39
|
const now = new Date('2026-01-01T00:00:00.000Z');
|
|
40
40
|
return {
|
|
41
|
-
_id: VOUCHER_ID,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
_id: VOUCHER_ID,
|
|
42
|
+
code: VOUCHER_CODE,
|
|
43
|
+
brand_id: 'brand_1',
|
|
44
|
+
tenants: ['tenant_1'],
|
|
45
|
+
name: 'SAVE10',
|
|
46
|
+
description: '',
|
|
47
|
+
active: true,
|
|
48
|
+
is_public: true,
|
|
49
|
+
max_uses: null,
|
|
50
|
+
max_uses_per_customer: null,
|
|
51
|
+
max_assignments: null,
|
|
52
|
+
max_assignments_per_customer: null,
|
|
53
|
+
assigned_count: 0,
|
|
54
|
+
last_assigned_at: null,
|
|
55
|
+
used_count: 0,
|
|
56
|
+
last_used_at: null,
|
|
57
|
+
expire_at: null,
|
|
58
|
+
updatedAt: now,
|
|
59
|
+
createdAt: now,
|
|
46
60
|
};
|
|
47
61
|
}
|
|
48
62
|
function makeGiftCard() {
|
|
49
63
|
const now = new Date('2026-01-01T00:00:00.000Z');
|
|
50
64
|
return {
|
|
51
|
-
_id: GIFT_CARD_ID,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
_id: GIFT_CARD_ID,
|
|
66
|
+
code: 'GC100',
|
|
67
|
+
brand_id: 'brand_1',
|
|
68
|
+
tenants: ['tenant_1'],
|
|
69
|
+
name: 'Free Broast',
|
|
70
|
+
description: '',
|
|
71
|
+
active: true,
|
|
72
|
+
max_uses: null,
|
|
73
|
+
max_uses_per_customer: null,
|
|
74
|
+
max_assignments: null,
|
|
75
|
+
max_assignments_per_customer: null,
|
|
76
|
+
assigned_count: 0,
|
|
77
|
+
used_count: 0,
|
|
78
|
+
expire_at: null,
|
|
55
79
|
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS,
|
|
56
80
|
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: [ITEM_ID], allocation: null },
|
|
57
|
-
updatedAt: now,
|
|
81
|
+
updatedAt: now,
|
|
82
|
+
createdAt: now,
|
|
58
83
|
};
|
|
59
84
|
}
|
|
60
85
|
function pathwayPayload(pathway, unlocked) {
|
|
@@ -148,7 +173,11 @@ function rewardPayload(reward) {
|
|
|
148
173
|
return {
|
|
149
174
|
reward_type: reward,
|
|
150
175
|
reward_items: {
|
|
151
|
-
num_of_items: 1,
|
|
176
|
+
num_of_items: 1,
|
|
177
|
+
excluded_refs: [],
|
|
178
|
+
exclusive_refs: [],
|
|
179
|
+
item_ids: [ITEM_ID],
|
|
180
|
+
allocation: null,
|
|
152
181
|
},
|
|
153
182
|
};
|
|
154
183
|
case constants_1.OFFER_REWARD_TYPE_ENUM.POINTS:
|
|
@@ -157,7 +186,10 @@ function rewardPayload(reward) {
|
|
|
157
186
|
return {
|
|
158
187
|
reward_type: reward,
|
|
159
188
|
reward_cashback: {
|
|
160
|
-
cashback_value: 5,
|
|
189
|
+
cashback_value: 5,
|
|
190
|
+
is_cashback_percentage: false,
|
|
191
|
+
max_cashback_amount: null,
|
|
192
|
+
excluded_refs: [],
|
|
161
193
|
},
|
|
162
194
|
};
|
|
163
195
|
case constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS:
|
|
@@ -335,13 +367,20 @@ describe('pathway x reward matrix', () => {
|
|
|
335
367
|
...pct,
|
|
336
368
|
pathway_to_unlock_type_orders: { ...pct.pathway_to_unlock_type_orders, total_amount: 100 },
|
|
337
369
|
reward_cashback: {
|
|
338
|
-
cashback_value: 5,
|
|
370
|
+
cashback_value: 5,
|
|
371
|
+
is_cashback_percentage: true,
|
|
372
|
+
max_cashback_amount: null,
|
|
373
|
+
excluded_refs: [],
|
|
339
374
|
},
|
|
340
375
|
};
|
|
341
376
|
expect(statsFor(pctOffer).stats.applicable_quantity).toBe(1);
|
|
342
377
|
});
|
|
343
378
|
it('once-per-order rewards never exceed one claim', () => {
|
|
344
|
-
for (const reward of [
|
|
379
|
+
for (const reward of [
|
|
380
|
+
constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
381
|
+
constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS,
|
|
382
|
+
constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER,
|
|
383
|
+
]) {
|
|
345
384
|
expect(statsFor(ordersOffer(reward)).stats.applicable_quantity).toBe(1);
|
|
346
385
|
}
|
|
347
386
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const common_1 = require("../helpers/utils/common");
|
|
5
|
+
const offers_helpers_1 = require("../helpers/utils/offers-helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Two different things are called "excluded_refs":
|
|
8
|
+
*
|
|
9
|
+
* - On a plain DISCOUNT / CASHBACK reward it is an **item-level** list, collected
|
|
10
|
+
* by the "Excluded Items" picker. A ref is an item id - and, because a SPECIAL
|
|
11
|
+
* or HALF_HALF order line stores its own document id in `item_id`, a special or
|
|
12
|
+
* half-half id too. These refs reduce the spend-qualification base.
|
|
13
|
+
* - On a DISCOUNT_ITEMS reward it behaves exactly like IRewardTypeItems: an
|
|
14
|
+
* **option-level** hide list, acting on the modifier tree at selection time.
|
|
15
|
+
* Which items the reward may be applied to is decided by `item_ids`. It does
|
|
16
|
+
* NOT reduce the spend-qualification base.
|
|
17
|
+
*/
|
|
18
|
+
const item = (overrides = {}) => ({
|
|
19
|
+
_id: 'cart-1',
|
|
20
|
+
item_id: 'item-broast',
|
|
21
|
+
name: 'Broast',
|
|
22
|
+
quantity: 1,
|
|
23
|
+
subtotal: 1000,
|
|
24
|
+
modifiers: [
|
|
25
|
+
{
|
|
26
|
+
_id: 'm-1',
|
|
27
|
+
ref: 'modifier-dips',
|
|
28
|
+
name: 'Dips',
|
|
29
|
+
options: [{ _id: 'o-1', ref: 'option-garlic', name: 'Garlic', price: 100, quantity: 1, modifiers: [] }],
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
item_discount_details: null,
|
|
33
|
+
...overrides,
|
|
34
|
+
});
|
|
35
|
+
const categories = [
|
|
36
|
+
{
|
|
37
|
+
category_id: 'category-broast',
|
|
38
|
+
name: 'BROAST',
|
|
39
|
+
items: [
|
|
40
|
+
item(),
|
|
41
|
+
{ _id: 'c2', item_id: 'special-1', item_type: 'SPECIAL', name: 'Deal', quantity: 1, subtotal: 800, modifiers: [], item_discount_details: null },
|
|
42
|
+
{ _id: 'c3', item_id: 'halfhalf-1', item_type: 'HALF_HALF', name: 'Half & Half', quantity: 1, subtotal: 600, modifiers: [], item_discount_details: null },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
describe('doesOrderItemMatchRefs', () => {
|
|
47
|
+
it('matches item-level ids only', () => {
|
|
48
|
+
expect((0, common_1.doesOrderItemMatchRefs)(item(), ['item-broast'])).toBe(true);
|
|
49
|
+
expect((0, common_1.doesOrderItemMatchRefs)(item(), ['special-1'])).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
it('does not treat a modifier or option ref as an item ref', () => {
|
|
52
|
+
expect((0, common_1.doesOrderItemMatchRefs)(item(), ['modifier-dips'])).toBe(false);
|
|
53
|
+
expect((0, common_1.doesOrderItemMatchRefs)(item(), ['option-garlic'])).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
it('is false for an empty list', () => {
|
|
56
|
+
expect((0, common_1.doesOrderItemMatchRefs)(item(), [])).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('calculateEligibleOfferDiscountDetails (item-level refs)', () => {
|
|
60
|
+
it('excludes by item id, special id and half-half id', () => {
|
|
61
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['item-broast']).subtotal).toBe(1400);
|
|
62
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['special-1']).subtotal).toBe(1600);
|
|
63
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['halfhalf-1']).subtotal).toBe(1800);
|
|
64
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['special-1', 'halfhalf-1']).subtotal).toBe(1000);
|
|
65
|
+
});
|
|
66
|
+
it('ignores modifier/option refs entirely', () => {
|
|
67
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['modifier-dips']).subtotal).toBe(2400);
|
|
68
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['modifier-dips']).hasExcludedRefs).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
it('excludes a whole category', () => {
|
|
71
|
+
expect((0, common_1.calculateEligibleOfferDiscountDetails)(categories, ['category-broast']).subtotal).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('DISCOUNT_ITEMS option refs do not shrink the qualification base', () => {
|
|
75
|
+
const makeOffer = (rewardType, excludedRefs) => ({
|
|
76
|
+
_id: 'offer-1',
|
|
77
|
+
name: 'Offer',
|
|
78
|
+
active: true,
|
|
79
|
+
auto_apply: false,
|
|
80
|
+
sort_id: 1,
|
|
81
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_DELIVERY],
|
|
82
|
+
offer_special_hours: null,
|
|
83
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
84
|
+
pathway_to_unlock_type_orders: {
|
|
85
|
+
scope: 'OVERALL',
|
|
86
|
+
max_uses_per_customer: null,
|
|
87
|
+
max_claims: null,
|
|
88
|
+
min_num_of_orders: 0,
|
|
89
|
+
max_num_of_orders: null,
|
|
90
|
+
total_amount: 1200,
|
|
91
|
+
max_amount: null,
|
|
92
|
+
orders_between_unlocks: null,
|
|
93
|
+
},
|
|
94
|
+
reward_type: rewardType,
|
|
95
|
+
...(rewardType === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS
|
|
96
|
+
? {
|
|
97
|
+
reward_discount_items: {
|
|
98
|
+
num_of_items: 1,
|
|
99
|
+
excluded_refs: excludedRefs,
|
|
100
|
+
exclusive_refs: [],
|
|
101
|
+
item_ids: ['item-broast'],
|
|
102
|
+
discount_value: 50,
|
|
103
|
+
is_discount_percentage: true,
|
|
104
|
+
allocation: null,
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
: {
|
|
108
|
+
reward_discount: {
|
|
109
|
+
discount_value: 50,
|
|
110
|
+
is_discount_percentage: true,
|
|
111
|
+
max_discount_amount: null,
|
|
112
|
+
max_discount_percentage: null,
|
|
113
|
+
excluded_refs: excludedRefs,
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
const stats = (rewardType, excludedRefs) => (0, offers_helpers_1.getOffersWithStats)({
|
|
118
|
+
offers: [makeOffer(rewardType, excludedRefs)],
|
|
119
|
+
customer: {
|
|
120
|
+
phone_number: '+9200000000',
|
|
121
|
+
loyalty_points: 0,
|
|
122
|
+
cashback_balance: 0,
|
|
123
|
+
total_orders: 5,
|
|
124
|
+
total_orders_per_platform_type: { [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 5 },
|
|
125
|
+
voucher_codes: {},
|
|
126
|
+
gift_cards: {},
|
|
127
|
+
},
|
|
128
|
+
vouchers: [],
|
|
129
|
+
giftCards: [],
|
|
130
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
131
|
+
redeemed_offers: null,
|
|
132
|
+
platform: constants_1.PLATFORMS_ENUM.WEB_DELIVERY,
|
|
133
|
+
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.Rs,
|
|
134
|
+
currentItemsPrice: 2400,
|
|
135
|
+
totalDiscountApplied: 0,
|
|
136
|
+
categories,
|
|
137
|
+
order_discount_details: null,
|
|
138
|
+
}).offersWithStats[0].stats;
|
|
139
|
+
it('leaves the base untouched when an option ref is listed on a DISCOUNT_ITEMS reward', () => {
|
|
140
|
+
// Cart is 2400 and the threshold is 1200: still unlocked, even though an
|
|
141
|
+
// option inside the 1000 item is listed in excluded_refs.
|
|
142
|
+
expect(stats(constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS, ['modifier-dips']).progress).toBe(100);
|
|
143
|
+
});
|
|
144
|
+
it('does shrink the base when an item id is listed on a plain DISCOUNT reward', () => {
|
|
145
|
+
// Cart 2400, threshold 1200. Excluding the 1000 item leaves 1400 -> still unlocked.
|
|
146
|
+
expect(stats(constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT, ['item-broast']).progress).toBe(100);
|
|
147
|
+
// Excluding the 1000 item and the 800 special leaves 600 -> locked.
|
|
148
|
+
expect(stats(constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT, ['item-broast', 'special-1']).progress).toBeLessThan(100);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|