@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
|
@@ -7,6 +7,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
code: string;
|
|
11
12
|
_id: import("mongoose").Types.ObjectId;
|
|
12
13
|
name: string;
|
|
@@ -15,7 +16,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
15
16
|
brand_id: string;
|
|
16
17
|
tenants: string[];
|
|
17
18
|
active: boolean;
|
|
18
|
-
description: string;
|
|
19
19
|
is_public: boolean;
|
|
20
20
|
used_count: number;
|
|
21
21
|
assigned_count: number;
|
|
@@ -30,6 +30,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
30
30
|
createdAt: NativeDate;
|
|
31
31
|
updatedAt: NativeDate;
|
|
32
32
|
} & {
|
|
33
|
+
description: string;
|
|
33
34
|
code: string;
|
|
34
35
|
_id: import("mongoose").Types.ObjectId;
|
|
35
36
|
name: string;
|
|
@@ -38,7 +39,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
38
39
|
brand_id: string;
|
|
39
40
|
tenants: string[];
|
|
40
41
|
active: boolean;
|
|
41
|
-
description: string;
|
|
42
42
|
is_public: boolean;
|
|
43
43
|
used_count: number;
|
|
44
44
|
assigned_count: number;
|
|
@@ -53,6 +53,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
53
53
|
createdAt: NativeDate;
|
|
54
54
|
updatedAt: NativeDate;
|
|
55
55
|
} & {
|
|
56
|
+
description: string;
|
|
56
57
|
code: string;
|
|
57
58
|
_id: import("mongoose").Types.ObjectId;
|
|
58
59
|
name: string;
|
|
@@ -61,7 +62,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
|
|
|
61
62
|
brand_id: string;
|
|
62
63
|
tenants: string[];
|
|
63
64
|
active: boolean;
|
|
64
|
-
description: string;
|
|
65
65
|
is_public: boolean;
|
|
66
66
|
used_count: number;
|
|
67
67
|
assigned_count: number;
|
|
@@ -8,10 +8,10 @@ export declare const WarehouseCommunicationsSchema: Schema<any, import("mongoose
|
|
|
8
8
|
createdAt: NativeDate;
|
|
9
9
|
updatedAt: NativeDate;
|
|
10
10
|
} & {
|
|
11
|
+
description: string;
|
|
11
12
|
_id: import("mongoose").Types.ObjectId;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
|
-
description: string;
|
|
15
15
|
to: string;
|
|
16
16
|
warehouse_id: string;
|
|
17
17
|
document_kind: import("../../constants").EMAIL_DOCUMENT_KIND_ENUM;
|
|
@@ -81,10 +81,10 @@ export declare const WarehouseCommunicationsSchema: Schema<any, import("mongoose
|
|
|
81
81
|
createdAt: NativeDate;
|
|
82
82
|
updatedAt: NativeDate;
|
|
83
83
|
} & {
|
|
84
|
+
description: string;
|
|
84
85
|
_id: import("mongoose").Types.ObjectId;
|
|
85
86
|
createdAt: NativeDate;
|
|
86
87
|
updatedAt: NativeDate;
|
|
87
|
-
description: string;
|
|
88
88
|
to: string;
|
|
89
89
|
warehouse_id: string;
|
|
90
90
|
document_kind: import("../../constants").EMAIL_DOCUMENT_KIND_ENUM;
|
|
@@ -154,10 +154,10 @@ export declare const WarehouseCommunicationsSchema: Schema<any, import("mongoose
|
|
|
154
154
|
createdAt: NativeDate;
|
|
155
155
|
updatedAt: NativeDate;
|
|
156
156
|
} & {
|
|
157
|
+
description: string;
|
|
157
158
|
_id: import("mongoose").Types.ObjectId;
|
|
158
159
|
createdAt: NativeDate;
|
|
159
160
|
updatedAt: NativeDate;
|
|
160
|
-
description: string;
|
|
161
161
|
to: string;
|
|
162
162
|
warehouse_id: string;
|
|
163
163
|
document_kind: import("../../constants").EMAIL_DOCUMENT_KIND_ENUM;
|
|
@@ -8,6 +8,7 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
8
8
|
createdAt: NativeDate;
|
|
9
9
|
updatedAt: NativeDate;
|
|
10
10
|
} & {
|
|
11
|
+
description: string;
|
|
11
12
|
_id: import("mongoose").Types.ObjectId;
|
|
12
13
|
type: import("../../constants").INVENTORY_ITEM_TYPE_ENUM;
|
|
13
14
|
name: string;
|
|
@@ -17,7 +18,6 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
17
18
|
brand_id: string;
|
|
18
19
|
active: boolean;
|
|
19
20
|
sort_id: number;
|
|
20
|
-
description: string;
|
|
21
21
|
inventory_code: string;
|
|
22
22
|
ingredients: import("mongoose").Types.DocumentArray<{
|
|
23
23
|
inventory_code: string;
|
|
@@ -57,6 +57,7 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
57
57
|
createdAt: NativeDate;
|
|
58
58
|
updatedAt: NativeDate;
|
|
59
59
|
} & {
|
|
60
|
+
description: string;
|
|
60
61
|
_id: import("mongoose").Types.ObjectId;
|
|
61
62
|
type: import("../../constants").INVENTORY_ITEM_TYPE_ENUM;
|
|
62
63
|
name: string;
|
|
@@ -66,7 +67,6 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
66
67
|
brand_id: string;
|
|
67
68
|
active: boolean;
|
|
68
69
|
sort_id: number;
|
|
69
|
-
description: string;
|
|
70
70
|
inventory_code: string;
|
|
71
71
|
ingredients: import("mongoose").Types.DocumentArray<{
|
|
72
72
|
inventory_code: string;
|
|
@@ -106,6 +106,7 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
106
106
|
createdAt: NativeDate;
|
|
107
107
|
updatedAt: NativeDate;
|
|
108
108
|
} & {
|
|
109
|
+
description: string;
|
|
109
110
|
_id: import("mongoose").Types.ObjectId;
|
|
110
111
|
type: import("../../constants").INVENTORY_ITEM_TYPE_ENUM;
|
|
111
112
|
name: string;
|
|
@@ -115,7 +116,6 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
115
116
|
brand_id: string;
|
|
116
117
|
active: boolean;
|
|
117
118
|
sort_id: number;
|
|
118
|
-
description: string;
|
|
119
119
|
inventory_code: string;
|
|
120
120
|
ingredients: import("mongoose").Types.DocumentArray<{
|
|
121
121
|
inventory_code: string;
|
|
@@ -7,11 +7,11 @@ export declare const VoidPurchaseOrderItemSchema: Schema<any, import("mongoose")
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
name: string;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
|
-
description: string;
|
|
15
15
|
createdAt_mins: number;
|
|
16
16
|
order_id: import("mongoose").Types.ObjectId;
|
|
17
17
|
order_number: number;
|
|
@@ -62,11 +62,11 @@ export declare const VoidPurchaseOrderItemSchema: Schema<any, import("mongoose")
|
|
|
62
62
|
createdAt: NativeDate;
|
|
63
63
|
updatedAt: NativeDate;
|
|
64
64
|
} & {
|
|
65
|
+
description: string;
|
|
65
66
|
_id: import("mongoose").Types.ObjectId;
|
|
66
67
|
name: string;
|
|
67
68
|
createdAt: NativeDate;
|
|
68
69
|
updatedAt: NativeDate;
|
|
69
|
-
description: string;
|
|
70
70
|
createdAt_mins: number;
|
|
71
71
|
order_id: import("mongoose").Types.ObjectId;
|
|
72
72
|
order_number: number;
|
|
@@ -117,11 +117,11 @@ export declare const VoidPurchaseOrderItemSchema: Schema<any, import("mongoose")
|
|
|
117
117
|
createdAt: NativeDate;
|
|
118
118
|
updatedAt: NativeDate;
|
|
119
119
|
} & {
|
|
120
|
+
description: string;
|
|
120
121
|
_id: import("mongoose").Types.ObjectId;
|
|
121
122
|
name: string;
|
|
122
123
|
createdAt: NativeDate;
|
|
123
124
|
updatedAt: NativeDate;
|
|
124
|
-
description: string;
|
|
125
125
|
createdAt_mins: number;
|
|
126
126
|
order_id: import("mongoose").Types.ObjectId;
|
|
127
127
|
order_number: number;
|
|
@@ -7,11 +7,11 @@ export declare const VoidSaleOrderItemSchema: Schema<any, import("mongoose").Mod
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
name: string;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
|
-
description: string;
|
|
15
15
|
createdAt_mins: number;
|
|
16
16
|
order_id: import("mongoose").Types.ObjectId;
|
|
17
17
|
order_number: number;
|
|
@@ -62,11 +62,11 @@ export declare const VoidSaleOrderItemSchema: Schema<any, import("mongoose").Mod
|
|
|
62
62
|
createdAt: NativeDate;
|
|
63
63
|
updatedAt: NativeDate;
|
|
64
64
|
} & {
|
|
65
|
+
description: string;
|
|
65
66
|
_id: import("mongoose").Types.ObjectId;
|
|
66
67
|
name: string;
|
|
67
68
|
createdAt: NativeDate;
|
|
68
69
|
updatedAt: NativeDate;
|
|
69
|
-
description: string;
|
|
70
70
|
createdAt_mins: number;
|
|
71
71
|
order_id: import("mongoose").Types.ObjectId;
|
|
72
72
|
order_number: number;
|
|
@@ -117,11 +117,11 @@ export declare const VoidSaleOrderItemSchema: Schema<any, import("mongoose").Mod
|
|
|
117
117
|
createdAt: NativeDate;
|
|
118
118
|
updatedAt: NativeDate;
|
|
119
119
|
} & {
|
|
120
|
+
description: string;
|
|
120
121
|
_id: import("mongoose").Types.ObjectId;
|
|
121
122
|
name: string;
|
|
122
123
|
createdAt: NativeDate;
|
|
123
124
|
updatedAt: NativeDate;
|
|
124
|
-
description: string;
|
|
125
125
|
createdAt_mins: number;
|
|
126
126
|
order_id: import("mongoose").Types.ObjectId;
|
|
127
127
|
order_number: number;
|
|
@@ -21,3 +21,10 @@ export interface ITenantChartOfAccount {
|
|
|
21
21
|
createdAt: Date;
|
|
22
22
|
updatedAt: Date;
|
|
23
23
|
}
|
|
24
|
+
/** Static seed row for a chart-of-accounts template (not a collection document). */
|
|
25
|
+
export interface IAccountTemplateEntry {
|
|
26
|
+
code: string;
|
|
27
|
+
name: string;
|
|
28
|
+
type: ACCOUNT_TYPE_ENUM;
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const cart_helpers_1 = require("../helpers/utils/cart-helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Editing an already-applied reward item has to carry two different ref lists:
|
|
7
|
+
*
|
|
8
|
+
* - excluded_refs -> "Hide Options" -> props.excludeRefs
|
|
9
|
+
* - exclusive_refs -> "Discount Not Applicable" -> props.excludedDiscountRefs
|
|
10
|
+
*
|
|
11
|
+
* They were crossed: the hide list was never passed and the no-discount slot
|
|
12
|
+
* received the hide list, so editing a reward item hid nothing and price-protected
|
|
13
|
+
* the wrong options. Every reward screen in every app uses the correct mapping,
|
|
14
|
+
* so this pins the edit path to the same contract.
|
|
15
|
+
*/
|
|
16
|
+
const HIDE_REF = 'mod-hide';
|
|
17
|
+
const NO_DISCOUNT_REF = 'mod-nodiscount';
|
|
18
|
+
function makeOffer(rewardType) {
|
|
19
|
+
const base = {
|
|
20
|
+
_id: 'offer-1',
|
|
21
|
+
name: 'Reward',
|
|
22
|
+
active: true,
|
|
23
|
+
auto_apply: false,
|
|
24
|
+
sort_id: 1,
|
|
25
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_DELIVERY],
|
|
26
|
+
offer_special_hours: null,
|
|
27
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
28
|
+
reward_type: rewardType,
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
...base,
|
|
32
|
+
...(rewardType === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS
|
|
33
|
+
? {
|
|
34
|
+
reward_items: {
|
|
35
|
+
num_of_items: 1,
|
|
36
|
+
excluded_refs: [HIDE_REF],
|
|
37
|
+
exclusive_refs: [NO_DISCOUNT_REF],
|
|
38
|
+
item_ids: ['item-1'],
|
|
39
|
+
allocation: null,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
reward_discount_items: {
|
|
44
|
+
num_of_items: 1,
|
|
45
|
+
excluded_refs: [HIDE_REF],
|
|
46
|
+
exclusive_refs: [NO_DISCOUNT_REF],
|
|
47
|
+
item_ids: ['item-1'],
|
|
48
|
+
discount_value: 50,
|
|
49
|
+
is_discount_percentage: true,
|
|
50
|
+
allocation: null,
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function editProps(rewardType, appliedAs) {
|
|
56
|
+
return (0, cart_helpers_1.getEditItemProps)({
|
|
57
|
+
item: { _id: 'item-1' },
|
|
58
|
+
orderItemCategoryId: 'category-1',
|
|
59
|
+
orderItem: {
|
|
60
|
+
_id: 'order-item-1',
|
|
61
|
+
item_type: 'ITEM',
|
|
62
|
+
quantity: 1,
|
|
63
|
+
item_discount_details: appliedAs === 'loyalty'
|
|
64
|
+
? { loyalty_discount_id: 'offer-1' }
|
|
65
|
+
: { voucher_discount_id: 'offer-1' },
|
|
66
|
+
},
|
|
67
|
+
offers: [makeOffer(rewardType)],
|
|
68
|
+
isLoyaltyDiscountApplied: appliedAs === 'loyalty',
|
|
69
|
+
isVoucherDiscountApplied: appliedAs === 'voucher',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
describe('getEditItemProps ref mapping', () => {
|
|
73
|
+
it.each([constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS])('maps hide and no-discount refs correctly for %s rewards', (rewardType) => {
|
|
74
|
+
const props = editProps(rewardType, 'loyalty');
|
|
75
|
+
expect(props.excludeRefs).toEqual([HIDE_REF]);
|
|
76
|
+
expect(props.excludedDiscountRefs).toEqual([NO_DISCOUNT_REF]);
|
|
77
|
+
// The reward item itself is always excluded from its own discount.
|
|
78
|
+
expect(props.applyLoyalty.refs).toEqual([NO_DISCOUNT_REF, 'item-1']);
|
|
79
|
+
});
|
|
80
|
+
it.each([constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS, constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS])('maps hide and no-discount refs correctly for %s rewards applied by voucher', (rewardType) => {
|
|
81
|
+
const props = editProps(rewardType, 'voucher');
|
|
82
|
+
expect(props.excludeRefs).toEqual([HIDE_REF]);
|
|
83
|
+
expect(props.excludedDiscountRefs).toEqual([NO_DISCOUNT_REF]);
|
|
84
|
+
expect(props.applyVoucher.refs).toEqual([NO_DISCOUNT_REF, 'item-1']);
|
|
85
|
+
});
|
|
86
|
+
it('returns undefined when the reward item has no matching offer', () => {
|
|
87
|
+
expect((0, cart_helpers_1.getEditItemProps)({
|
|
88
|
+
item: { _id: 'item-1' },
|
|
89
|
+
orderItemCategoryId: 'category-1',
|
|
90
|
+
orderItem: { _id: 'oi-1', item_type: 'ITEM', quantity: 1, item_discount_details: { loyalty_discount_id: 'missing' } },
|
|
91
|
+
offers: [],
|
|
92
|
+
isLoyaltyDiscountApplied: true,
|
|
93
|
+
isVoucherDiscountApplied: false,
|
|
94
|
+
})).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const code_redemption_helpers_1 = require("../helpers/utils/code-redemption-helpers");
|
|
5
|
+
/**
|
|
6
|
+
* The code-redemption module (705 lines) had no tests at all, yet it is what
|
|
7
|
+
* decides whether a customer may spend a gift card or a voucher. Every gate here
|
|
8
|
+
* protects money: a wrong `claimable` either blocks a paid-for asset or gives one
|
|
9
|
+
* away.
|
|
10
|
+
*/
|
|
11
|
+
const now = new Date('2026-01-01T00:00:00.000Z');
|
|
12
|
+
function voucher(overrides = {}) {
|
|
13
|
+
return {
|
|
14
|
+
_id: 'voucher-1', code: 'SAVE10', brand_id: 'b', tenants: ['t'], name: 'SAVE10', description: '',
|
|
15
|
+
active: true, is_public: true, max_uses: null, max_uses_per_customer: null,
|
|
16
|
+
max_assignments: null, max_assignments_per_customer: null,
|
|
17
|
+
assigned_count: 0, last_assigned_at: null, used_count: 0, last_used_at: null, expire_at: null,
|
|
18
|
+
updatedAt: now, createdAt: now, ...overrides,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function giftCard(overrides = {}) {
|
|
22
|
+
return {
|
|
23
|
+
_id: 'gc-1', code: 'GC100', brand_id: 'b', tenants: ['t'], name: 'Free Broast', description: '',
|
|
24
|
+
active: true, max_uses: null, max_uses_per_customer: null,
|
|
25
|
+
max_assignments: null, max_assignments_per_customer: null,
|
|
26
|
+
assigned_count: 0, used_count: 0, expire_at: null,
|
|
27
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS,
|
|
28
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['item-1'], allocation: null },
|
|
29
|
+
updatedAt: now, createdAt: now, ...overrides,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
describe('getDirectWalletGiftCardUsageGate', () => {
|
|
33
|
+
it('blocks an inactive gift card', () => {
|
|
34
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
35
|
+
giftCard: giftCard({ active: false }),
|
|
36
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
37
|
+
});
|
|
38
|
+
expect(gate.blocked).toBe(true);
|
|
39
|
+
expect(gate.message).toContain('not available');
|
|
40
|
+
});
|
|
41
|
+
it('blocks a gift card that has been fully used', () => {
|
|
42
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
43
|
+
giftCard: giftCard({ max_uses: 2, used_count: 2 }),
|
|
44
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
45
|
+
});
|
|
46
|
+
expect(gate.blocked).toBe(true);
|
|
47
|
+
expect(gate.message).toContain('fully used');
|
|
48
|
+
});
|
|
49
|
+
it('allows an uncapped gift card', () => {
|
|
50
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
51
|
+
giftCard: giftCard(),
|
|
52
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
53
|
+
});
|
|
54
|
+
expect(gate.blocked).toBe(false);
|
|
55
|
+
expect(gate.message).toBeNull();
|
|
56
|
+
});
|
|
57
|
+
it('blocks when a per-customer cap exists but the counts are unknown (fail closed)', () => {
|
|
58
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
59
|
+
giftCard: giftCard({ max_uses_per_customer: 3 }),
|
|
60
|
+
customerOfferRedemptionCounts: null,
|
|
61
|
+
});
|
|
62
|
+
expect(gate.blocked).toBe(true);
|
|
63
|
+
expect(gate.message).toContain('Unable to verify');
|
|
64
|
+
});
|
|
65
|
+
it('blocks once the per-customer cap is reached', () => {
|
|
66
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
67
|
+
giftCard: giftCard({ max_uses_per_customer: 2 }),
|
|
68
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: { 'gc-1': 2 } },
|
|
69
|
+
});
|
|
70
|
+
expect(gate.blocked).toBe(true);
|
|
71
|
+
expect(gate.message).toContain('personal limit');
|
|
72
|
+
});
|
|
73
|
+
it('allows the claim below the per-customer cap', () => {
|
|
74
|
+
const gate = (0, code_redemption_helpers_1.getDirectWalletGiftCardUsageGate)({
|
|
75
|
+
giftCard: giftCard({ max_uses_per_customer: 2 }),
|
|
76
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: { 'gc-1': 1 } },
|
|
77
|
+
});
|
|
78
|
+
expect(gate.blocked).toBe(false);
|
|
79
|
+
expect(gate.usedCount).toBe(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('getGiftCardRewardVoucherAssignmentGate', () => {
|
|
83
|
+
const voucherRewardGiftCard = (overrides = {}) => giftCard({
|
|
84
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER,
|
|
85
|
+
reward_items: null,
|
|
86
|
+
reward_voucher: { voucher_ids: { 'voucher-1': 1 } },
|
|
87
|
+
...overrides,
|
|
88
|
+
});
|
|
89
|
+
it('is a no-op for a gift card that grants no voucher', () => {
|
|
90
|
+
const gate = (0, code_redemption_helpers_1.getGiftCardRewardVoucherAssignmentGate)({
|
|
91
|
+
giftCard: giftCard(),
|
|
92
|
+
vouchers: [voucher()],
|
|
93
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
94
|
+
});
|
|
95
|
+
expect(gate.blocked).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
it('blocks when the reward voucher is inactive', () => {
|
|
98
|
+
const gate = (0, code_redemption_helpers_1.getGiftCardRewardVoucherAssignmentGate)({
|
|
99
|
+
giftCard: voucherRewardGiftCard(),
|
|
100
|
+
vouchers: [voucher({ active: false })],
|
|
101
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
102
|
+
});
|
|
103
|
+
expect(gate.blocked).toBe(true);
|
|
104
|
+
expect(gate.message).toContain('not available');
|
|
105
|
+
});
|
|
106
|
+
it('blocks when the reward voucher has no assignment headroom left', () => {
|
|
107
|
+
// The gate answers "would THIS claim fit", so it needs the pending increment.
|
|
108
|
+
const gate = (0, code_redemption_helpers_1.getGiftCardRewardVoucherAssignmentGate)({
|
|
109
|
+
giftCard: voucherRewardGiftCard(),
|
|
110
|
+
vouchers: [voucher({ max_assignments: 2, assigned_count: 2 })],
|
|
111
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
112
|
+
claimsIncrement: 1,
|
|
113
|
+
});
|
|
114
|
+
expect(gate.blocked).toBe(true);
|
|
115
|
+
expect(gate.message).toContain('no longer available');
|
|
116
|
+
});
|
|
117
|
+
it('blocks when the per-customer assignment cap is reached', () => {
|
|
118
|
+
const gate = (0, code_redemption_helpers_1.getGiftCardRewardVoucherAssignmentGate)({
|
|
119
|
+
giftCard: voucherRewardGiftCard(),
|
|
120
|
+
vouchers: [voucher({ max_assignments_per_customer: 1 })],
|
|
121
|
+
customerOfferRedemptionCounts: { ASSIGNED: { 'voucher-1': 1 }, USED: {} },
|
|
122
|
+
claimsIncrement: 1,
|
|
123
|
+
});
|
|
124
|
+
expect(gate.blocked).toBe(true);
|
|
125
|
+
expect(gate.message).toContain('personal limit');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('buildValidatedWalletGiftCardRedemptionClaimPatch', () => {
|
|
129
|
+
const base = {
|
|
130
|
+
currentWalletRedemptions: null,
|
|
131
|
+
vouchers: [],
|
|
132
|
+
customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
133
|
+
};
|
|
134
|
+
it('refuses an inactive gift card and explains why', () => {
|
|
135
|
+
const result = (0, code_redemption_helpers_1.buildValidatedWalletGiftCardRedemptionClaimPatch)({
|
|
136
|
+
...base,
|
|
137
|
+
giftCard: giftCard({ active: false }),
|
|
138
|
+
});
|
|
139
|
+
expect(result.success).toBe(false);
|
|
140
|
+
expect(result.errorMessage).toContain('not available');
|
|
141
|
+
expect(result.walletPatch).toEqual({});
|
|
142
|
+
});
|
|
143
|
+
it('claims a healthy gift card and records the redemption', () => {
|
|
144
|
+
const result = (0, code_redemption_helpers_1.buildValidatedWalletGiftCardRedemptionClaimPatch)({
|
|
145
|
+
...base,
|
|
146
|
+
giftCard: giftCard(),
|
|
147
|
+
});
|
|
148
|
+
expect(result.success).toBe(true);
|
|
149
|
+
expect(result.errorMessage).toBeNull();
|
|
150
|
+
expect(result.walletPatch.wallet_redemptions.gift_cards).toEqual([
|
|
151
|
+
{ gift_card_id: 'gc-1', redeemed_times: 1 },
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe('getWalletRedemptionsSourceOfTruth', () => {
|
|
156
|
+
const voucherPathwayOffer = {
|
|
157
|
+
_id: 'offer-v', name: 'Voucher offer', active: true, auto_apply: false, sort_id: 1,
|
|
158
|
+
included_platforms: ['WEB_DELIVERY'], offer_special_hours: null,
|
|
159
|
+
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
|
|
160
|
+
pathway_to_unlock_type_vouchers: {
|
|
161
|
+
total_amount: 0, max_amount: null, max_uses_per_customer: null, max_claims: null, voucher_ids: ['voucher-1'],
|
|
162
|
+
},
|
|
163
|
+
reward_type: 'ITEMS',
|
|
164
|
+
reward_items: { num_of_items: 1, excluded_refs: [], exclusive_refs: [], item_ids: ['item-1'], allocation: null },
|
|
165
|
+
};
|
|
166
|
+
const empty = {
|
|
167
|
+
offers: [], vouchers: [], giftCards: [],
|
|
168
|
+
redeemedOffers: null, walletRedemptions: null, orderDiscountDetails: null,
|
|
169
|
+
customerGiftCardCodes: null, customerOfferRedemptionCounts: { ASSIGNED: {}, USED: {} },
|
|
170
|
+
};
|
|
171
|
+
it('reports the voucher code of a redeemed voucher-pathway offer', () => {
|
|
172
|
+
const result = (0, code_redemption_helpers_1.getWalletRedemptionsSourceOfTruth)({
|
|
173
|
+
...empty,
|
|
174
|
+
offers: [voucherPathwayOffer],
|
|
175
|
+
vouchers: [voucher()],
|
|
176
|
+
redeemedOffers: { 'offer-v': 1 },
|
|
177
|
+
});
|
|
178
|
+
expect(result.activeVoucherOfferIds).toEqual(['offer-v']);
|
|
179
|
+
expect(result.activeVoucherCode).toBe('SAVE10');
|
|
180
|
+
expect(result.activeCodeType).toBe('voucher');
|
|
181
|
+
expect(result.activeCode).toBe('SAVE10');
|
|
182
|
+
});
|
|
183
|
+
it('reports the applied gift card and its claim stats', () => {
|
|
184
|
+
const result = (0, code_redemption_helpers_1.getWalletRedemptionsSourceOfTruth)({
|
|
185
|
+
...empty,
|
|
186
|
+
giftCards: [giftCard()],
|
|
187
|
+
walletRedemptions: { gift_cards: [{ gift_card_id: 'gc-1', redeemed_times: 1 }] },
|
|
188
|
+
customerGiftCardCodes: { GC100: 2 },
|
|
189
|
+
});
|
|
190
|
+
expect(result.activeGiftCardId).toBe('gc-1');
|
|
191
|
+
expect(result.activeGiftCardCode).toBe('GC100');
|
|
192
|
+
expect(result.activeCodeType).toBe('gift-card');
|
|
193
|
+
expect(result.giftCardStatsById['gc-1'].claimable).toBe(true);
|
|
194
|
+
expect(result.giftCardStatsById['gc-1'].is_applied).toBe(true);
|
|
195
|
+
expect(result.giftCardStatsById['gc-1'].owned_count).toBe(2);
|
|
196
|
+
});
|
|
197
|
+
it('marks an inactive gift card as blocked with a reason', () => {
|
|
198
|
+
const result = (0, code_redemption_helpers_1.getWalletRedemptionsSourceOfTruth)({
|
|
199
|
+
...empty,
|
|
200
|
+
giftCards: [giftCard({ active: false })],
|
|
201
|
+
});
|
|
202
|
+
expect(result.giftCardStatsById['gc-1'].claimable).toBe(false);
|
|
203
|
+
expect(result.giftCardStatsById['gc-1'].claim_block_message).toContain('not available');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const gift_card_helpers_1 = require("../helpers/utils/gift-card-helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Gift-card rewards are their own container of reward types (a gift card can
|
|
7
|
+
* hold a discount, items, points, cashback, a voucher or a mystery gift), so
|
|
8
|
+
* their presentation is a second, parallel switch to the offer reward preview.
|
|
9
|
+
* None of it was covered.
|
|
10
|
+
*/
|
|
11
|
+
const base = { _id: 'gc-1', code: 'GC100', name: 'Gift', brand_id: 'b', tenants: ['t'], active: true };
|
|
12
|
+
function preview(giftCard, currencySymbol = 'Rs') {
|
|
13
|
+
return (0, gift_card_helpers_1.getGiftCardRewardPreviewText)({ giftCard: { ...base, ...giftCard }, currencySymbol });
|
|
14
|
+
}
|
|
15
|
+
describe('getGiftCardRewardPreviewText', () => {
|
|
16
|
+
it('renders every reward type', () => {
|
|
17
|
+
expect(preview({
|
|
18
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT,
|
|
19
|
+
reward_discount: { discount_value: 10, is_discount_percentage: true },
|
|
20
|
+
})).toBe('10% off');
|
|
21
|
+
expect(preview({
|
|
22
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT_ITEMS,
|
|
23
|
+
reward_discount_items: { num_of_items: 2, discount_value: 50, is_discount_percentage: true },
|
|
24
|
+
})).toContain('2 items at 50% off');
|
|
25
|
+
expect(preview({
|
|
26
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS,
|
|
27
|
+
reward_items: { num_of_items: 3 },
|
|
28
|
+
})).toBe('3 free items');
|
|
29
|
+
expect(preview({ reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.POINTS, reward_points: { num_of_points: 5 } })).toBe('5 points');
|
|
30
|
+
expect(preview({
|
|
31
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK,
|
|
32
|
+
reward_cashback: { cashback_value: 5, is_cashback_percentage: true, max_cashback_amount: 100 },
|
|
33
|
+
})).toContain('% cashback up to');
|
|
34
|
+
expect(preview({ reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER, reward_voucher: { voucher_ids: { v: 1 } } })).toContain('voucher');
|
|
35
|
+
});
|
|
36
|
+
it('describes a mystery gift by its choices', () => {
|
|
37
|
+
const text = preview({
|
|
38
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT,
|
|
39
|
+
reward_mystery_gift: {
|
|
40
|
+
choice_of_rewards: [constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT, constants_1.GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER],
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
expect(text).toBe('Mystery reward (discount, voucher)');
|
|
44
|
+
});
|
|
45
|
+
it('degrades gracefully when the reward payload is missing', () => {
|
|
46
|
+
expect(preview({ reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT })).toBe('Discount reward');
|
|
47
|
+
expect(preview({ reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT, reward_mystery_gift: {} })).toBe('Mystery reward');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('getGiftCardPostOrderRewardDetail', () => {
|
|
51
|
+
it('says a mystery gift is revealed after the order', () => {
|
|
52
|
+
const detail = (0, gift_card_helpers_1.getGiftCardPostOrderRewardDetail)({
|
|
53
|
+
giftCard: {
|
|
54
|
+
...base,
|
|
55
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT,
|
|
56
|
+
reward_mystery_gift: { choice_of_rewards: [constants_1.GIFT_CARD_REWARD_TYPE_ENUM.POINTS] },
|
|
57
|
+
},
|
|
58
|
+
currencySymbol: 'Rs',
|
|
59
|
+
});
|
|
60
|
+
expect(detail.detail).toBe('Mystery reward will be revealed after your order');
|
|
61
|
+
});
|
|
62
|
+
it('says item rewards are applied after the order', () => {
|
|
63
|
+
const detail = (0, gift_card_helpers_1.getGiftCardPostOrderRewardDetail)({
|
|
64
|
+
giftCard: { ...base, reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS, reward_items: { num_of_items: 2 } },
|
|
65
|
+
currencySymbol: 'Rs',
|
|
66
|
+
});
|
|
67
|
+
expect(detail.detail).toBe('2 free items will be applied after your order');
|
|
68
|
+
});
|
|
69
|
+
it('says credit rewards are credited after the order', () => {
|
|
70
|
+
const detail = (0, gift_card_helpers_1.getGiftCardPostOrderRewardDetail)({
|
|
71
|
+
giftCard: {
|
|
72
|
+
...base,
|
|
73
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.POINTS,
|
|
74
|
+
reward_points: { num_of_points: 5 },
|
|
75
|
+
},
|
|
76
|
+
currencySymbol: 'Rs',
|
|
77
|
+
});
|
|
78
|
+
expect(detail.detail).toBe('5 points will be credited after your order');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('getGiftCardWithPrice', () => {
|
|
82
|
+
it('converts stored cents into display units exactly once', () => {
|
|
83
|
+
const converted = (0, gift_card_helpers_1.getGiftCardWithPrice)({
|
|
84
|
+
...base,
|
|
85
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK,
|
|
86
|
+
reward_cashback: { cashback_value: 500, is_cashback_percentage: false, max_cashback_amount: 1000 },
|
|
87
|
+
});
|
|
88
|
+
expect(converted.reward_cashback.cashback_value).toBe(5);
|
|
89
|
+
expect(converted.reward_cashback.max_cashback_amount).toBe(10);
|
|
90
|
+
});
|
|
91
|
+
it('leaves the input object untouched', () => {
|
|
92
|
+
const input = {
|
|
93
|
+
...base,
|
|
94
|
+
reward_type: constants_1.GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK,
|
|
95
|
+
reward_cashback: { cashback_value: 500, is_cashback_percentage: false, max_cashback_amount: null },
|
|
96
|
+
};
|
|
97
|
+
(0, gift_card_helpers_1.getGiftCardWithPrice)(input);
|
|
98
|
+
expect(input.reward_cashback.cashback_value).toBe(500);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -74,11 +74,7 @@ describe('day vs period scope classification', () => {
|
|
|
74
74
|
'localWeekOfYear',
|
|
75
75
|
'localYear',
|
|
76
76
|
]);
|
|
77
|
-
expect(materialized_prep_time_close_day_helpers_1.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES.sort()).toEqual([
|
|
78
|
-
'localMonth',
|
|
79
|
-
'localWeek',
|
|
80
|
-
'localWeekOfYear',
|
|
81
|
-
]);
|
|
77
|
+
expect(materialized_prep_time_close_day_helpers_1.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES.sort()).toEqual(['localMonth', 'localWeek', 'localWeekOfYear']);
|
|
82
78
|
});
|
|
83
79
|
it('enumerates the FULL report sibling days (through year) separately from the item days', () => {
|
|
84
80
|
// Item period days stay month-bounded (Sep 1..30 for this Monday).
|
|
@@ -44,7 +44,11 @@ const order = () => ({
|
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
name: 'Other',
|
|
47
|
-
items: [
|
|
47
|
+
items: [
|
|
48
|
+
item('b', 20),
|
|
49
|
+
item('invalid-high', MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_MAX_MINUTES + 1),
|
|
50
|
+
item('invalid-negative', -3),
|
|
51
|
+
],
|
|
48
52
|
},
|
|
49
53
|
],
|
|
50
54
|
});
|
|
@@ -55,10 +59,8 @@ const compiled = (0, materialized_prep_time_compile_helpers_1.compileTenantPrepT
|
|
|
55
59
|
orders: [order()],
|
|
56
60
|
computedAt: new Date(`${DAY}T23:00:00.000Z`),
|
|
57
61
|
});
|
|
58
|
-
const dayReport = compiled.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE &&
|
|
59
|
-
|
|
60
|
-
const dayEntry = compiled.entries.find((entry) => entry.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE &&
|
|
61
|
-
entry.scope_field === DAY);
|
|
62
|
+
const dayReport = compiled.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && report.scope_field === DAY);
|
|
63
|
+
const dayEntry = compiled.entries.find((entry) => entry.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && entry.scope_field === DAY);
|
|
62
64
|
const readRows = Object.values(dayEntry.prep_time_entries ?? {}).flatMap((section) => (section.rows ?? []).map((row) => ({
|
|
63
65
|
tenant_id: TENANT,
|
|
64
66
|
order_id: row.order_id,
|