@managesome/eposmatic-toolkit 0.2.709 → 0.2.712
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/lib/constants/ENUMS.d.ts +1 -0
- package/lib/constants/ENUMS.js +1 -0
- package/lib/helpers/types/catalog.d.ts +3 -1
- package/lib/helpers/utils/catalog-conversion.d.ts +1 -1
- package/lib/helpers/utils/catalog-conversion.js +4 -2
- package/lib/helpers/utils/halfhalf-setup-helpers.js +2 -0
- package/lib/helpers/utils/minified-catalog.js +4 -0
- package/lib/helpers/utils/order-engine.d.ts +13 -0
- package/lib/helpers/utils/order-engine.js +59 -5
- package/lib/helpers/utils/platform-num.d.ts +1 -1
- package/lib/helpers/utils/platform-num.js +40 -22
- package/lib/helpers/utils/receipt-engine.js +69 -11
- package/lib/helpers/utils/selection-model.d.ts +3 -0
- package/lib/helpers/utils/selection-model.js +1 -0
- package/lib/helpers/utils/specials-helpers.d.ts +3 -3
- package/lib/helpers/utils/specials-helpers.js +44 -7
- package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
- package/lib/schemas/models/items.d.ts +54 -0
- package/lib/schemas/models/items.js +11 -0
- package/lib/schemas/models/modifier_extras.d.ts +9 -9
- package/lib/schemas/models/orders.d.ts +981 -0
- package/lib/schemas/models/orders.js +5 -0
- package/lib/schemas/models/rewards_usage.d.ts +3 -3
- package/lib/schemas/models/tenant_cash_in_out.d.ts +3 -3
- package/lib/schemas/models/warehouse_internal_movements.d.ts +3 -3
- package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +3 -3
- package/lib/schemas/types/items.d.ts +3 -1
- package/lib/schemas/types/orders.d.ts +2 -1
- package/lib/tests/nested-halfhalf-segment-price.test.d.ts +1 -0
- package/lib/tests/nested-halfhalf-segment-price.test.js +224 -0
- package/lib/tests/receipt-engine.test.d.ts +1 -0
- package/lib/tests/receipt-engine.test.js +204 -0
- package/lib/tests/specials-halfhalf-options.test.d.ts +1 -0
- package/lib/tests/specials-halfhalf-options.test.js +328 -0
- package/package.json +1 -1
|
@@ -279,6 +279,11 @@ const OptionsSchema = new mongoose_1.Schema({
|
|
|
279
279
|
type: Boolean,
|
|
280
280
|
default: false,
|
|
281
281
|
},
|
|
282
|
+
ref_type: {
|
|
283
|
+
type: String,
|
|
284
|
+
enum: constants_1.ALL_MODIFIER_OPTION_REF_TYPES,
|
|
285
|
+
required: false,
|
|
286
|
+
},
|
|
282
287
|
});
|
|
283
288
|
exports.OrderItemModifiersSchema = new mongoose_1.Schema({
|
|
284
289
|
_id: {
|
|
@@ -10,13 +10,13 @@ export declare const RewardsUsageSchema: Schema<any, import("mongoose").Model<an
|
|
|
10
10
|
_id: import("mongoose").Types.ObjectId;
|
|
11
11
|
createdAt: NativeDate;
|
|
12
12
|
updatedAt: NativeDate;
|
|
13
|
+
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
13
14
|
ref_id: import("mongoose").Types.ObjectId;
|
|
14
15
|
customer_phone: string;
|
|
15
16
|
last_used_at: NativeDate;
|
|
16
17
|
used_count: number;
|
|
17
18
|
assigned_count: number;
|
|
18
19
|
last_assigned_at: NativeDate;
|
|
19
|
-
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
20
20
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
21
21
|
createdAt: NativeDate;
|
|
22
22
|
updatedAt: NativeDate;
|
|
@@ -24,13 +24,13 @@ export declare const RewardsUsageSchema: Schema<any, import("mongoose").Model<an
|
|
|
24
24
|
_id: import("mongoose").Types.ObjectId;
|
|
25
25
|
createdAt: NativeDate;
|
|
26
26
|
updatedAt: NativeDate;
|
|
27
|
+
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
27
28
|
ref_id: import("mongoose").Types.ObjectId;
|
|
28
29
|
customer_phone: string;
|
|
29
30
|
last_used_at: NativeDate;
|
|
30
31
|
used_count: number;
|
|
31
32
|
assigned_count: number;
|
|
32
33
|
last_assigned_at: NativeDate;
|
|
33
|
-
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
34
34
|
}>> & import("mongoose").FlatRecord<{
|
|
35
35
|
createdAt: NativeDate;
|
|
36
36
|
updatedAt: NativeDate;
|
|
@@ -38,13 +38,13 @@ export declare const RewardsUsageSchema: Schema<any, import("mongoose").Model<an
|
|
|
38
38
|
_id: import("mongoose").Types.ObjectId;
|
|
39
39
|
createdAt: NativeDate;
|
|
40
40
|
updatedAt: NativeDate;
|
|
41
|
+
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
41
42
|
ref_id: import("mongoose").Types.ObjectId;
|
|
42
43
|
customer_phone: string;
|
|
43
44
|
last_used_at: NativeDate;
|
|
44
45
|
used_count: number;
|
|
45
46
|
assigned_count: number;
|
|
46
47
|
last_assigned_at: NativeDate;
|
|
47
|
-
ref_type: import("../../constants").REWARDS_USAGE_REF_TYPE_ENUM;
|
|
48
48
|
}> & Required<{
|
|
49
49
|
_id: import("mongoose").Types.ObjectId;
|
|
50
50
|
}> & {
|
|
@@ -15,6 +15,7 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
15
15
|
createdAt: NativeDate;
|
|
16
16
|
updatedAt: NativeDate;
|
|
17
17
|
note: string;
|
|
18
|
+
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
18
19
|
ref_id: import("mongoose").Types.ObjectId;
|
|
19
20
|
amount: number;
|
|
20
21
|
localYear: number;
|
|
@@ -31,7 +32,6 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
31
32
|
localDate: string;
|
|
32
33
|
localTime: string;
|
|
33
34
|
localDayOfYear: number;
|
|
34
|
-
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
35
35
|
day_id: import("mongoose").Types.ObjectId;
|
|
36
36
|
drawer_id: import("mongoose").Types.ObjectId;
|
|
37
37
|
shift_id: import("mongoose").Types.ObjectId;
|
|
@@ -50,6 +50,7 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
50
50
|
createdAt: NativeDate;
|
|
51
51
|
updatedAt: NativeDate;
|
|
52
52
|
note: string;
|
|
53
|
+
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
53
54
|
ref_id: import("mongoose").Types.ObjectId;
|
|
54
55
|
amount: number;
|
|
55
56
|
localYear: number;
|
|
@@ -66,7 +67,6 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
66
67
|
localDate: string;
|
|
67
68
|
localTime: string;
|
|
68
69
|
localDayOfYear: number;
|
|
69
|
-
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
70
70
|
day_id: import("mongoose").Types.ObjectId;
|
|
71
71
|
drawer_id: import("mongoose").Types.ObjectId;
|
|
72
72
|
shift_id: import("mongoose").Types.ObjectId;
|
|
@@ -85,6 +85,7 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
85
85
|
createdAt: NativeDate;
|
|
86
86
|
updatedAt: NativeDate;
|
|
87
87
|
note: string;
|
|
88
|
+
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
88
89
|
ref_id: import("mongoose").Types.ObjectId;
|
|
89
90
|
amount: number;
|
|
90
91
|
localYear: number;
|
|
@@ -101,7 +102,6 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
|
|
|
101
102
|
localDate: string;
|
|
102
103
|
localTime: string;
|
|
103
104
|
localDayOfYear: number;
|
|
104
|
-
ref_type: import("../../constants").CASH_IN_OUT_REF_ENUM;
|
|
105
105
|
day_id: import("mongoose").Types.ObjectId;
|
|
106
106
|
drawer_id: import("mongoose").Types.ObjectId;
|
|
107
107
|
shift_id: import("mongoose").Types.ObjectId;
|
|
@@ -362,6 +362,7 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
362
362
|
unit_price?: number | null | undefined;
|
|
363
363
|
dispatched_qty?: number | null | undefined;
|
|
364
364
|
}>;
|
|
365
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
365
366
|
ref_id: string;
|
|
366
367
|
status: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM;
|
|
367
368
|
iterations: import("mongoose").Types.DocumentArray<{
|
|
@@ -747,7 +748,6 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
747
748
|
uid: string;
|
|
748
749
|
};
|
|
749
750
|
doc_number: string;
|
|
750
|
-
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
751
751
|
record_type: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_ENUM;
|
|
752
752
|
flow: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_FLOW_ENUM;
|
|
753
753
|
source_id: string;
|
|
@@ -863,6 +863,7 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
863
863
|
unit_price?: number | null | undefined;
|
|
864
864
|
dispatched_qty?: number | null | undefined;
|
|
865
865
|
}>;
|
|
866
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
866
867
|
ref_id: string;
|
|
867
868
|
status: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM;
|
|
868
869
|
iterations: import("mongoose").Types.DocumentArray<{
|
|
@@ -1248,7 +1249,6 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
1248
1249
|
uid: string;
|
|
1249
1250
|
};
|
|
1250
1251
|
doc_number: string;
|
|
1251
|
-
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
1252
1252
|
record_type: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_ENUM;
|
|
1253
1253
|
flow: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_FLOW_ENUM;
|
|
1254
1254
|
source_id: string;
|
|
@@ -1364,6 +1364,7 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
1364
1364
|
unit_price?: number | null | undefined;
|
|
1365
1365
|
dispatched_qty?: number | null | undefined;
|
|
1366
1366
|
}>;
|
|
1367
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
1367
1368
|
ref_id: string;
|
|
1368
1369
|
status: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM;
|
|
1369
1370
|
iterations: import("mongoose").Types.DocumentArray<{
|
|
@@ -1749,7 +1750,6 @@ export declare const WarehouseInternalMovementsSchema: Schema<any, import("mongo
|
|
|
1749
1750
|
uid: string;
|
|
1750
1751
|
};
|
|
1751
1752
|
doc_number: string;
|
|
1752
|
-
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
1753
1753
|
record_type: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_ENUM;
|
|
1754
1754
|
flow: import("../../constants").WAREHOUSE_INTERNAL_MOVEMENT_FLOW_ENUM;
|
|
1755
1755
|
source_id: string;
|
|
@@ -12,8 +12,8 @@ export declare const WarehouseInventoryLotSerialNumberSchema: Schema<any, import
|
|
|
12
12
|
createdAt: NativeDate;
|
|
13
13
|
updatedAt: NativeDate;
|
|
14
14
|
inventory_code: string;
|
|
15
|
-
ref_id: string;
|
|
16
15
|
ref_type: string;
|
|
16
|
+
ref_id: string;
|
|
17
17
|
tracking_mode: WAREHOUSE_TRACKING_MODE_ENUM;
|
|
18
18
|
doc_type: WAREHOUSE_LOT_SERIAL_DOC_TYPE_ENUM;
|
|
19
19
|
source?: import("../../constants").WAREHOUSE_LOT_SERIAL_MOVEMENT_SOURCE_ENUM | null | undefined;
|
|
@@ -59,8 +59,8 @@ export declare const WarehouseInventoryLotSerialNumberSchema: Schema<any, import
|
|
|
59
59
|
createdAt: NativeDate;
|
|
60
60
|
updatedAt: NativeDate;
|
|
61
61
|
inventory_code: string;
|
|
62
|
-
ref_id: string;
|
|
63
62
|
ref_type: string;
|
|
63
|
+
ref_id: string;
|
|
64
64
|
tracking_mode: WAREHOUSE_TRACKING_MODE_ENUM;
|
|
65
65
|
doc_type: WAREHOUSE_LOT_SERIAL_DOC_TYPE_ENUM;
|
|
66
66
|
source?: import("../../constants").WAREHOUSE_LOT_SERIAL_MOVEMENT_SOURCE_ENUM | null | undefined;
|
|
@@ -106,8 +106,8 @@ export declare const WarehouseInventoryLotSerialNumberSchema: Schema<any, import
|
|
|
106
106
|
createdAt: NativeDate;
|
|
107
107
|
updatedAt: NativeDate;
|
|
108
108
|
inventory_code: string;
|
|
109
|
-
ref_id: string;
|
|
110
109
|
ref_type: string;
|
|
110
|
+
ref_id: string;
|
|
111
111
|
tracking_mode: WAREHOUSE_TRACKING_MODE_ENUM;
|
|
112
112
|
doc_type: WAREHOUSE_LOT_SERIAL_DOC_TYPE_ENUM;
|
|
113
113
|
source?: import("../../constants").WAREHOUSE_LOT_SERIAL_MOVEMENT_SOURCE_ENUM | null | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITEM_CAVEATS_ENUM, ITEM_DIETARY_PREFERENCE_ENUM, ORDER_ITEM_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
1
|
+
import { ITEM_CAVEATS_ENUM, ITEM_DIETARY_PREFERENCE_ENUM, MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
2
2
|
import { IIngredient, IItemSpecialHour, IPrice } from './common';
|
|
3
3
|
export interface IModifier {
|
|
4
4
|
_id: string /** * Unique identifier for the modifier */;
|
|
@@ -33,6 +33,8 @@ export interface IModifierOption {
|
|
|
33
33
|
default?: boolean;
|
|
34
34
|
ingredients?: IIngredient[] | null;
|
|
35
35
|
item_modifier_option_special_hours?: IItemSpecialHour[] | null;
|
|
36
|
+
ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
|
|
37
|
+
choose_expensive_segment_price?: boolean;
|
|
36
38
|
}
|
|
37
39
|
export interface IItem {
|
|
38
40
|
_id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GIFT_CARD_REWARD_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, PAYMENT_METHOD_EXPECTED_ENUM, PAYMENT_PROVIDERS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PLATFORMS_ENUM, SPLIT_BILL_TYPE_ENUM } from '../../constants';
|
|
1
|
+
import { GIFT_CARD_REWARD_TYPE_ENUM, MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, PAYMENT_METHOD_EXPECTED_ENUM, PAYMENT_PROVIDERS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PLATFORMS_ENUM, SPLIT_BILL_TYPE_ENUM } from '../../constants';
|
|
2
2
|
import { ILocalTimeFields } from '../../helpers';
|
|
3
3
|
export interface IOrderCourse {
|
|
4
4
|
name: string;
|
|
@@ -55,6 +55,7 @@ export interface IOrderOption {
|
|
|
55
55
|
price: number;
|
|
56
56
|
quantity: number;
|
|
57
57
|
is_free: boolean;
|
|
58
|
+
ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
|
|
58
59
|
modifiers: IOrderModifier[] | null;
|
|
59
60
|
}
|
|
60
61
|
export interface ICardDetails {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const order_engine_1 = require("../helpers/utils/order-engine");
|
|
5
|
+
function makeEngineOption(overrides = {}) {
|
|
6
|
+
return {
|
|
7
|
+
_id: 'opt-1',
|
|
8
|
+
ref: 'opt-1',
|
|
9
|
+
name: 'Option',
|
|
10
|
+
active: true,
|
|
11
|
+
sold_out: [],
|
|
12
|
+
sort_id: 1,
|
|
13
|
+
excluded_platforms: [],
|
|
14
|
+
default: false,
|
|
15
|
+
price: 0,
|
|
16
|
+
quantity: 1,
|
|
17
|
+
modifiers: [],
|
|
18
|
+
is_free: false,
|
|
19
|
+
loyalty_applied: false,
|
|
20
|
+
voucher_applied: false,
|
|
21
|
+
...overrides,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function makeEngineModifier(overrides = {}) {
|
|
25
|
+
return {
|
|
26
|
+
_id: 'mod-1',
|
|
27
|
+
ref: 'mod-1',
|
|
28
|
+
name: 'Modifier',
|
|
29
|
+
description: '',
|
|
30
|
+
active: true,
|
|
31
|
+
sold_out: [],
|
|
32
|
+
sort_id: 1,
|
|
33
|
+
min_num_options: 1,
|
|
34
|
+
max_num_options: 1,
|
|
35
|
+
depth: 1,
|
|
36
|
+
default: false,
|
|
37
|
+
options: [],
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function makeEngineItem(overrides = {}) {
|
|
42
|
+
return {
|
|
43
|
+
_id: 'item-1',
|
|
44
|
+
category_id: 'cat-1',
|
|
45
|
+
item_id: 'special-1',
|
|
46
|
+
menu_id: 'menu-1',
|
|
47
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
48
|
+
name: 'Buy 1 Pizza Get 1 Free',
|
|
49
|
+
description: 'Deal',
|
|
50
|
+
loyalty_applied: false,
|
|
51
|
+
voucher_applied: false,
|
|
52
|
+
price: 1500,
|
|
53
|
+
gross_total: 0,
|
|
54
|
+
subtotal: 0,
|
|
55
|
+
tax_rate: 0,
|
|
56
|
+
quantity: 1,
|
|
57
|
+
image_url: '',
|
|
58
|
+
special_instructions: '',
|
|
59
|
+
item_discount_details: null,
|
|
60
|
+
modifiers: [],
|
|
61
|
+
...overrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Two single-select segment groups (the half-half's segments), max = 600. */
|
|
65
|
+
function makeSegmentGroups() {
|
|
66
|
+
return [
|
|
67
|
+
makeEngineModifier({
|
|
68
|
+
_id: 'seg-1',
|
|
69
|
+
name: 'First Pizza',
|
|
70
|
+
depth: 1,
|
|
71
|
+
options: [
|
|
72
|
+
makeEngineOption({ _id: 'milan', ref: 'milan', price: 500, default: true }),
|
|
73
|
+
makeEngineOption({ _id: 'torent', ref: 'torent', price: 600 }),
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
makeEngineModifier({
|
|
77
|
+
_id: 'seg-2',
|
|
78
|
+
name: 'Second Pizza',
|
|
79
|
+
depth: 1,
|
|
80
|
+
options: [
|
|
81
|
+
makeEngineOption({ _id: 'milan2', ref: 'milan', price: 500 }),
|
|
82
|
+
makeEngineOption({ _id: 'torent2', ref: 'torent', price: 600, default: true }),
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
describe('hasFlaggedHalfHalfOption', () => {
|
|
88
|
+
it('detects a top-level group option with ref_type HALF_HALF + flag', () => {
|
|
89
|
+
const item = makeEngineItem({
|
|
90
|
+
modifiers: [
|
|
91
|
+
makeEngineModifier({
|
|
92
|
+
depth: 0,
|
|
93
|
+
options: [
|
|
94
|
+
makeEngineOption({
|
|
95
|
+
_id: 'halfhalf-1',
|
|
96
|
+
ref: 'halfhalf-1',
|
|
97
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
98
|
+
choose_expensive_segment_price: true,
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
expect((0, order_engine_1.hasFlaggedHalfHalfOption)(item)).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
it('is false for flagged-off half-half, ITEM and normal options', () => {
|
|
107
|
+
const item = makeEngineItem({
|
|
108
|
+
modifiers: [
|
|
109
|
+
makeEngineModifier({
|
|
110
|
+
depth: 0,
|
|
111
|
+
options: [
|
|
112
|
+
makeEngineOption({
|
|
113
|
+
_id: 'halfhalf-1',
|
|
114
|
+
ref: 'halfhalf-1',
|
|
115
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
116
|
+
choose_expensive_segment_price: false,
|
|
117
|
+
}),
|
|
118
|
+
makeEngineOption({
|
|
119
|
+
_id: 'milan',
|
|
120
|
+
ref: 'milan',
|
|
121
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
122
|
+
choose_expensive_segment_price: true,
|
|
123
|
+
}),
|
|
124
|
+
makeEngineOption({ _id: 'normal', ref: 'normal', default: true }),
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
expect((0, order_engine_1.hasFlaggedHalfHalfOption)(item)).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('applyNestedChooseExpensiveSegmentPrice (half-half inside a special)', () => {
|
|
133
|
+
it('raises the selected cheap segment option to the most expensive one', () => {
|
|
134
|
+
const item = makeEngineItem({
|
|
135
|
+
modifiers: [
|
|
136
|
+
makeEngineModifier({
|
|
137
|
+
_id: 'first-pizza',
|
|
138
|
+
name: 'First Pizza',
|
|
139
|
+
depth: 0,
|
|
140
|
+
options: [
|
|
141
|
+
makeEngineOption({
|
|
142
|
+
_id: 'milan',
|
|
143
|
+
ref: 'milan',
|
|
144
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
145
|
+
price: 0,
|
|
146
|
+
default: true,
|
|
147
|
+
}),
|
|
148
|
+
makeEngineOption({
|
|
149
|
+
_id: 'halfhalf-1',
|
|
150
|
+
ref: 'halfhalf-1',
|
|
151
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
152
|
+
choose_expensive_segment_price: true,
|
|
153
|
+
default: true,
|
|
154
|
+
price: 0,
|
|
155
|
+
modifiers: makeSegmentGroups(),
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
}),
|
|
159
|
+
makeEngineModifier({
|
|
160
|
+
_id: 'drink',
|
|
161
|
+
name: 'Drink',
|
|
162
|
+
depth: 0,
|
|
163
|
+
options: [
|
|
164
|
+
makeEngineOption({
|
|
165
|
+
_id: 'cola',
|
|
166
|
+
ref: 'cola',
|
|
167
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
168
|
+
default: true,
|
|
169
|
+
price: 0,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
const result = (0, order_engine_1.applyNestedChooseExpensiveSegmentPrice)(item);
|
|
176
|
+
const firstPizza = result.modifiers.find((m) => m._id === 'first-pizza');
|
|
177
|
+
const halfHalfOption = firstPizza.options.find((o) => o._id === 'halfhalf-1');
|
|
178
|
+
const segA = halfHalfOption.modifiers.find((m) => m._id === 'seg-1');
|
|
179
|
+
const segB = halfHalfOption.modifiers.find((m) => m._id === 'seg-2');
|
|
180
|
+
// Selected MILAN (500) in segment 1 raised to 600; selected TORENT (600)
|
|
181
|
+
// in segment 2 unchanged. Unselected options keep their prices.
|
|
182
|
+
expect(segA.options.find((o) => o._id === 'milan').price).toBe(600);
|
|
183
|
+
expect(segA.options.find((o) => o._id === 'torent').price).toBe(600);
|
|
184
|
+
expect(segB.options.find((o) => o._id === 'torent2').price).toBe(600);
|
|
185
|
+
// Other groups untouched.
|
|
186
|
+
const drink = result.modifiers.find((m) => m._id === 'drink');
|
|
187
|
+
expect(drink.options.find((o) => o._id === 'cola').price).toBe(0);
|
|
188
|
+
});
|
|
189
|
+
it('does nothing when the half-half flag is off', () => {
|
|
190
|
+
const item = makeEngineItem({
|
|
191
|
+
modifiers: [
|
|
192
|
+
makeEngineModifier({
|
|
193
|
+
depth: 0,
|
|
194
|
+
options: [
|
|
195
|
+
makeEngineOption({
|
|
196
|
+
_id: 'halfhalf-1',
|
|
197
|
+
ref: 'halfhalf-1',
|
|
198
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
199
|
+
choose_expensive_segment_price: false,
|
|
200
|
+
default: true,
|
|
201
|
+
modifiers: makeSegmentGroups(),
|
|
202
|
+
}),
|
|
203
|
+
],
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
const result = (0, order_engine_1.applyNestedChooseExpensiveSegmentPrice)(item);
|
|
208
|
+
const halfHalfOption = result.modifiers[0].options[0];
|
|
209
|
+
expect(halfHalfOption.modifiers[0].options[0].price).toBe(500);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('applyChooseExpensiveSegmentPrice (standalone regression)', () => {
|
|
213
|
+
it('still raises to the max at top-level segment groups', () => {
|
|
214
|
+
const item = makeEngineItem({
|
|
215
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
216
|
+
modifiers: makeSegmentGroups().map((modifier, i) => ({ ...modifier, depth: 0, _id: `seg-${i}` })),
|
|
217
|
+
});
|
|
218
|
+
const result = (0, order_engine_1.applyChooseExpensiveSegmentPrice)(item);
|
|
219
|
+
const segA = result.modifiers.find((m) => m._id === 'seg-0');
|
|
220
|
+
const segB = result.modifiers.find((m) => m._id === 'seg-1');
|
|
221
|
+
expect(segA.options.find((o) => o._id === 'milan').price).toBe(600);
|
|
222
|
+
expect(segB.options.find((o) => o._id === 'torent2').price).toBe(600);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const receipt_engine_1 = require("../helpers/utils/receipt-engine");
|
|
5
|
+
// =========================><=========================
|
|
6
|
+
function makeItem(_id, name, overrides = {}) {
|
|
7
|
+
return {
|
|
8
|
+
_id,
|
|
9
|
+
item_id: _id,
|
|
10
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.ITEM,
|
|
11
|
+
name,
|
|
12
|
+
price: 500,
|
|
13
|
+
subtotal: 500,
|
|
14
|
+
tax_rate: 0,
|
|
15
|
+
quantity: 1,
|
|
16
|
+
_net_amount: 500,
|
|
17
|
+
_gross_amount: 500,
|
|
18
|
+
_gst_amount: 0,
|
|
19
|
+
_discount_amount: 0,
|
|
20
|
+
special_instructions: '',
|
|
21
|
+
item_discount_details: null,
|
|
22
|
+
modifiers: null,
|
|
23
|
+
...overrides,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function makeOption(id, ref, name, overrides = {}) {
|
|
27
|
+
return { _id: id, ref, name, price: 500, quantity: 1, is_free: false, modifiers: null, ...overrides };
|
|
28
|
+
}
|
|
29
|
+
function makeModifier(_id, ref, name, options) {
|
|
30
|
+
return { _id, ref, name, options };
|
|
31
|
+
}
|
|
32
|
+
const PIZZA_ONLY_MENU = {
|
|
33
|
+
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-1': { sortId: 0 } } },
|
|
34
|
+
'cat-pizza': {
|
|
35
|
+
sortId: 1,
|
|
36
|
+
includedItemsMap: { 'pizza-milano': { sortId: 0 }, 'pizza-toronto': { sortId: 1 } },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
const DRINK_ONLY_MENU = {
|
|
40
|
+
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-1': { sortId: 0 } } },
|
|
41
|
+
'cat-drinks': {
|
|
42
|
+
sortId: 1,
|
|
43
|
+
includedItemsMap: { 'cola-next': { sortId: 0 } },
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
// =========================><=========================
|
|
47
|
+
describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
|
|
48
|
+
it('filters ITEM options by the partial menu and keeps regular OPTION options', () => {
|
|
49
|
+
const deal = makeItem('deal-1', 'Buy 1 Pizza Get 1 Free', {
|
|
50
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
51
|
+
modifiers: [
|
|
52
|
+
makeModifier('mod-pizza-1', 'modref-pizza-1', 'FIRST PIZZA', [
|
|
53
|
+
makeOption('opt-milano', 'pizza-milano', 'Milano', {
|
|
54
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
55
|
+
modifiers: [
|
|
56
|
+
makeModifier('mod-size-1', 'modref-size-1', 'PIZZA SIZE', [
|
|
57
|
+
// regular modifier option (no ref_type / OPTION) -> never partialed
|
|
58
|
+
makeOption('opt-large', 'size-large', 'Large 13"', {
|
|
59
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.OPTION,
|
|
60
|
+
}),
|
|
61
|
+
]),
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
]),
|
|
65
|
+
makeModifier('mod-pizza-2', 'modref-pizza-2', 'SECOND PIZZA', [
|
|
66
|
+
makeOption('opt-toronto', 'pizza-toronto', 'Toronto', {
|
|
67
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
68
|
+
modifiers: [
|
|
69
|
+
makeModifier('mod-size-2', 'modref-size-2', 'PIZZA SIZE', [
|
|
70
|
+
makeOption('opt-medium', 'size-medium', 'Medium 10"'),
|
|
71
|
+
]),
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
]),
|
|
75
|
+
makeModifier('mod-drink', 'modref-drink', 'DRINK', [
|
|
76
|
+
makeOption('opt-cola', 'cola-next', 'Cola Next 1.5 Ltr', {
|
|
77
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
78
|
+
}),
|
|
79
|
+
]),
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
const categories = [
|
|
83
|
+
{ name: 'Deals', category_id: 'cat-deals', items: [deal] },
|
|
84
|
+
{
|
|
85
|
+
name: 'Pizza',
|
|
86
|
+
category_id: 'cat-pizza',
|
|
87
|
+
items: [makeItem('pizza-milano', 'Milano'), makeItem('pizza-toronto', 'Toronto')],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
const result = (0, receipt_engine_1.getPartialItems)(categories, PIZZA_ONLY_MENU);
|
|
91
|
+
const dealCategory = result.find((c) => c.category_id === 'cat-deals');
|
|
92
|
+
expect(dealCategory).toBeDefined();
|
|
93
|
+
expect(dealCategory.items).toHaveLength(1);
|
|
94
|
+
const trimmedDeal = dealCategory.items[0];
|
|
95
|
+
expect(trimmedDeal.modifiers.map((m) => m.name)).toEqual(['FIRST PIZZA', 'SECOND PIZZA']);
|
|
96
|
+
expect(trimmedDeal.modifiers[0].options.map((o) => o.ref)).toEqual(['pizza-milano']);
|
|
97
|
+
expect(trimmedDeal.modifiers[1].options.map((o) => o.ref)).toEqual(['pizza-toronto']);
|
|
98
|
+
// regular OPTION options survive untouched even though they are not in the menu
|
|
99
|
+
const sizeModifier = trimmedDeal.modifiers[0].options[0].modifiers[0];
|
|
100
|
+
expect(sizeModifier.name).toBe('PIZZA SIZE');
|
|
101
|
+
expect(sizeModifier.options[0].ref).toBe('size-large');
|
|
102
|
+
expect(trimmedDeal.modifiers[1].options[0].modifiers[0].options[0].ref).toBe('size-medium');
|
|
103
|
+
// the drink belongs to the drink KOT
|
|
104
|
+
expect(result.find((c) => c.category_id === 'cat-drinks')).toBeUndefined();
|
|
105
|
+
});
|
|
106
|
+
it('recursively trims a HALF_HALF option by its internal ITEM options', () => {
|
|
107
|
+
const deal = makeItem('deal-2', 'Deal With Half Half', {
|
|
108
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
109
|
+
modifiers: [
|
|
110
|
+
makeModifier('mod-half', 'modref-half', 'HALF HALF PIZZA', [
|
|
111
|
+
makeOption('opt-half', 'half-pizza-1', 'Half Half Pizza', {
|
|
112
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
113
|
+
modifiers: [
|
|
114
|
+
makeModifier('mod-left', 'modref-left', 'LEFT HALF', [
|
|
115
|
+
makeOption('opt-left', 'pizza-milano', 'Milano', {
|
|
116
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
117
|
+
}),
|
|
118
|
+
]),
|
|
119
|
+
makeModifier('mod-right', 'modref-right', 'RIGHT HALF', [
|
|
120
|
+
makeOption('opt-right', 'pizza-toronto', 'Toronto', {
|
|
121
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
122
|
+
}),
|
|
123
|
+
]),
|
|
124
|
+
],
|
|
125
|
+
}),
|
|
126
|
+
]),
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
const categories = [
|
|
130
|
+
{ name: 'Deals', category_id: 'cat-deals', items: [deal] },
|
|
131
|
+
{
|
|
132
|
+
name: 'Pizza',
|
|
133
|
+
category_id: 'cat-pizza',
|
|
134
|
+
items: [makeItem('pizza-milano', 'Milano')],
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
const result = (0, receipt_engine_1.getPartialItems)(categories, {
|
|
138
|
+
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-2': { sortId: 0 } } },
|
|
139
|
+
'cat-pizza': {
|
|
140
|
+
sortId: 1,
|
|
141
|
+
includedItemsMap: { 'pizza-milano': { sortId: 0 } },
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const trimmedDeal = result.find((c) => c.category_id === 'cat-deals').items[0];
|
|
145
|
+
expect(trimmedDeal.modifiers).toHaveLength(1);
|
|
146
|
+
const halfOption = trimmedDeal.modifiers[0].options[0];
|
|
147
|
+
expect(halfOption.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
|
|
148
|
+
// only the LEFT HALF survived; RIGHT HALF (Toronto) is trimmed away
|
|
149
|
+
expect(halfOption.modifiers.map((m) => m.name)).toEqual(['LEFT HALF']);
|
|
150
|
+
expect(halfOption.modifiers[0].options.map((o) => o.ref)).toEqual(['pizza-milano']);
|
|
151
|
+
});
|
|
152
|
+
it('drops a HALF_HALF option whose nested parts are all filtered', () => {
|
|
153
|
+
const deal = makeItem('deal-3', 'Deal With Half Half', {
|
|
154
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
155
|
+
modifiers: [
|
|
156
|
+
makeModifier('mod-half', 'modref-half', 'HALF HALF PIZZA', [
|
|
157
|
+
makeOption('opt-half', 'half-pizza-1', 'Half Half Pizza', {
|
|
158
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
159
|
+
modifiers: [
|
|
160
|
+
makeModifier('mod-left', 'modref-left', 'LEFT HALF', [
|
|
161
|
+
makeOption('opt-left', 'pizza-milano', 'Milano', {
|
|
162
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
163
|
+
}),
|
|
164
|
+
]),
|
|
165
|
+
],
|
|
166
|
+
}),
|
|
167
|
+
]),
|
|
168
|
+
makeModifier('mod-drink', 'modref-drink', 'DRINK', [
|
|
169
|
+
makeOption('opt-cola', 'cola-next', 'Cola Next 1.5 Ltr', {
|
|
170
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
171
|
+
}),
|
|
172
|
+
]),
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
const categories = [
|
|
176
|
+
{ name: 'Deals', category_id: 'cat-deals', items: [deal] },
|
|
177
|
+
{ name: 'Drinks', category_id: 'cat-drinks', items: [makeItem('cola-next', 'Cola Next 1.5 Ltr')] },
|
|
178
|
+
];
|
|
179
|
+
const result = (0, receipt_engine_1.getPartialItems)(categories, {
|
|
180
|
+
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-3': { sortId: 0 } } },
|
|
181
|
+
'cat-drinks': { sortId: 1, includedItemsMap: { 'cola-next': { sortId: 0 } } },
|
|
182
|
+
});
|
|
183
|
+
const trimmedDeal = result.find((c) => c.category_id === 'cat-deals').items[0];
|
|
184
|
+
// half-half gone (its parts belong to the pizza KOT), drink kept
|
|
185
|
+
expect(trimmedDeal.modifiers.map((m) => m.name)).toEqual(['DRINK']);
|
|
186
|
+
expect(trimmedDeal.modifiers[0].options.map((o) => o.ref)).toEqual(['cola-next']);
|
|
187
|
+
});
|
|
188
|
+
it('treats options without ref_type as regular options and keeps them', () => {
|
|
189
|
+
const deal = makeItem('deal-4', 'Legacy Deal', {
|
|
190
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
191
|
+
modifiers: [
|
|
192
|
+
makeModifier('mod-drink', 'modref-drink', 'DRINK', [
|
|
193
|
+
// legacy stored order: no ref_type at all
|
|
194
|
+
makeOption('opt-cola', 'cola-next', 'Cola Next 1.5 Ltr'),
|
|
195
|
+
]),
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
const result = (0, receipt_engine_1.getPartialItems)([{ name: 'Deals', category_id: 'cat-deals', items: [deal] }], {
|
|
199
|
+
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-4': { sortId: 0 } } },
|
|
200
|
+
});
|
|
201
|
+
const trimmedDeal = result.find((c) => c.category_id === 'cat-deals').items[0];
|
|
202
|
+
expect(trimmedDeal.modifiers[0].options.map((o) => o.ref)).toEqual(['cola-next']);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|