@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.
Files changed (53) hide show
  1. package/esm/constants/accounting-templates.js +431 -0
  2. package/esm/constants/index.js +1 -0
  3. package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +1 -3
  4. package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +5 -14
  5. package/lib/constants/accounting-templates.d.ts +8 -0
  6. package/lib/constants/accounting-templates.js +434 -0
  7. package/lib/constants/index.d.ts +1 -0
  8. package/lib/constants/index.js +1 -0
  9. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +1 -3
  10. package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +5 -14
  11. package/lib/schemas/models/expense_categories.d.ts +3 -3
  12. package/lib/schemas/models/expense_details.d.ts +3 -3
  13. package/lib/schemas/models/gift_cards.d.ts +3 -3
  14. package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
  15. package/lib/schemas/models/internal_invoices.d.ts +3 -3
  16. package/lib/schemas/models/items.d.ts +12 -12
  17. package/lib/schemas/models/marketing_fingerprints.d.ts +3 -3
  18. package/lib/schemas/models/modifier_extras.d.ts +3 -3
  19. package/lib/schemas/models/offers.d.ts +3 -3
  20. package/lib/schemas/models/public_holidays.d.ts +3 -3
  21. package/lib/schemas/models/specials.d.ts +3 -3
  22. package/lib/schemas/models/tenant_chart_of_accounts.d.ts +3 -3
  23. package/lib/schemas/models/tenant_hr_departments.d.ts +3 -3
  24. package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
  25. package/lib/schemas/models/tenant_hr_policies.d.ts +3 -3
  26. package/lib/schemas/models/tenant_hr_positions.d.ts +3 -3
  27. package/lib/schemas/models/tenant_journal_entries.d.ts +3 -3
  28. package/lib/schemas/models/void_order_items.d.ts +3 -3
  29. package/lib/schemas/models/vouchers.d.ts +3 -3
  30. package/lib/schemas/models/warehouse_communications.d.ts +3 -3
  31. package/lib/schemas/models/warehouse_items.d.ts +3 -3
  32. package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +3 -3
  33. package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +3 -3
  34. package/lib/schemas/types/tenant_chart_of_accounts.d.ts +7 -0
  35. package/lib/tests/cart-helpers-edit-item-refs.test.d.ts +1 -0
  36. package/lib/tests/cart-helpers-edit-item-refs.test.js +96 -0
  37. package/lib/tests/code-redemption-helpers.test.d.ts +1 -0
  38. package/lib/tests/code-redemption-helpers.test.js +205 -0
  39. package/lib/tests/gift-card-helpers.test.d.ts +1 -0
  40. package/lib/tests/gift-card-helpers.test.js +100 -0
  41. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +1 -5
  42. package/lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.js +7 -5
  43. package/lib/tests/materialized-reports/materialized-prep-time-identity.test.js +2 -10
  44. package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.js +8 -13
  45. package/lib/tests/materialized-reports/materialized-report-drilldown-rows.test.js +1 -4
  46. package/lib/tests/offer-claim-regressions.test.d.ts +1 -0
  47. package/lib/tests/offer-claim-regressions.test.js +299 -0
  48. package/lib/tests/offers-matrix.test.js +53 -14
  49. package/lib/tests/ref-exclusion-matching.test.d.ts +1 -0
  50. package/lib/tests/ref-exclusion-matching.test.js +150 -0
  51. package/lib/tests/wallet-cashback-helpers.test.d.ts +1 -0
  52. package/lib/tests/wallet-cashback-helpers.test.js +95 -0
  53. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const offers_helpers_1 = require("../helpers/utils/offers-helpers");
4
+ /**
5
+ * The cashback half of the wallet, which had no tests at all.
6
+ *
7
+ * `getMaxApplicableWalletCashback` is what the cashback slider is bounded by, so
8
+ * an off-by-one here either lets the customer spend more than the order is worth
9
+ * or hides cashback they own.
10
+ */
11
+ describe('getMaxApplicableWalletCashback', () => {
12
+ const base = { cashbackBalance: 500, itemsPrice: 1000, totalDiscountApplied: 0, orderLevelDiscount: 0 };
13
+ it('is capped by the wallet balance', () => {
14
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)(base)).toBe(500);
15
+ });
16
+ it('is capped by the net items value when cashback is larger', () => {
17
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, cashbackBalance: 5000 })).toBe(1000);
18
+ });
19
+ it('ignores order-level discounts but subtracts item-level ones', () => {
20
+ // order-level only: net value is still the full 1000
21
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, totalDiscountApplied: 200, orderLevelDiscount: 200 })).toBe(500);
22
+ // item-level: 1000 - 200 = 800
23
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, totalDiscountApplied: 200, orderLevelDiscount: 0 })).toBe(500);
24
+ // item-level discount bigger than the balance -> balance is the cap
25
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, cashbackBalance: 900, totalDiscountApplied: 300, orderLevelDiscount: 0 })).toBe(700);
26
+ });
27
+ it('never goes negative or NaN', () => {
28
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, cashbackBalance: -50 })).toBe(0);
29
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ cashbackBalance: NaN, itemsPrice: NaN, totalDiscountApplied: NaN, orderLevelDiscount: NaN })).toBe(0);
30
+ expect((0, offers_helpers_1.getMaxApplicableWalletCashback)({ ...base, cashbackBalance: 5000, itemsPrice: 0 })).toBe(0);
31
+ });
32
+ });
33
+ describe('cashback recommended breakpoints', () => {
34
+ it('splits the applicable amount into the default 25/50/75/100 steps', () => {
35
+ expect((0, offers_helpers_1.getWalletCashbackRecommendedValues)({ maxApplicableCashback: 100 })).toEqual([25, 50, 75, 100]);
36
+ });
37
+ it('keeps the percentage when the amount rounds', () => {
38
+ const breakpoints = (0, offers_helpers_1.getWalletCashbackRecommendedBreakpoints)({ maxApplicableCashback: 10 });
39
+ expect(breakpoints).toEqual([
40
+ { value: 2.5, percentage: 25 },
41
+ { value: 5, percentage: 50 },
42
+ { value: 7.5, percentage: 75 },
43
+ { value: 10, percentage: 100 },
44
+ ]);
45
+ });
46
+ it('returns nothing when there is nothing applicable', () => {
47
+ expect((0, offers_helpers_1.getWalletCashbackRecommendedValues)({ maxApplicableCashback: 0 })).toEqual([]);
48
+ expect((0, offers_helpers_1.getWalletCashbackRecommendedValues)({ maxApplicableCashback: null })).toEqual([]);
49
+ });
50
+ it('accepts custom steps and clamps percentages to 0..100', () => {
51
+ expect((0, offers_helpers_1.getWalletCashbackRecommendedBreakpoints)({ maxApplicableCashback: 100, percentageSteps: [10, 200] })).toEqual([
52
+ { value: 10, percentage: 10 },
53
+ { value: 100, percentage: 100 },
54
+ ]);
55
+ });
56
+ });
57
+ describe('wallet redemption patches', () => {
58
+ it('sets the cashback amount and keeps gift cards', () => {
59
+ const patch = (0, offers_helpers_1.buildWalletCashbackRedemptionPatch)({
60
+ currentWalletRedemptions: { gift_cards: [{ gift_card_id: 'gc-1', redeemed_times: 1 }] },
61
+ cashbackAmount: 25,
62
+ });
63
+ expect(patch.wallet_redemptions.cashback_amount).toBe(25);
64
+ expect(patch.wallet_redemptions.gift_cards).toEqual([{ gift_card_id: 'gc-1', redeemed_times: 1 }]);
65
+ });
66
+ it('drops a zero cashback amount instead of writing 0', () => {
67
+ const patch = (0, offers_helpers_1.buildWalletCashbackRedemptionPatch)({ currentWalletRedemptions: null, cashbackAmount: 0 });
68
+ expect(patch.wallet_redemptions).toBeNull();
69
+ });
70
+ it('clears only cashback when asked, leaving gift cards intact', () => {
71
+ const patch = (0, offers_helpers_1.buildClearWalletRedemptionsPatch)({
72
+ currentWalletRedemptions: {
73
+ cashback_amount: 25,
74
+ gift_cards: [{ gift_card_id: 'gc-1', redeemed_times: 1 }],
75
+ },
76
+ clearCashbackAmount: true,
77
+ });
78
+ expect(patch.wallet_redemptions.cashback_amount).toBeUndefined();
79
+ expect(patch.wallet_redemptions.gift_cards).toEqual([{ gift_card_id: 'gc-1', redeemed_times: 1 }]);
80
+ });
81
+ it('clears everything when clearAll is set', () => {
82
+ const patch = (0, offers_helpers_1.buildClearWalletRedemptionsPatch)({
83
+ currentWalletRedemptions: { cashback_amount: 25, gift_cards: [{ gift_card_id: 'gc-1', redeemed_times: 1 }] },
84
+ clearAll: true,
85
+ });
86
+ expect(patch.wallet_redemptions).toBeNull();
87
+ });
88
+ it('merges a partial patch over the existing redemptions', () => {
89
+ const patch = (0, offers_helpers_1.buildWalletRedemptionsMergePatch)({
90
+ currentWalletRedemptions: { cashback_amount: 10 },
91
+ walletRedemptionsPatch: { cashback_amount: 40 },
92
+ });
93
+ expect(patch.wallet_redemptions.cashback_amount).toBe(40);
94
+ });
95
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.36",
3
+ "version": "0.4.38",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",