@managesome/eposmatic-toolkit 0.3.6 → 0.3.7

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.
@@ -15,6 +15,7 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
15
15
  start_time: number;
16
16
  end_time: number;
17
17
  is_active: boolean;
18
+ grace_period_minutes: number;
18
19
  required_positions: import("mongoose").Types.DocumentArray<{
19
20
  count: number;
20
21
  position: string;
@@ -37,6 +38,7 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
37
38
  start_time: number;
38
39
  end_time: number;
39
40
  is_active: boolean;
41
+ grace_period_minutes: number;
40
42
  required_positions: import("mongoose").Types.DocumentArray<{
41
43
  count: number;
42
44
  position: string;
@@ -59,6 +61,7 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
59
61
  start_time: number;
60
62
  end_time: number;
61
63
  is_active: boolean;
64
+ grace_period_minutes: number;
62
65
  required_positions: import("mongoose").Types.DocumentArray<{
63
66
  count: number;
64
67
  position: string;
@@ -36,6 +36,10 @@ exports.TenantHrShiftSchema = new mongoose_1.Schema({
36
36
  type: Number,
37
37
  required: true,
38
38
  },
39
+ grace_period_minutes: {
40
+ type: Number,
41
+ default: null,
42
+ },
39
43
  required_positions: {
40
44
  type: [hrRequiredPositionSchema],
41
45
  default: [],
@@ -8,6 +8,7 @@ export interface ITenantHrShift {
8
8
  name: string;
9
9
  start_time: number;
10
10
  end_time: number;
11
+ grace_period_minutes?: number | null;
11
12
  required_positions: ITenantHrRequiredPosition[];
12
13
  is_active: boolean;
13
14
  createdAt: Date;
@@ -174,6 +174,95 @@ describe('edit-order baseline keeps the applied item reward through the full sta
174
174
  expect(getFlatItems(result.iterations?.[0]?.categories)[0]?.void_reason).toBe(constants_1.OFFER_NO_LONGER_QUALIFIED_VOID_REASON);
175
175
  });
176
176
  });
177
+ describe('edit-order baseline keeps an applied order-level discount through the full stats → sync chain', () => {
178
+ const makeOrderLevelDiscountOffer = () => makeOffer('DISCOUNT', {
179
+ included_platforms: [constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY],
180
+ pathway_to_unlock_type_orders: {
181
+ scope: 'OVERALL',
182
+ min_num_of_orders: 0,
183
+ max_num_of_orders: null,
184
+ total_amount: 1000,
185
+ max_amount: null,
186
+ orders_between_unlocks: null,
187
+ max_claims: null,
188
+ max_uses_per_customer: 1,
189
+ },
190
+ reward_discount: {
191
+ discount_value: 10,
192
+ is_discount_percentage: true,
193
+ max_discount_amount: null,
194
+ max_discount_percentage: null,
195
+ excluded_refs: [],
196
+ },
197
+ });
198
+ const makeEditOrderStats = ({ isEdit, editedOrderRedeemedOffers, }) => (0, offers_helpers_1.getOffersWithStats)({
199
+ offers: [makeOrderLevelDiscountOffer()],
200
+ customer: { total_orders: 1, loyalty_points: 0 },
201
+ vouchers: [],
202
+ giftCards: [],
203
+ customerOfferRedemptionCounts: {
204
+ USED: { [OFFER_ID]: 1 },
205
+ ASSIGNED: {},
206
+ },
207
+ redeemed_offers: { [OFFER_ID]: 1 },
208
+ platform: constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY,
209
+ currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.$,
210
+ categories: makeCategories({ subtotal: 2000 }),
211
+ currentItemsPrice: 2000,
212
+ totalDiscountApplied: 0,
213
+ order_discount_details: null,
214
+ isEdit,
215
+ editedOrderRedeemedOffers,
216
+ });
217
+ const makeDiscountOrder = () => makeOrder({
218
+ order_discount_details: {
219
+ loyalty_discount_id: OFFER_ID,
220
+ loyalty_discount_name: 'DISCOUNT threshold reward',
221
+ loyalty_discount: 10,
222
+ is_loyalty_discount_percentage: true,
223
+ total_discount: 10,
224
+ },
225
+ iterations: [{ categories: makeCategories({ subtotal: 2000 }) }],
226
+ });
227
+ it('keeps the applied discount when editing the order that consumed it', () => {
228
+ const stats = makeEditOrderStats({
229
+ isEdit: true,
230
+ editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
231
+ });
232
+ expect(stats.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
233
+ const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeDiscountOrder(), [], {}, stats.unlockedOffersApplicableTimes, [
234
+ makeOrderLevelDiscountOffer(),
235
+ ]);
236
+ expect(result.order_discount_details?.loyalty_discount_id).toBe(OFFER_ID);
237
+ });
238
+ it('clears the discount when the limit is genuinely exhausted (regression guard)', () => {
239
+ const stats = makeEditOrderStats({ isEdit: false, editedOrderRedeemedOffers: null });
240
+ expect(stats.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
241
+ const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeDiscountOrder(), [], {}, stats.unlockedOffersApplicableTimes, [
242
+ makeOrderLevelDiscountOffer(),
243
+ ]);
244
+ expect(result.order_discount_details?.loyalty_discount_id).toBeUndefined();
245
+ });
246
+ });
247
+ describe('wallet cashback discount survives the sync while its evidence is present', () => {
248
+ const makeWalletCashbackOrder = (walletRedemptions) => makeOrder({
249
+ order_discount_details: {
250
+ loyalty_discount_id: constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID,
251
+ loyalty_discount: 5,
252
+ is_loyalty_discount_percentage: false,
253
+ total_discount: 5,
254
+ },
255
+ wallet_redemptions: walletRedemptions,
256
+ });
257
+ it('keeps the wallet cashback loyalty discount when cashback evidence exists', () => {
258
+ const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeWalletCashbackOrder({ cashback_amount: 5, gift_cards: [] }), [], {}, {}, []);
259
+ expect(result.order_discount_details?.loyalty_discount_id).toBe(constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID);
260
+ });
261
+ it('clears it when the wallet evidence is gone (legacy/empty state)', () => {
262
+ const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeWalletCashbackOrder(null), [], {}, {}, []);
263
+ expect(result.order_discount_details?.loyalty_discount_id).toBeUndefined();
264
+ });
265
+ });
177
266
  describe('offer sync auto-removed items void reason', () => {
178
267
  const getFlatItems = (categories) => (categories ?? []).flatMap((category) => category.items ?? []);
179
268
  const makeIteration = (categories) => [{ categories }];
@@ -147,6 +147,25 @@ describe('getOffersWithStats — edited-order redemption baseline', () => {
147
147
  expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
148
148
  expect(stats.message).toContain('personal limit');
149
149
  });
150
+ it('ignores a provided baseline snapshot when the cart is not an edit (new order)', () => {
151
+ const result = runStats({
152
+ counts: makeUsedCounts(1),
153
+ editedOrderRedeemedOffers: { [OFFER_ID]: 1 },
154
+ });
155
+ const { stats } = result.offersWithStats[0];
156
+ // The baseline only applies to edit sessions — isEdit must be set, so a
157
+ // stray snapshot can never change new-order behavior.
158
+ expect(stats.applicable_quantity).toBe(0);
159
+ expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
160
+ expect(stats.message).toContain('personal limit');
161
+ });
162
+ it('stays fail-closed for new orders while counts are unknown (pre-change behavior)', () => {
163
+ const result = runStats({ counts: null });
164
+ const { stats } = result.offersWithStats[0];
165
+ expect(stats.applicable_quantity).toBe(0);
166
+ expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(0);
167
+ expect(stats.message).toContain('personal limit');
168
+ });
150
169
  it('preserves the claim while counts are unknown if the edited order carried it', () => {
151
170
  const result = runStats({
152
171
  counts: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",