@managesome/eposmatic-toolkit 0.4.59 → 0.4.61
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/MATERIALIZED_REPORTS.js +177 -8
- package/esm/helpers/materialized-reports/index.js +7 -0
- package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
- package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
- package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
- package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
- package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
- package/esm/helpers/reporting-contract/report-contract.js +3 -0
- package/esm/schemas/models/index.js +2 -0
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
- package/esm/schemas/types/index.js +2 -0
- package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +160 -8
- package/lib/constants/MATERIALIZED_REPORTS.js +178 -9
- package/lib/helpers/materialized-reports/index.d.ts +7 -0
- package/lib/helpers/materialized-reports/index.js +7 -0
- package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
- package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
- package/lib/helpers/reporting-contract/report-contract.js +3 -0
- package/lib/schemas/models/index.d.ts +2 -0
- package/lib/schemas/models/index.js +2 -0
- package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
- package/lib/schemas/types/index.d.ts +2 -0
- package/lib/schemas/types/index.js +2 -0
- package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
- package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
- package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
- package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
- package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
- package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +299 -0
- package/package.json +1 -1
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_dinein_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-dinein-compile-helpers");
|
|
5
|
+
const materialized_dinein_entry_pages_1 = require("../../helpers/materialized-reports/materialized-dinein-entry-pages");
|
|
6
|
+
const dinein_fixtures_1 = require("./dinein-fixtures");
|
|
7
|
+
/**
|
|
8
|
+
* Dinein day compile — the frozen POS semantics.
|
|
9
|
+
*
|
|
10
|
+
* Fixtures cover: non-split check, split group with a deleted parent, newest-first
|
|
11
|
+
* iterations with a QR first version, staff-tablet and POS-direct origins,
|
|
12
|
+
* percentage/fixed + taxable/original-price service charges, card/cash/split
|
|
13
|
+
* tender, offline, fingerprint start and fallback, missing fingerprint, courses,
|
|
14
|
+
* reservation statuses + lead time, a rating on the deleted parent, mixed
|
|
15
|
+
* origins and an empty day.
|
|
16
|
+
*/
|
|
17
|
+
const COMPLETED_POS = 'COMPLETED:POS_DINE-IN';
|
|
18
|
+
const entryRowsOfPage = (page) => Object.values(page.dinein_entries ?? {}).flatMap((section) => section.rows);
|
|
19
|
+
describe('dinein day compile', () => {
|
|
20
|
+
it('counts one non-split check with its money, items and check row', () => {
|
|
21
|
+
const order = (0, dinein_fixtures_1.dineinOrder)({
|
|
22
|
+
amount_earned: 21400,
|
|
23
|
+
tax_amount: 1400,
|
|
24
|
+
tip_amount: 500,
|
|
25
|
+
total_discount_applied: 1000,
|
|
26
|
+
surcharge_amount: 200,
|
|
27
|
+
service_fee_amount: 1240,
|
|
28
|
+
is_service_fee_percentage: true,
|
|
29
|
+
service_fee: 5.8,
|
|
30
|
+
is_service_fee_taxable: true,
|
|
31
|
+
apply_service_fee_on_original_price: true,
|
|
32
|
+
categories: [
|
|
33
|
+
{
|
|
34
|
+
items: [
|
|
35
|
+
{ _id: 'line-a', quantity: 2 },
|
|
36
|
+
{ _id: 'line-b', quantity: 1 },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
payments: [{ payment_type: 'CARD', amount_paid: 21400, amount_refunded: 400 }],
|
|
41
|
+
});
|
|
42
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
43
|
+
orders: [order],
|
|
44
|
+
fingerprints: [(0, dinein_fixtures_1.dineinFingerprint)(String(order._id))],
|
|
45
|
+
});
|
|
46
|
+
expect(result).not.toBeNull();
|
|
47
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
48
|
+
expect(counters.orders).toBe(1);
|
|
49
|
+
expect(counters.completed_orders).toBe(1);
|
|
50
|
+
expect(counters.cancelled_orders).toBe(0);
|
|
51
|
+
expect(counters.items).toBe(3);
|
|
52
|
+
expect(counters.sales).toBe(21400);
|
|
53
|
+
expect(counters.sales).not.toBe(counters.sales + counters.service_charge_amount);
|
|
54
|
+
expect(counters.discounts).toBe(1000);
|
|
55
|
+
expect(counters.tax).toBe(1400);
|
|
56
|
+
expect(counters.tips).toBe(500);
|
|
57
|
+
expect(counters.surcharge_amount).toBe(200);
|
|
58
|
+
expect(counters.service_charge_amount).toBe(1240);
|
|
59
|
+
expect(counters.service_charge_taxable_amount).toBe(1240);
|
|
60
|
+
expect(counters.service_charge_orders).toBe(1);
|
|
61
|
+
expect(counters.service_charge_percentage_orders).toBe(1);
|
|
62
|
+
expect(counters.service_charge_fixed_orders).toBe(0);
|
|
63
|
+
expect(counters.service_charge_original_price_orders).toBe(1);
|
|
64
|
+
expect(counters.service_charge_rate_counts).toEqual({ 'PCT:5.8': 1 });
|
|
65
|
+
expect(counters.refunds).toBe(400);
|
|
66
|
+
expect(counters.card_amount).toBe(21000);
|
|
67
|
+
expect(counters.card_orders).toBe(1);
|
|
68
|
+
expect(counters.cash_orders).toBe(0);
|
|
69
|
+
expect(counters.split_tender_orders).toBe(0);
|
|
70
|
+
expect(counters.by_payment_type.CARD).toEqual({ amount: 21000, orders: 1 });
|
|
71
|
+
// covers come from the fingerprint, not from any num_of_guests on the order
|
|
72
|
+
expect(counters.covers).toBe(4);
|
|
73
|
+
expect(counters.table_sessions).toBe(1);
|
|
74
|
+
expect(counters.occupancy_sessions).toBe(1);
|
|
75
|
+
expect(counters.fallback_occupancy_sessions).toBe(0);
|
|
76
|
+
expect(counters.occupancy_minutes_sum).toBe(35);
|
|
77
|
+
expect(counters.tables_served).toBe(1);
|
|
78
|
+
expect(counters.by_table['table-t04']).toMatchObject({
|
|
79
|
+
table_id: 'table-t04',
|
|
80
|
+
table_name: 'T-04',
|
|
81
|
+
floor_id: 'floor-main',
|
|
82
|
+
orders: 1,
|
|
83
|
+
sessions: 1,
|
|
84
|
+
covers: 4,
|
|
85
|
+
occupancy_minutes: 35,
|
|
86
|
+
sales: 21400,
|
|
87
|
+
});
|
|
88
|
+
expect(counters.by_floor['floor-main']).toMatchObject({ orders: 1, sessions: 1, covers: 4 });
|
|
89
|
+
const row = (0, dinein_fixtures_1.entryRowsOfDay)(result)[0];
|
|
90
|
+
expect(row).toMatchObject({
|
|
91
|
+
order_id: String(order._id),
|
|
92
|
+
order_number: 2418,
|
|
93
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
94
|
+
table_id: 'table-t04',
|
|
95
|
+
table_name: 'T-04',
|
|
96
|
+
floor_id: 'floor-main',
|
|
97
|
+
covers: 4,
|
|
98
|
+
status: 'COMPLETED',
|
|
99
|
+
platform: 'POS_DINE-IN',
|
|
100
|
+
origin: 'POS_DIRECT',
|
|
101
|
+
split_type: null,
|
|
102
|
+
split_role: 'NONE',
|
|
103
|
+
offline: false,
|
|
104
|
+
rating: null,
|
|
105
|
+
sales: 21400,
|
|
106
|
+
service_charge: 1240,
|
|
107
|
+
items: 3,
|
|
108
|
+
edits: 0,
|
|
109
|
+
});
|
|
110
|
+
// Privacy: no phone / name / review text on a row.
|
|
111
|
+
expect(Object.keys(row).sort()).toEqual([
|
|
112
|
+
'covers',
|
|
113
|
+
'edits',
|
|
114
|
+
'floor_id',
|
|
115
|
+
'items',
|
|
116
|
+
'localDate',
|
|
117
|
+
'offline',
|
|
118
|
+
'order_id',
|
|
119
|
+
'order_number',
|
|
120
|
+
'origin',
|
|
121
|
+
'platform',
|
|
122
|
+
'rating',
|
|
123
|
+
'sales',
|
|
124
|
+
'service_charge',
|
|
125
|
+
'split_role',
|
|
126
|
+
'split_type',
|
|
127
|
+
'status',
|
|
128
|
+
'table_id',
|
|
129
|
+
'table_name',
|
|
130
|
+
'time',
|
|
131
|
+
].sort());
|
|
132
|
+
});
|
|
133
|
+
it('excludes the deleted split parent from sales and counts its children', () => {
|
|
134
|
+
const parent = (0, dinein_fixtures_1.dineinOrder)({
|
|
135
|
+
is_deleted: true,
|
|
136
|
+
delete_reason: 'Auto Deleted on Split',
|
|
137
|
+
split_child_ids: ['child-1', 'child-2'],
|
|
138
|
+
split_type: 'EQUAL',
|
|
139
|
+
amount_earned: 30000,
|
|
140
|
+
});
|
|
141
|
+
const childA = (0, dinein_fixtures_1.dineinOrder)({
|
|
142
|
+
_id: 'child-1',
|
|
143
|
+
split_parent_id: String(parent._id),
|
|
144
|
+
split_type: null,
|
|
145
|
+
amount_earned: 15000,
|
|
146
|
+
payments: [{ payment_type: 'CASH', amount_paid: 15000, amount_refunded: 0 }],
|
|
147
|
+
});
|
|
148
|
+
const childB = (0, dinein_fixtures_1.dineinOrder)({
|
|
149
|
+
_id: 'child-2',
|
|
150
|
+
split_parent_id: String(parent._id),
|
|
151
|
+
split_type: null,
|
|
152
|
+
amount_earned: 15000,
|
|
153
|
+
payments: [{ payment_type: 'CARD', amount_paid: 15000, amount_refunded: 0 }],
|
|
154
|
+
});
|
|
155
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
156
|
+
orders: [childA, childB],
|
|
157
|
+
deletedSplitParents: [parent],
|
|
158
|
+
fingerprints: [(0, dinein_fixtures_1.dineinFingerprint)('child-1', { num_of_guests: 4 })],
|
|
159
|
+
});
|
|
160
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
161
|
+
expect(counters.orders).toBe(2);
|
|
162
|
+
expect(counters.sales).toBe(30000);
|
|
163
|
+
expect(counters.split_parents).toBe(1);
|
|
164
|
+
expect(counters.split_children).toBe(2);
|
|
165
|
+
expect(counters.split_checks).toBe(3);
|
|
166
|
+
expect(counters.split_sales).toBe(30000);
|
|
167
|
+
expect(counters.split_type_counts).toEqual({ EQUAL: 2 });
|
|
168
|
+
// never the children's (default 0) guests — the fingerprint says 4
|
|
169
|
+
expect(counters.covers).toBe(4);
|
|
170
|
+
// a split group with no parent rating stays unrated
|
|
171
|
+
expect(counters.rated_orders).toBe(0);
|
|
172
|
+
expect(result?.coverage.deleted_split_parents_excluded).toBe(1);
|
|
173
|
+
const rows = (0, dinein_fixtures_1.entryRowsOfDay)(result);
|
|
174
|
+
expect(rows).toHaveLength(2);
|
|
175
|
+
expect(rows.every((row) => row.split_role === 'CHILD')).toBe(true);
|
|
176
|
+
expect(rows.every((row) => row.split_type === 'EQUAL')).toBe(true);
|
|
177
|
+
expect(rows.some((row) => row.order_id === String(parent._id))).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
it('reads the OLDEST iteration for origin and counts edits from oldest to current', () => {
|
|
180
|
+
// iterations[0] is the MOST RECENT previous version; iterations[last] is first.
|
|
181
|
+
const order = (0, dinein_fixtures_1.dineinOrder)({
|
|
182
|
+
platform: 'POS_DINE-IN',
|
|
183
|
+
iterations: [
|
|
184
|
+
// most recent previous version (added 1 line-b)
|
|
185
|
+
{
|
|
186
|
+
platform: 'POS_DINE-IN',
|
|
187
|
+
staff_details: { staff_id: 'staff-1' },
|
|
188
|
+
consumer: { phone: '0300-0000000' },
|
|
189
|
+
categories: [
|
|
190
|
+
{
|
|
191
|
+
items: [
|
|
192
|
+
{ _id: 'line-a', quantity: 2 },
|
|
193
|
+
{ _id: 'line-b', quantity: 1 },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
// FIRST version: a QR self-order (no staff, consumer phone)
|
|
199
|
+
{
|
|
200
|
+
platform: 'APP_DINE-IN',
|
|
201
|
+
staff_details: null,
|
|
202
|
+
order_taker_details: null,
|
|
203
|
+
consumer: { phone: '0300-1111111' },
|
|
204
|
+
categories: [{ items: [{ _id: 'line-a', quantity: 1 }] }],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
categories: [
|
|
208
|
+
{
|
|
209
|
+
items: [
|
|
210
|
+
{ _id: 'line-a', quantity: 2 },
|
|
211
|
+
{ _id: 'line-b', quantity: 1 },
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [order] });
|
|
217
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
218
|
+
// QR self-order is the FIRST version's classification, not the newest one.
|
|
219
|
+
expect(counters.by_origin.QR_SELF_ORDER).toMatchObject({ orders: 1 });
|
|
220
|
+
expect(counters.by_origin.POS_DIRECT).toBeUndefined();
|
|
221
|
+
expect(counters.edited_orders).toBe(1);
|
|
222
|
+
expect(counters.total_edits).toBe(2);
|
|
223
|
+
// oldest(line-a=1) -> mid(line-a=2, line-b=1): +2 ; mid -> current: 0
|
|
224
|
+
expect(counters.item_additions).toBe(2);
|
|
225
|
+
expect(counters.item_removals).toBe(0);
|
|
226
|
+
expect(counters.net_item_change).toBe(2);
|
|
227
|
+
expect((0, dinein_fixtures_1.entryRowsOfDay)(result)[0].edits).toBe(2);
|
|
228
|
+
expect((0, dinein_fixtures_1.entryRowsOfDay)(result)[0].origin).toBe('QR_SELF_ORDER');
|
|
229
|
+
});
|
|
230
|
+
it('classifies a staff-tablet first version and a POS-direct check', () => {
|
|
231
|
+
const tablet = (0, dinein_fixtures_1.dineinOrder)({
|
|
232
|
+
_id: 'tablet',
|
|
233
|
+
platform: 'WEB_DINE-IN',
|
|
234
|
+
iterations: [
|
|
235
|
+
{ platform: 'WEB_DINE-IN', staff_details: { staff_id: 's1' }, categories: [] },
|
|
236
|
+
{ platform: 'WEB_DINE-IN', staff_details: { staff_id: 's1' }, categories: [] },
|
|
237
|
+
],
|
|
238
|
+
});
|
|
239
|
+
const qr = (0, dinein_fixtures_1.dineinOrder)({
|
|
240
|
+
_id: 'qr',
|
|
241
|
+
platform: 'APP_DINE-IN',
|
|
242
|
+
consumer: { phone: '0300-2222222' },
|
|
243
|
+
});
|
|
244
|
+
const unknown = (0, dinein_fixtures_1.dineinOrder)({ _id: 'unknown', platform: 'WEB_DINE-IN', consumer: { phone: '' } });
|
|
245
|
+
const pos = (0, dinein_fixtures_1.dineinOrder)({ _id: 'pos', platform: 'POS_DINE-IN' });
|
|
246
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [tablet, qr, unknown, pos] });
|
|
247
|
+
// Origin is per key (`ORDER_STATUS:PLATFORM`); each fixture platform is its
|
|
248
|
+
// own key, so the origin mix is folded across the day's counter blocks.
|
|
249
|
+
const blocks = Object.values(result.reports[0].dinein_counters);
|
|
250
|
+
const originOrders = (origin) => blocks.reduce((total, block) => total + (block.by_origin[origin]?.orders ?? 0), 0);
|
|
251
|
+
expect(originOrders('STAFF_TABLET')).toBe(1);
|
|
252
|
+
expect(originOrders('QR_SELF_ORDER')).toBe(1);
|
|
253
|
+
expect(originOrders('UNKNOWN_ORIGIN')).toBe(1);
|
|
254
|
+
expect(originOrders('POS_DIRECT')).toBe(1);
|
|
255
|
+
expect(blocks.reduce((total, block) => total + block.origin_orders, 0)).toBe(4);
|
|
256
|
+
expect(blocks.reduce((total, block) => total + block.origin_sales, 0)).toBe(blocks.reduce((total, block) => total + block.sales, 0));
|
|
257
|
+
expect(blocks.reduce((total, block) => total + block.origin_covers, 0)).toBe(blocks.reduce((total, block) => total + block.covers, 0));
|
|
258
|
+
});
|
|
259
|
+
it('classifies card, cash and split-tender payments by collected amount net of refunds', () => {
|
|
260
|
+
const cash = (0, dinein_fixtures_1.dineinOrder)({
|
|
261
|
+
_id: 'cash',
|
|
262
|
+
payments: [{ payment_type: 'CASH', amount_paid: 5000, amount_refunded: 0 }],
|
|
263
|
+
});
|
|
264
|
+
const card = (0, dinein_fixtures_1.dineinOrder)({
|
|
265
|
+
_id: 'card',
|
|
266
|
+
payments: [
|
|
267
|
+
{ payment_type: 'CARD', amount_paid: 3000, amount_refunded: 0 },
|
|
268
|
+
{ payment_type: 'TERMINAL', amount_paid: 2000, amount_refunded: 500 },
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
const split = (0, dinein_fixtures_1.dineinOrder)({
|
|
272
|
+
_id: 'split',
|
|
273
|
+
payments: [
|
|
274
|
+
{ payment_type: 'CASH', amount_paid: 6000, amount_refunded: 0 },
|
|
275
|
+
{ payment_type: 'CARD', amount_paid: 4000, amount_refunded: 0 },
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
const other = (0, dinein_fixtures_1.dineinOrder)({
|
|
279
|
+
_id: 'other',
|
|
280
|
+
payments: [{ payment_type: 'COMPLIMENTARY', amount_paid: 1000, amount_refunded: 0 }],
|
|
281
|
+
});
|
|
282
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [cash, card, split, other] });
|
|
283
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
284
|
+
expect(counters.cash_amount).toBe(11000);
|
|
285
|
+
expect(counters.card_amount).toBe(8500);
|
|
286
|
+
expect(counters.other_amount).toBe(1000);
|
|
287
|
+
expect(counters.cash_orders).toBe(2);
|
|
288
|
+
// two card rows on ONE check is one card order
|
|
289
|
+
expect(counters.card_orders).toBe(2);
|
|
290
|
+
expect(counters.split_tender_orders).toBe(1);
|
|
291
|
+
expect(counters.refunds).toBe(500);
|
|
292
|
+
expect(counters.by_payment_type.CARD).toEqual({ amount: 7000, orders: 2 });
|
|
293
|
+
expect(counters.by_payment_type.TERMINAL).toEqual({ amount: 1500, orders: 1 });
|
|
294
|
+
});
|
|
295
|
+
it('classifies a FIXED service charge (not percentage, not original-price)', () => {
|
|
296
|
+
const fixed = (0, dinein_fixtures_1.dineinOrder)({
|
|
297
|
+
service_fee_amount: 750,
|
|
298
|
+
is_service_fee_percentage: false,
|
|
299
|
+
is_service_fee_taxable: false,
|
|
300
|
+
apply_service_fee_on_original_price: false,
|
|
301
|
+
});
|
|
302
|
+
const percentage = (0, dinein_fixtures_1.dineinOrder)({
|
|
303
|
+
_id: 'pct',
|
|
304
|
+
service_fee_amount: 500,
|
|
305
|
+
service_fee: 10,
|
|
306
|
+
is_service_fee_percentage: true,
|
|
307
|
+
is_service_fee_taxable: true,
|
|
308
|
+
apply_service_fee_on_original_price: true,
|
|
309
|
+
});
|
|
310
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [fixed, percentage] });
|
|
311
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
312
|
+
expect(counters.service_charge_orders).toBe(2);
|
|
313
|
+
expect(counters.service_charge_fixed_orders).toBe(1);
|
|
314
|
+
expect(counters.service_charge_percentage_orders).toBe(1);
|
|
315
|
+
expect(counters.service_charge_taxable_amount).toBe(500);
|
|
316
|
+
expect(counters.service_charge_original_price_orders).toBe(1);
|
|
317
|
+
expect(counters.service_charge_amount).toBe(1250);
|
|
318
|
+
expect(counters.service_charge_rate_counts).toEqual({ 'FIXED:750': 1, 'PCT:10': 1 });
|
|
319
|
+
});
|
|
320
|
+
it('counts offline checks and their sales', () => {
|
|
321
|
+
const offline = (0, dinein_fixtures_1.dineinOrder)({ synced_offline: true, amount_earned: 7000 });
|
|
322
|
+
const online = (0, dinein_fixtures_1.dineinOrder)({ amount_earned: 3000 });
|
|
323
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [offline, online] });
|
|
324
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
325
|
+
expect(counters.offline_orders).toBe(1);
|
|
326
|
+
expect(counters.offline_sales).toBe(7000);
|
|
327
|
+
expect(counters.sales).toBe(10000);
|
|
328
|
+
});
|
|
329
|
+
it('measures seated occupancy from start_time and counts the fallback separately', () => {
|
|
330
|
+
const real = (0, dinein_fixtures_1.dineinOrder)({
|
|
331
|
+
_id: 'real',
|
|
332
|
+
createdAt: '2026-10-01T13:00:00.000Z',
|
|
333
|
+
dinein_details: {
|
|
334
|
+
table_id: 'table-t04',
|
|
335
|
+
table_name: 'T-04',
|
|
336
|
+
floor_id: 'floor-main',
|
|
337
|
+
start_time: '2026-10-01T13:10:00.000Z',
|
|
338
|
+
courses: null,
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
const fallback = (0, dinein_fixtures_1.dineinOrder)({
|
|
342
|
+
_id: 'fallback',
|
|
343
|
+
createdAt: '2026-10-01T14:00:00.000Z',
|
|
344
|
+
dinein_details: {
|
|
345
|
+
table_id: 'table-t11',
|
|
346
|
+
table_name: 'T-11',
|
|
347
|
+
floor_id: 'floor-main',
|
|
348
|
+
start_time: null,
|
|
349
|
+
courses: null,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
353
|
+
orders: [real, fallback],
|
|
354
|
+
fingerprints: [
|
|
355
|
+
(0, dinein_fixtures_1.dineinFingerprint)('real', { createdAt: '2026-10-01T13:50:00.000Z', num_of_guests: 2 }),
|
|
356
|
+
(0, dinein_fixtures_1.dineinFingerprint)('fallback', {
|
|
357
|
+
table_id: 'table-t11',
|
|
358
|
+
name: 'T-11',
|
|
359
|
+
createdAt: '2026-10-01T14:30:00.000Z',
|
|
360
|
+
num_of_guests: 6,
|
|
361
|
+
}),
|
|
362
|
+
],
|
|
363
|
+
});
|
|
364
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
365
|
+
expect(counters.table_sessions).toBe(2);
|
|
366
|
+
expect(counters.occupancy_sessions).toBe(1);
|
|
367
|
+
expect(counters.fallback_occupancy_sessions).toBe(1);
|
|
368
|
+
expect(counters.occupancy_minutes_sum).toBe(40 + 30);
|
|
369
|
+
expect(counters.covers).toBe(2 + 6);
|
|
370
|
+
expect(result?.coverage.fingerprints_fallback_start).toBe(1);
|
|
371
|
+
expect(result?.coverage.fingerprints_joined).toBe(2);
|
|
372
|
+
});
|
|
373
|
+
it('counts a missing fingerprint as a coverage gap and never fabricates covers', () => {
|
|
374
|
+
const withFingerprint = (0, dinein_fixtures_1.dineinOrder)({ _id: 'with' });
|
|
375
|
+
const withoutFingerprint = (0, dinein_fixtures_1.dineinOrder)({ _id: 'without', amount_earned: 5000 });
|
|
376
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
377
|
+
orders: [withFingerprint, withoutFingerprint],
|
|
378
|
+
fingerprints: [(0, dinein_fixtures_1.dineinFingerprint)('with', { num_of_guests: 3 })],
|
|
379
|
+
});
|
|
380
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
381
|
+
expect(counters.orders).toBe(2);
|
|
382
|
+
expect(counters.covers).toBe(3);
|
|
383
|
+
expect(counters.table_sessions).toBe(1);
|
|
384
|
+
expect(result?.coverage.orders_without_fingerprint).toBe(1);
|
|
385
|
+
const rows = (0, dinein_fixtures_1.entryRowsOfDay)(result);
|
|
386
|
+
const missing = rows.find((row) => row.order_id === 'without');
|
|
387
|
+
expect(missing?.covers).toBe(0);
|
|
388
|
+
});
|
|
389
|
+
it('skips a fingerprint with no end and a negative session, counting the gaps', () => {
|
|
390
|
+
const order = (0, dinein_fixtures_1.dineinOrder)();
|
|
391
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
392
|
+
orders: [order],
|
|
393
|
+
fingerprints: [
|
|
394
|
+
(0, dinein_fixtures_1.dineinFingerprint)(String(order._id), { createdAt: null }),
|
|
395
|
+
(0, dinein_fixtures_1.dineinFingerprint)(String(order._id), { createdAt: '2026-10-01T12:00:00.000Z' }),
|
|
396
|
+
],
|
|
397
|
+
});
|
|
398
|
+
expect(result?.coverage.fingerprints_missing_end).toBe(1);
|
|
399
|
+
expect(result?.coverage.fingerprints_negative_duration).toBe(1);
|
|
400
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
401
|
+
expect(counters.table_sessions).toBe(0);
|
|
402
|
+
expect(counters.covers).toBe(0);
|
|
403
|
+
});
|
|
404
|
+
it('dedupes a repeated fingerprint id and ignores an unattached fingerprint', () => {
|
|
405
|
+
const order = (0, dinein_fixtures_1.dineinOrder)();
|
|
406
|
+
const fingerprint = (0, dinein_fixtures_1.dineinFingerprint)(String(order._id));
|
|
407
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
408
|
+
orders: [order],
|
|
409
|
+
fingerprints: [fingerprint, { ...fingerprint }, (0, dinein_fixtures_1.dineinFingerprint)('someone-else', { _id: 'orphan' })],
|
|
410
|
+
});
|
|
411
|
+
expect(result?.coverage.fingerprints_duplicate).toBe(1);
|
|
412
|
+
expect(result?.coverage.fingerprints_unattached).toBe(1);
|
|
413
|
+
expect((0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS).table_sessions).toBe(1);
|
|
414
|
+
});
|
|
415
|
+
it('counts courses as current state only (assigned / called / on hold)', () => {
|
|
416
|
+
const order = (0, dinein_fixtures_1.dineinOrder)({
|
|
417
|
+
dinein_details: {
|
|
418
|
+
table_id: 'table-t04',
|
|
419
|
+
table_name: 'T-04',
|
|
420
|
+
floor_id: 'floor-main',
|
|
421
|
+
start_time: '2026-10-01T13:00:00.000Z',
|
|
422
|
+
courses: [
|
|
423
|
+
{ course_id: 'c-starters', name: 'Starters', item_ids: ['i1', 'i2'], called: true },
|
|
424
|
+
{ course_id: 'c-mains', name: 'Mains', item_ids: ['i3'], called: false },
|
|
425
|
+
],
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [order] });
|
|
429
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
430
|
+
expect(counters.courses_assigned).toBe(2);
|
|
431
|
+
expect(counters.courses_called).toBe(1);
|
|
432
|
+
expect(counters.courses_on_hold).toBe(1);
|
|
433
|
+
expect(counters.course_items).toBe(3);
|
|
434
|
+
expect(counters.by_course['c-starters']).toEqual({
|
|
435
|
+
course_id: 'c-starters',
|
|
436
|
+
name: 'Starters',
|
|
437
|
+
assigned: 1,
|
|
438
|
+
called: 1,
|
|
439
|
+
on_hold: 0,
|
|
440
|
+
items: 2,
|
|
441
|
+
});
|
|
442
|
+
expect(counters.by_course['c-mains']).toMatchObject({ called: 0, on_hold: 1, items: 1 });
|
|
443
|
+
});
|
|
444
|
+
it('counts reservation statuses, covers, lead time and duration', () => {
|
|
445
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
446
|
+
orders: [(0, dinein_fixtures_1.dineinOrder)()],
|
|
447
|
+
reservations: [
|
|
448
|
+
// lead 600 minutes, duration 90
|
|
449
|
+
(0, dinein_fixtures_1.dineinReservation)({ _id: 'r1', reservation_status: 'CONFIRMED' }),
|
|
450
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
451
|
+
_id: 'r2',
|
|
452
|
+
reservation_status: 'PENDING',
|
|
453
|
+
reservation_time: '2026-10-01T19:30:00.000Z',
|
|
454
|
+
createdAt: '2026-10-01T18:30:00.000Z',
|
|
455
|
+
reservation_duration: 60,
|
|
456
|
+
num_of_guests: 2,
|
|
457
|
+
}),
|
|
458
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
459
|
+
_id: 'r3',
|
|
460
|
+
reservation_status: 'CANCELLED',
|
|
461
|
+
num_of_guests: 6,
|
|
462
|
+
reservation_duration: 45,
|
|
463
|
+
}),
|
|
464
|
+
// created AFTER its slot: no lead time, still a booking
|
|
465
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
466
|
+
_id: 'r4',
|
|
467
|
+
reservation_status: 'CONFIRMED',
|
|
468
|
+
reservation_time: '2026-10-01T18:00:00.000Z',
|
|
469
|
+
createdAt: '2026-10-01T18:30:00.000Z',
|
|
470
|
+
source_local_date: '2026-10-02',
|
|
471
|
+
}),
|
|
472
|
+
],
|
|
473
|
+
});
|
|
474
|
+
const reservations = result.reports[0].reservation_counters;
|
|
475
|
+
expect(reservations.reservations).toBe(3);
|
|
476
|
+
expect(reservations.reservation_covers).toBe(4 + 2 + 6);
|
|
477
|
+
expect(reservations.reservation_confirmed).toBe(1);
|
|
478
|
+
expect(reservations.reservation_pending).toBe(1);
|
|
479
|
+
expect(reservations.reservation_cancelled).toBe(1);
|
|
480
|
+
// r1: 600m, r2: 60m, r3: 600m; r4 is out-of-day and never folded
|
|
481
|
+
expect(reservations.reservation_lead_minutes_sum).toBe(600 + 60 + 600);
|
|
482
|
+
expect(reservations.reservation_lead_count).toBe(3);
|
|
483
|
+
expect(reservations.reservation_duration_minutes_sum).toBe(90 + 60 + 45);
|
|
484
|
+
expect(reservations.reservation_duration_count).toBe(3);
|
|
485
|
+
expect(result?.coverage.reservations_out_of_day).toBe(1);
|
|
486
|
+
// reservations are document-level, never in the order-keyed block
|
|
487
|
+
expect((0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS)).not.toHaveProperty('reservations');
|
|
488
|
+
});
|
|
489
|
+
it('exposes reservation counters by TENANT-LOCAL hour and bounded masked rows', () => {
|
|
490
|
+
const reservations = [
|
|
491
|
+
// 18:30Z at +05:30 is 00:00 next day local -> hour 0 of the NEXT local day;
|
|
492
|
+
// for this day we use slots that stay inside the local day.
|
|
493
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
494
|
+
_id: 'r-masked',
|
|
495
|
+
reservation_time: new Date('2026-10-01T13:30:00.000Z'), // 19:00 local at +05:30
|
|
496
|
+
num_of_guests: 4,
|
|
497
|
+
status: 'CONFIRMED',
|
|
498
|
+
customer_name: 'Ayesha Khan',
|
|
499
|
+
customer_phone: '0300-1234567',
|
|
500
|
+
customer_email: 'ayesha@example.com',
|
|
501
|
+
order_from: 'POS',
|
|
502
|
+
createdAt: new Date('2026-10-01T09:00:00.000Z'),
|
|
503
|
+
}),
|
|
504
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
505
|
+
_id: 'r-2',
|
|
506
|
+
reservation_time: new Date('2026-10-01T14:30:00.000Z'), // 20:00 local
|
|
507
|
+
num_of_guests: 2,
|
|
508
|
+
status: 'PENDING',
|
|
509
|
+
customer_name: 'Bilal Ahmed',
|
|
510
|
+
createdAt: new Date('2026-10-01T10:00:00.000Z'),
|
|
511
|
+
order_from: 'WEB',
|
|
512
|
+
}),
|
|
513
|
+
];
|
|
514
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [(0, dinein_fixtures_1.dineinOrder)()], reservations, gmtOffset: 5.5 });
|
|
515
|
+
const block = result.reports[0].reservation_counters;
|
|
516
|
+
expect(block.reservations).toBe(2);
|
|
517
|
+
expect(block.reservation_covers).toBe(6);
|
|
518
|
+
expect(Object.keys(block.by_hour)).toHaveLength(24);
|
|
519
|
+
// 19:00 local -> "19", 20:00 local -> "20"; never the UTC hour.
|
|
520
|
+
expect(block.by_hour['19']).toEqual({ reservations: 1, reservation_covers: 4 });
|
|
521
|
+
expect(block.by_hour['20']).toEqual({ reservations: 1, reservation_covers: 2 });
|
|
522
|
+
expect(block.by_hour['13']).toEqual({ reservations: 0, reservation_covers: 0 });
|
|
523
|
+
const upcoming = result.reports[0].upcoming_reservations ?? [];
|
|
524
|
+
expect(upcoming).toHaveLength(2);
|
|
525
|
+
// Soonest first, deduped by reservation id.
|
|
526
|
+
expect(upcoming.map((row) => row.reservation_id)).toEqual(['r-masked', 'r-2']);
|
|
527
|
+
expect(upcoming[0]).toEqual({
|
|
528
|
+
reservation_id: 'r-masked',
|
|
529
|
+
guest_label: 'A. K.',
|
|
530
|
+
reservation_time: '2026-10-01T13:30:00.000Z',
|
|
531
|
+
local_hour: 19,
|
|
532
|
+
party_size: 4,
|
|
533
|
+
status: 'CONFIRMED',
|
|
534
|
+
source: 'POS',
|
|
535
|
+
lead_minutes: 270,
|
|
536
|
+
});
|
|
537
|
+
// No customer name / phone / email anywhere on the document.
|
|
538
|
+
const serialized = JSON.stringify(result.reports[0]);
|
|
539
|
+
expect(serialized).not.toContain('Ayesha');
|
|
540
|
+
expect(serialized).not.toContain('0300-1234567');
|
|
541
|
+
expect(serialized).not.toContain('ayesha@example.com');
|
|
542
|
+
});
|
|
543
|
+
it('caps the upcoming and most-edited snapshots at the declared limits', () => {
|
|
544
|
+
const reservations = [];
|
|
545
|
+
for (let index = 0; index < 15; index += 1) {
|
|
546
|
+
reservations.push((0, dinein_fixtures_1.dineinReservation)({
|
|
547
|
+
_id: 'cap-r-' + String(index).padStart(2, '0'),
|
|
548
|
+
reservation_time: new Date(`2026-10-01T${String(10 + (index % 10)).padStart(2, '0')}:00:00.000Z`),
|
|
549
|
+
customer_name: 'Guest ' + index,
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
const edited = [];
|
|
553
|
+
for (let index = 0; index < 15; index += 1) {
|
|
554
|
+
edited.push((0, dinein_fixtures_1.dineinOrder)({
|
|
555
|
+
_id: 'edit-' + String(index).padStart(2, '0'),
|
|
556
|
+
iterations: new Array(index + 1).fill({
|
|
557
|
+
categories: [{ items: [{ _id: 'line-a', quantity: 1 }] }],
|
|
558
|
+
}),
|
|
559
|
+
categories: [{ items: [{ _id: 'line-a', quantity: 2 }] }],
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: edited, reservations });
|
|
563
|
+
const report = result.reports[0];
|
|
564
|
+
expect(report.upcoming_reservations).toHaveLength(10);
|
|
565
|
+
expect(report.top_edited_checks).toHaveLength(10);
|
|
566
|
+
// Ranked `edits DESC, item_additions DESC, order_id ASC`.
|
|
567
|
+
expect(report.top_edited_checks.map((row) => row.edits)).toEqual([15, 14, 13, 12, 11, 10, 9, 8, 7, 6]);
|
|
568
|
+
for (const row of report.upcoming_reservations ?? []) {
|
|
569
|
+
expect(row.guest_label).toMatch(/^[A-Z]\.( [A-Z]\.)?$/);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
it('writes the EXACT canonical entry row field set', () => {
|
|
573
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [(0, dinein_fixtures_1.dineinOrder)()] });
|
|
574
|
+
const row = (0, dinein_fixtures_1.entryRowsOfDay)(result)[0];
|
|
575
|
+
expect(Object.keys(row).sort()).toEqual([
|
|
576
|
+
'covers',
|
|
577
|
+
'edits',
|
|
578
|
+
'floor_id',
|
|
579
|
+
'items',
|
|
580
|
+
'localDate',
|
|
581
|
+
'offline',
|
|
582
|
+
'order_id',
|
|
583
|
+
'order_number',
|
|
584
|
+
'origin',
|
|
585
|
+
'platform',
|
|
586
|
+
'rating',
|
|
587
|
+
'sales',
|
|
588
|
+
'service_charge',
|
|
589
|
+
'split_role',
|
|
590
|
+
'split_type',
|
|
591
|
+
'status',
|
|
592
|
+
'table_id',
|
|
593
|
+
'table_name',
|
|
594
|
+
'time',
|
|
595
|
+
].sort());
|
|
596
|
+
expect(typeof row.localDate).toBe('string');
|
|
597
|
+
expect(typeof row.time).toBe('string');
|
|
598
|
+
expect(row.order_number).toBe(2418);
|
|
599
|
+
expect(row.split_role).toBe('NONE');
|
|
600
|
+
});
|
|
601
|
+
it('credits a rating written on the deleted split parent to exactly one child', () => {
|
|
602
|
+
const parent = (0, dinein_fixtures_1.dineinOrder)({
|
|
603
|
+
is_deleted: true,
|
|
604
|
+
delete_reason: 'Auto Deleted on Split',
|
|
605
|
+
split_child_ids: ['child-a', 'child-b'],
|
|
606
|
+
split_type: 'ITEM',
|
|
607
|
+
rating: 4,
|
|
608
|
+
review: 'Great service',
|
|
609
|
+
});
|
|
610
|
+
const childA = (0, dinein_fixtures_1.dineinOrder)({ _id: 'child-a', split_parent_id: String(parent._id) });
|
|
611
|
+
const childB = (0, dinein_fixtures_1.dineinOrder)({ _id: 'child-b', split_parent_id: String(parent._id), review: 'second' });
|
|
612
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
613
|
+
orders: [childB, childA],
|
|
614
|
+
deletedSplitParents: [parent],
|
|
615
|
+
});
|
|
616
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
617
|
+
expect(counters.rated_orders).toBe(1);
|
|
618
|
+
expect(counters.rating_sum).toBe(4);
|
|
619
|
+
expect(counters.rating_4).toBe(1);
|
|
620
|
+
expect(counters.review_count).toBe(1);
|
|
621
|
+
expect(result?.coverage.ratings_from_deleted_parents).toBe(1);
|
|
622
|
+
const rows = (0, dinein_fixtures_1.entryRowsOfDay)(result);
|
|
623
|
+
const rated = rows.filter((row) => row.rating != null);
|
|
624
|
+
expect(rated).toHaveLength(1);
|
|
625
|
+
// deterministic: the smallest child id inherits the parent's rating
|
|
626
|
+
expect(rated[0].order_id).toBe('child-a');
|
|
627
|
+
});
|
|
628
|
+
it('does not duplicate a parent rating when the child already has one', () => {
|
|
629
|
+
const parent = (0, dinein_fixtures_1.dineinOrder)({
|
|
630
|
+
is_deleted: true,
|
|
631
|
+
delete_reason: 'Auto Deleted on Split',
|
|
632
|
+
split_child_ids: ['child-a'],
|
|
633
|
+
rating: 3,
|
|
634
|
+
});
|
|
635
|
+
const child = (0, dinein_fixtures_1.dineinOrder)({ _id: 'child-a', split_parent_id: String(parent._id), rating: 5 });
|
|
636
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [child], deletedSplitParents: [parent] });
|
|
637
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
638
|
+
expect(counters.rated_orders).toBe(1);
|
|
639
|
+
expect(counters.rating_5).toBe(1);
|
|
640
|
+
expect(counters.rating_sum).toBe(5);
|
|
641
|
+
expect(result?.coverage.ratings_from_deleted_parents).toBe(0);
|
|
642
|
+
});
|
|
643
|
+
it('ignores an invalid rating and counts only a non-empty review', () => {
|
|
644
|
+
const bad = (0, dinein_fixtures_1.dineinOrder)({ rating: 0, review: ' ' });
|
|
645
|
+
const good = (0, dinein_fixtures_1.dineinOrder)({ rating: 5, review: 'Lovely' });
|
|
646
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [bad, good] });
|
|
647
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
648
|
+
expect(counters.rated_orders).toBe(1);
|
|
649
|
+
expect(counters.rating_sum).toBe(5);
|
|
650
|
+
expect(counters.review_count).toBe(1);
|
|
651
|
+
});
|
|
652
|
+
it('buckets by the order hour, status, platform, table and floor', () => {
|
|
653
|
+
const morning = (0, dinein_fixtures_1.dineinOrder)({ _id: 'm', localHour: 9 });
|
|
654
|
+
const evening = (0, dinein_fixtures_1.dineinOrder)({ _id: 'e', localHour: 20 });
|
|
655
|
+
const noHour = (0, dinein_fixtures_1.dineinOrder)({ _id: 'n', localHour: null });
|
|
656
|
+
const cancelled = (0, dinein_fixtures_1.dineinOrder)({ _id: 'c', localHour: 9, order_status: 'CANCELLED' });
|
|
657
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [morning, evening, noHour, cancelled] });
|
|
658
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
659
|
+
expect(counters.by_hour['9']).toEqual({ orders: 1, sales: 21400, covers: 0 });
|
|
660
|
+
expect(counters.by_hour['20']).toEqual({ orders: 1, sales: 21400, covers: 0 });
|
|
661
|
+
expect(counters.by_hour['0']).toEqual({ orders: 0, sales: 0, covers: 0 });
|
|
662
|
+
expect(Object.keys(counters.by_hour)).toHaveLength(24);
|
|
663
|
+
expect(counters.by_status.COMPLETED).toEqual({ orders: 3, covers: 0, sales: 64200 });
|
|
664
|
+
expect(counters.by_platform['POS_DINE-IN']).toEqual({ orders: 3, covers: 0, sales: 64200 });
|
|
665
|
+
const cancelledCounters = (0, dinein_fixtures_1.countersOfDay)(result, 'CANCELLED:POS_DINE-IN');
|
|
666
|
+
expect(cancelledCounters.cancelled_orders).toBe(1);
|
|
667
|
+
expect(cancelledCounters.by_hour['9']).toEqual({ orders: 1, sales: 21400, covers: 0 });
|
|
668
|
+
});
|
|
669
|
+
it('keys counters by ORDER_STATUS:PLATFORM and keeps a missing dimension explicit', () => {
|
|
670
|
+
const order = (0, dinein_fixtures_1.dineinOrder)({ platform: null, order_status: null });
|
|
671
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [order] });
|
|
672
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, 'UNKNOWN:UNKNOWN');
|
|
673
|
+
expect(counters.orders).toBe(1);
|
|
674
|
+
expect(counters.by_status.UNKNOWN).toEqual({ orders: 1, covers: 0, sales: 21400 });
|
|
675
|
+
expect(counters.by_platform.UNKNOWN).toEqual({ orders: 1, covers: 0, sales: 21400 });
|
|
676
|
+
expect(result?.reports[0].sale_type_key_filters).toEqual(['ORDER_STATUS', 'PLATFORM']);
|
|
677
|
+
});
|
|
678
|
+
it('returns null for an empty day (no check, no reservation)', () => {
|
|
679
|
+
expect((0, dinein_fixtures_1.compileDay)({ orders: [] })).toBeNull();
|
|
680
|
+
// a dine-in order from ANOTHER day is never moved into this one
|
|
681
|
+
const otherDay = (0, dinein_fixtures_1.dineinOrder)({ localDate: '2026-10-02' });
|
|
682
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [otherDay] });
|
|
683
|
+
expect(result).toBeNull();
|
|
684
|
+
});
|
|
685
|
+
it('returns null for invalid arguments', () => {
|
|
686
|
+
expect((0, materialized_dinein_compile_helpers_1.compileTenantDineinReports)({
|
|
687
|
+
tenantId: '',
|
|
688
|
+
brandId: 'b',
|
|
689
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
690
|
+
})).toBeNull();
|
|
691
|
+
expect((0, materialized_dinein_compile_helpers_1.compileTenantDineinReports)({
|
|
692
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
693
|
+
brandId: 'b',
|
|
694
|
+
localDate: '2026-02-31',
|
|
695
|
+
})).toBeNull();
|
|
696
|
+
});
|
|
697
|
+
it('still materializes a day that only has reservations', () => {
|
|
698
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [], reservations: [(0, dinein_fixtures_1.dineinReservation)()] });
|
|
699
|
+
expect(result).not.toBeNull();
|
|
700
|
+
expect(result.reports[0].dinein_counters).toEqual({});
|
|
701
|
+
expect(result.reports[0].reservation_counters.reservations).toBe(1);
|
|
702
|
+
expect(result.entries).toHaveLength(0);
|
|
703
|
+
});
|
|
704
|
+
it('builds one day page plus the three period pages, all page-partitioned', () => {
|
|
705
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [(0, dinein_fixtures_1.dineinOrder)()] });
|
|
706
|
+
const scopes = (result?.entries ?? []).map((entry) => ({
|
|
707
|
+
scope: String(entry.scope_context),
|
|
708
|
+
field: entry.scope_field,
|
|
709
|
+
page: entry.page,
|
|
710
|
+
}));
|
|
711
|
+
expect(scopes).toEqual([
|
|
712
|
+
{ scope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, field: dinein_fixtures_1.DINEIN_DAY, page: 'all' },
|
|
713
|
+
{ scope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK, field: '2026-09-27', page: dinein_fixtures_1.DINEIN_DAY },
|
|
714
|
+
{ scope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR, field: '2026-W40', page: dinein_fixtures_1.DINEIN_DAY },
|
|
715
|
+
{ scope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH, field: '2026-10', page: dinein_fixtures_1.DINEIN_DAY },
|
|
716
|
+
]);
|
|
717
|
+
expect((0, dinein_fixtures_1.entryPageOfDay)(result, MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)?.day_index).toBe('THU');
|
|
718
|
+
expect((0, dinein_fixtures_1.entryPageOfDay)(result, MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH)?.day_index).toBeNull();
|
|
719
|
+
});
|
|
720
|
+
it('sorts the entry rows newest first with a total order-id tie-break', () => {
|
|
721
|
+
const first = (0, dinein_fixtures_1.dineinOrder)({ _id: 'o-a', createdAt: '2026-10-01T12:00:00.000Z' });
|
|
722
|
+
const second = (0, dinein_fixtures_1.dineinOrder)({ _id: 'o-b', createdAt: '2026-10-01T14:00:00.000Z' });
|
|
723
|
+
const same = (0, dinein_fixtures_1.dineinOrder)({ _id: 'o-a2', createdAt: '2026-10-01T14:00:00.000Z' });
|
|
724
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [first, second, same] });
|
|
725
|
+
const rows = (0, dinein_fixtures_1.entryPageOfDay)(result, MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE).dinein_entries[COMPLETED_POS].rows;
|
|
726
|
+
expect(rows.map((row) => row.order_id)).toEqual(['o-b', 'o-a2', 'o-a']);
|
|
727
|
+
});
|
|
728
|
+
it('reports an out-of-day order as a coverage fact, not as a count', () => {
|
|
729
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
730
|
+
orders: [(0, dinein_fixtures_1.dineinOrder)({ _id: 'in-day' }), (0, dinein_fixtures_1.dineinOrder)({ _id: 'other-day', localDate: '2026-09-30' })],
|
|
731
|
+
});
|
|
732
|
+
expect(result?.coverage.orders_counted).toBe(1);
|
|
733
|
+
expect(result?.coverage.orders_out_of_day).toBe(1);
|
|
734
|
+
expect((0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS).orders).toBe(1);
|
|
735
|
+
});
|
|
736
|
+
it('ignores a deleted non-split order entirely', () => {
|
|
737
|
+
const deleted = (0, dinein_fixtures_1.dineinOrder)({ is_deleted: true, delete_reason: 'Manual' });
|
|
738
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [deleted] });
|
|
739
|
+
expect(result).toBeNull();
|
|
740
|
+
});
|
|
741
|
+
it('splits an oversized entry page into disjoint deterministic #N pages', () => {
|
|
742
|
+
const orders = [];
|
|
743
|
+
for (let index = 0; index < 40; index += 1) {
|
|
744
|
+
orders.push((0, dinein_fixtures_1.dineinOrder)({ _id: 'split-' + String(index).padStart(3, '0'), amount_earned: 1000 + index }));
|
|
745
|
+
}
|
|
746
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders });
|
|
747
|
+
const page = (0, dinein_fixtures_1.entryPageOfDay)(result, 'localDate');
|
|
748
|
+
// Force a tiny budget so the splitter has to chunk the page.
|
|
749
|
+
const chunks = (0, materialized_dinein_entry_pages_1.splitMaterializedDineinEntryPage)(page, 6 * 1024);
|
|
750
|
+
expect(chunks.length).toBeGreaterThan(1);
|
|
751
|
+
expect(chunks.map((chunk) => chunk.page)).toEqual(chunks.map((_chunk, index) => 'all#' + String(index)));
|
|
752
|
+
const seen = new Set();
|
|
753
|
+
for (const chunk of chunks) {
|
|
754
|
+
for (const section of Object.values(chunk.dinein_entries ?? {})) {
|
|
755
|
+
for (const row of section.rows) {
|
|
756
|
+
expect(seen.has(row.order_id)).toBe(false);
|
|
757
|
+
seen.add(row.order_id);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
expect(seen.size).toBe(40);
|
|
762
|
+
// The merged logical page is the original rows, exactly once.
|
|
763
|
+
const merged = (0, materialized_dinein_entry_pages_1.mergeMaterializedDineinEntryPages)(chunks, {
|
|
764
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
765
|
+
scope_field: dinein_fixtures_1.DINEIN_DAY,
|
|
766
|
+
page: 'all',
|
|
767
|
+
});
|
|
768
|
+
expect(entryRowsOfPage(merged)).toHaveLength(40);
|
|
769
|
+
});
|
|
770
|
+
it('stays within the 15 MiB report and entry-page budgets for a large day', () => {
|
|
771
|
+
const orders = [];
|
|
772
|
+
for (let index = 0; index < 400; index += 1) {
|
|
773
|
+
orders.push((0, dinein_fixtures_1.dineinOrder)({
|
|
774
|
+
_id: 'bulk-' + String(index).padStart(4, '0'),
|
|
775
|
+
amount_earned: 1000 + index,
|
|
776
|
+
}));
|
|
777
|
+
}
|
|
778
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders });
|
|
779
|
+
expect(result).not.toBeNull();
|
|
780
|
+
const reportBytes = Buffer.byteLength(JSON.stringify(result.reports[0]));
|
|
781
|
+
const pageBytes = Buffer.byteLength(JSON.stringify((0, dinein_fixtures_1.entryPageOfDay)(result, 'localDate')));
|
|
782
|
+
expect(reportBytes).toBeLessThan(15 * 1024 * 1024);
|
|
783
|
+
expect(pageBytes).toBeLessThan(15 * 1024 * 1024);
|
|
784
|
+
});
|
|
785
|
+
it('re-bounds the table map at the document level when a day exceeds the cap', () => {
|
|
786
|
+
const orders = [];
|
|
787
|
+
for (let index = 0; index < 260; index += 1) {
|
|
788
|
+
orders.push((0, dinein_fixtures_1.dineinOrder)({
|
|
789
|
+
_id: 'cap-' + String(index).padStart(4, '0'),
|
|
790
|
+
dinein_details: {
|
|
791
|
+
table_id: 't-' + String(index),
|
|
792
|
+
table_name: 'T-' + String(index),
|
|
793
|
+
floor_id: 'f-1',
|
|
794
|
+
start_time: '2026-10-01T13:00:00.000Z',
|
|
795
|
+
courses: null,
|
|
796
|
+
},
|
|
797
|
+
}));
|
|
798
|
+
}
|
|
799
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders });
|
|
800
|
+
const counters = (0, dinein_fixtures_1.countersOfDay)(result, COMPLETED_POS);
|
|
801
|
+
expect(Object.keys(counters.by_table).length).toBeLessThanOrEqual(201);
|
|
802
|
+
expect(counters.by_table.__OTHER__).toBeDefined();
|
|
803
|
+
expect(counters.by_table.__OTHER__.orders).toBe(60);
|
|
804
|
+
// totals still reconcile
|
|
805
|
+
expect(counters.orders).toBe(260);
|
|
806
|
+
});
|
|
807
|
+
});
|