@managesome/eposmatic-toolkit 0.4.60 → 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 -4
- 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 -4
- package/lib/constants/MATERIALIZED_REPORTS.js +178 -5
- 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,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_dinein_close_day_helpers_1 = require("../../helpers/materialized-reports/materialized-dinein-close-day-helpers");
|
|
5
|
+
const tenant_dinein_formatter_1 = require("../../helpers/materialized-reports/tenant-dinein-formatter");
|
|
6
|
+
const dinein_fixtures_1 = require("./dinein-fixtures");
|
|
7
|
+
/**
|
|
8
|
+
* Dinein formatter — every rate/average is DERIVED, never stored.
|
|
9
|
+
*
|
|
10
|
+
* The formatter consumes integer-only documents and produces the page payload:
|
|
11
|
+
* summary + 24 hour rows + origin/table/floor/course/payment breakdowns +
|
|
12
|
+
* reservations. It is pure and never throws.
|
|
13
|
+
*/
|
|
14
|
+
const documentsFor = (orders, extras = {}) => {
|
|
15
|
+
const compiledOrders = orders.map((overrides) => (0, dinein_fixtures_1.dineinOrder)(overrides));
|
|
16
|
+
const compile = (0, dinein_fixtures_1.compileDay)({
|
|
17
|
+
orders: compiledOrders,
|
|
18
|
+
fingerprints: compiledOrders.map((order) => (0, dinein_fixtures_1.dineinFingerprint)(String(order._id), {
|
|
19
|
+
num_of_guests: extras.guests?.[String(order._id)] ?? 4,
|
|
20
|
+
...(extras.fingerprints?.[String(order._id)] ?? {}),
|
|
21
|
+
})),
|
|
22
|
+
reservations: (extras.reservations ?? []).map((overrides) => (0, dinein_fixtures_1.dineinReservation)(overrides)),
|
|
23
|
+
});
|
|
24
|
+
if (compile == null)
|
|
25
|
+
return [];
|
|
26
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
27
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
28
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
29
|
+
reports: compile.reports,
|
|
30
|
+
entries: compile.entries,
|
|
31
|
+
reason: 'NEW_DAY',
|
|
32
|
+
});
|
|
33
|
+
// The formatter consumes ONE scope level; the day documents are the level the
|
|
34
|
+
// page's current selection resolves to here.
|
|
35
|
+
return plan.writes.filter((write) => String(write.report.scope_context) === 'localDate').map((write) => write.report);
|
|
36
|
+
};
|
|
37
|
+
describe('dinein formatter', () => {
|
|
38
|
+
it('derives the headline rates from the stored integers', () => {
|
|
39
|
+
const documents = documentsFor([
|
|
40
|
+
{
|
|
41
|
+
_id: 'check-1',
|
|
42
|
+
amount_earned: 21400,
|
|
43
|
+
service_fee_amount: 1000,
|
|
44
|
+
is_service_fee_percentage: true,
|
|
45
|
+
is_service_fee_taxable: true,
|
|
46
|
+
rating: 5,
|
|
47
|
+
categories: [{ items: [{ _id: 'line-a', quantity: 3 }] }],
|
|
48
|
+
},
|
|
49
|
+
], { guests: { 'check-1': 4 } });
|
|
50
|
+
const { summary } = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
51
|
+
expect(summary.orders).toBe(1);
|
|
52
|
+
expect(summary.sales).toBe(21400);
|
|
53
|
+
expect(summary.covers).toBe(4);
|
|
54
|
+
expect(summary.items).toBe(3);
|
|
55
|
+
// money averages stay in integer cents
|
|
56
|
+
expect(summary.average_ticket).toBe(21400);
|
|
57
|
+
expect(summary.average_covers_per_check).toBe(4);
|
|
58
|
+
expect(summary.service_charge_share).toBe(4.67);
|
|
59
|
+
expect(summary.service_charge_orders).toBe(1);
|
|
60
|
+
expect(summary.service_charge_percentage_orders).toBe(1);
|
|
61
|
+
expect(summary.service_charge_fixed_orders).toBe(0);
|
|
62
|
+
expect(summary.average_rating).toBe(5);
|
|
63
|
+
expect(summary.rated_orders).toBe(1);
|
|
64
|
+
expect(summary.cancelled_rate).toBe(0);
|
|
65
|
+
expect(summary.edit_rate).toBe(0);
|
|
66
|
+
expect(summary.average_edits_per_check).toBe(0);
|
|
67
|
+
});
|
|
68
|
+
it('derives the average seated occupancy from the measured sessions', () => {
|
|
69
|
+
const documents = documentsFor([
|
|
70
|
+
{
|
|
71
|
+
_id: 'seated',
|
|
72
|
+
createdAt: '2026-10-01T13:00:00.000Z',
|
|
73
|
+
dinein_details: {
|
|
74
|
+
table_id: 'table-t04',
|
|
75
|
+
table_name: 'T-04',
|
|
76
|
+
floor_id: 'floor-main',
|
|
77
|
+
start_time: '2026-10-01T13:00:00.000Z',
|
|
78
|
+
courses: null,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
], {
|
|
82
|
+
fingerprints: {
|
|
83
|
+
seated: { createdAt: '2026-10-01T13:40:00.000Z', num_of_guests: 2 },
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const { summary } = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
87
|
+
expect(summary.occupancy_minutes_sum).toBe(40);
|
|
88
|
+
expect(summary.occupancy_sessions).toBe(1);
|
|
89
|
+
expect(summary.fallback_occupancy_sessions).toBe(0);
|
|
90
|
+
expect(summary.average_occupancy_minutes).toBe(40);
|
|
91
|
+
expect(summary.table_sessions).toBe(1);
|
|
92
|
+
expect(summary.tables_served).toBe(1);
|
|
93
|
+
expect(summary.tables_served_distinct).toBe(1);
|
|
94
|
+
expect(summary.tables_truncated).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
it('exposes split-bill counters and their share of sales', () => {
|
|
97
|
+
const parent = (0, dinein_fixtures_1.dineinOrder)({
|
|
98
|
+
_id: 'parent',
|
|
99
|
+
is_deleted: true,
|
|
100
|
+
delete_reason: 'Auto Deleted on Split',
|
|
101
|
+
split_child_ids: ['child-1', 'child-2'],
|
|
102
|
+
split_type: 'EQUAL',
|
|
103
|
+
});
|
|
104
|
+
const compiled = (0, dinein_fixtures_1.compileDay)({
|
|
105
|
+
orders: [
|
|
106
|
+
(0, dinein_fixtures_1.dineinOrder)({ _id: 'child-1', split_parent_id: String(parent._id), amount_earned: 5000 }),
|
|
107
|
+
(0, dinein_fixtures_1.dineinOrder)({ _id: 'child-2', split_parent_id: String(parent._id), amount_earned: 5000 }),
|
|
108
|
+
],
|
|
109
|
+
deletedSplitParents: [parent],
|
|
110
|
+
});
|
|
111
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
112
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
113
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
114
|
+
reports: compiled.reports,
|
|
115
|
+
entries: compiled.entries,
|
|
116
|
+
reason: 'NEW_DAY',
|
|
117
|
+
});
|
|
118
|
+
const { summary } = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(plan.writes.filter((write) => String(write.report.scope_context) === 'localDate').map((write) => write.report));
|
|
119
|
+
expect(summary.split_parents).toBe(1);
|
|
120
|
+
expect(summary.split_children).toBe(2);
|
|
121
|
+
expect(summary.split_checks).toBe(3);
|
|
122
|
+
expect(summary.split_sales).toBe(10000);
|
|
123
|
+
expect(summary.split_sales_share).toBe(100);
|
|
124
|
+
expect(summary.split_type_counts).toEqual({ EQUAL: 2 });
|
|
125
|
+
});
|
|
126
|
+
it('derives payment, offline and edit shares', () => {
|
|
127
|
+
const documents = documentsFor([
|
|
128
|
+
{
|
|
129
|
+
_id: 'mixed',
|
|
130
|
+
amount_earned: 10000,
|
|
131
|
+
synced_offline: true,
|
|
132
|
+
payments: [
|
|
133
|
+
{ payment_type: 'CASH', amount_paid: 6000, amount_refunded: 0 },
|
|
134
|
+
{ payment_type: 'CARD', amount_paid: 4000, amount_refunded: 0 },
|
|
135
|
+
],
|
|
136
|
+
iterations: [
|
|
137
|
+
{ categories: [{ items: [{ _id: 'line-a', quantity: 2 }] }] },
|
|
138
|
+
{ categories: [{ items: [{ _id: 'line-a', quantity: 1 }] }] },
|
|
139
|
+
],
|
|
140
|
+
categories: [{ items: [{ _id: 'line-a', quantity: 2 }] }],
|
|
141
|
+
},
|
|
142
|
+
], { guests: { mixed: 2 } });
|
|
143
|
+
const { summary } = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
144
|
+
expect(summary.cash_amount).toBe(6000);
|
|
145
|
+
expect(summary.card_amount).toBe(4000);
|
|
146
|
+
expect(summary.cash_share).toBe(60);
|
|
147
|
+
expect(summary.card_share).toBe(40);
|
|
148
|
+
expect(summary.other_share).toBe(0);
|
|
149
|
+
expect(summary.cash_orders).toBe(1);
|
|
150
|
+
expect(summary.card_orders).toBe(1);
|
|
151
|
+
expect(summary.split_tender_orders).toBe(1);
|
|
152
|
+
expect(summary.offline_orders).toBe(1);
|
|
153
|
+
expect(summary.offline_sales_share).toBe(100);
|
|
154
|
+
expect(summary.edited_orders).toBe(1);
|
|
155
|
+
expect(summary.total_edits).toBe(2);
|
|
156
|
+
expect(summary.item_additions).toBe(1);
|
|
157
|
+
expect(summary.item_removals).toBe(0);
|
|
158
|
+
expect(summary.net_item_change).toBe(1);
|
|
159
|
+
expect(summary.edit_rate).toBe(100);
|
|
160
|
+
expect(summary.average_edits_per_check).toBe(2);
|
|
161
|
+
});
|
|
162
|
+
it('returns 24 hour rows with sales and covers, zero where nothing happened', () => {
|
|
163
|
+
const documents = documentsFor([{ _id: 'hour-check', localHour: 20, amount_earned: 9000 }], {
|
|
164
|
+
guests: { 'hour-check': 3 },
|
|
165
|
+
});
|
|
166
|
+
const formatted = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
167
|
+
expect(formatted.by_hour).toHaveLength(24);
|
|
168
|
+
expect(formatted.by_hour.map((row) => row.label)).toEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS);
|
|
169
|
+
const hour20 = formatted.by_hour.find((row) => row.hour === 20);
|
|
170
|
+
expect(hour20).toMatchObject({ orders: 1, sales: 9000, covers: 3 });
|
|
171
|
+
expect(formatted.by_hour.find((row) => row.hour === 3)).toMatchObject({ orders: 0, sales: 0, covers: 0 });
|
|
172
|
+
});
|
|
173
|
+
it('exposes the origin / table / floor / course / payment breakdowns', () => {
|
|
174
|
+
const documents = documentsFor([
|
|
175
|
+
{
|
|
176
|
+
_id: 'breakdown',
|
|
177
|
+
amount_earned: 7000,
|
|
178
|
+
dinein_details: {
|
|
179
|
+
table_id: 'table-t11',
|
|
180
|
+
table_name: 'T-11',
|
|
181
|
+
floor_id: 'floor-terrace',
|
|
182
|
+
start_time: '2026-10-01T13:00:00.000Z',
|
|
183
|
+
courses: [
|
|
184
|
+
{ course_id: 'c-starters', name: 'Starters', item_ids: ['i1'], called: true },
|
|
185
|
+
{ course_id: 'c-mains', name: 'Mains', item_ids: ['i2', 'i3'], called: false },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
payments: [{ payment_type: 'CARD', amount_paid: 7000, amount_refunded: 0 }],
|
|
189
|
+
},
|
|
190
|
+
], {
|
|
191
|
+
fingerprints: {
|
|
192
|
+
breakdown: {
|
|
193
|
+
table_id: 'table-t11',
|
|
194
|
+
name: 'T-11',
|
|
195
|
+
dinein_floor_id: 'floor-terrace',
|
|
196
|
+
createdAt: '2026-10-01T13:30:00.000Z',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const formatted = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
201
|
+
expect(formatted.by_origin).toEqual([{ origin: 'POS_DIRECT', orders: 1, sales: 7000, covers: 4 }]);
|
|
202
|
+
expect(formatted.by_table[0]).toMatchObject({
|
|
203
|
+
table_id: 'table-t11',
|
|
204
|
+
table_name: 'T-11',
|
|
205
|
+
floor_id: 'floor-terrace',
|
|
206
|
+
orders: 1,
|
|
207
|
+
sessions: 1,
|
|
208
|
+
covers: 4,
|
|
209
|
+
sales: 7000,
|
|
210
|
+
average_occupancy_minutes: 30,
|
|
211
|
+
});
|
|
212
|
+
expect(formatted.by_floor[0]).toMatchObject({ floor_id: 'floor-terrace', orders: 1, sessions: 1 });
|
|
213
|
+
// deterministic: `assigned DESC, key ASC`
|
|
214
|
+
expect(formatted.by_course.map((row) => row.course_id)).toEqual(['c-mains', 'c-starters']);
|
|
215
|
+
expect(formatted.by_course[0]).toMatchObject({ called: 0, on_hold: 1, items: 2, call_rate: 0 });
|
|
216
|
+
expect(formatted.by_course[1]).toMatchObject({ called: 1, items: 1, call_rate: 100 });
|
|
217
|
+
expect(formatted.by_payment_type).toEqual([{ payment_type: 'CARD', amount: 7000, orders: 1 }]);
|
|
218
|
+
expect(formatted.summary.course_call_rate).toBe(50);
|
|
219
|
+
});
|
|
220
|
+
it('derives reservation averages and exposes no conversion rate', () => {
|
|
221
|
+
const documents = documentsFor([], {
|
|
222
|
+
reservations: [
|
|
223
|
+
(0, dinein_fixtures_1.dineinReservation)({ _id: 'r1', num_of_guests: 4, reservation_duration: 90 }),
|
|
224
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
225
|
+
_id: 'r2',
|
|
226
|
+
num_of_guests: 2,
|
|
227
|
+
reservation_duration: 60,
|
|
228
|
+
reservation_time: '2026-10-01T19:30:00.000Z',
|
|
229
|
+
createdAt: '2026-10-01T18:30:00.000Z',
|
|
230
|
+
}),
|
|
231
|
+
],
|
|
232
|
+
});
|
|
233
|
+
const formatted = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
234
|
+
expect(formatted.reservations.reservations).toBe(2);
|
|
235
|
+
expect(formatted.reservations.reservation_covers).toBe(6);
|
|
236
|
+
expect(formatted.reservations.average_party_size).toBe(3);
|
|
237
|
+
expect(formatted.reservations.average_lead_minutes).toBe(330);
|
|
238
|
+
expect(formatted.reservations.average_duration_minutes).toBe(75);
|
|
239
|
+
expect(formatted.reservations).not.toHaveProperty('seated_rate');
|
|
240
|
+
expect(formatted.reservations).not.toHaveProperty('no_show_rate');
|
|
241
|
+
expect(formatted.reservations).not.toHaveProperty('conversion_rate');
|
|
242
|
+
});
|
|
243
|
+
it('applies the key filters to the counters but never to reservations', () => {
|
|
244
|
+
const documents = documentsFor([
|
|
245
|
+
{ _id: 'pos', platform: 'POS_DINE-IN', amount_earned: 5000 },
|
|
246
|
+
{ _id: 'web', platform: 'WEB_DINE-IN', amount_earned: 7000, consumer: { phone: '0300-1' } },
|
|
247
|
+
], { reservations: [(0, dinein_fixtures_1.dineinReservation)()] });
|
|
248
|
+
const unfiltered = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
249
|
+
expect(unfiltered.summary.orders).toBe(2);
|
|
250
|
+
expect(unfiltered.summary.sales).toBe(12000);
|
|
251
|
+
expect(unfiltered.reservations.reservations).toBe(1);
|
|
252
|
+
const filtered = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents, { filters: { platforms: ['POS_DINE-IN'] } });
|
|
253
|
+
expect(filtered.summary.orders).toBe(1);
|
|
254
|
+
expect(filtered.summary.sales).toBe(5000);
|
|
255
|
+
// the reservation block has no order key, so a key filter cannot drop it
|
|
256
|
+
expect(filtered.reservations.reservations).toBe(1);
|
|
257
|
+
expect(filtered.by_origin.map((row) => row.origin)).toEqual(['POS_DIRECT']);
|
|
258
|
+
});
|
|
259
|
+
it('flags a truncated table map instead of reporting a false distinct count', () => {
|
|
260
|
+
const documents = documentsFor([{ amount_earned: 1000 }]);
|
|
261
|
+
const report = documents[0];
|
|
262
|
+
const key = Object.keys(report.dinein_counters)[0];
|
|
263
|
+
report.dinein_counters[key].by_table.__OTHER__ = {
|
|
264
|
+
table_id: '__OTHER__',
|
|
265
|
+
table_name: 'Other tables',
|
|
266
|
+
floor_id: 'UNKNOWN',
|
|
267
|
+
orders: 10,
|
|
268
|
+
sessions: 10,
|
|
269
|
+
covers: 10,
|
|
270
|
+
occupancy_minutes: 100,
|
|
271
|
+
sales: 1000,
|
|
272
|
+
};
|
|
273
|
+
const { summary } = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)([report]);
|
|
274
|
+
expect(summary.tables_truncated).toBe(true);
|
|
275
|
+
// a LOWER BOUND: the overflow row is not a table
|
|
276
|
+
expect(summary.tables_served_distinct).toBe(1);
|
|
277
|
+
});
|
|
278
|
+
it('never throws for an empty or missing document set', () => {
|
|
279
|
+
const empty = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(null);
|
|
280
|
+
expect(empty.summary.orders).toBe(0);
|
|
281
|
+
expect(empty.summary.average_ticket).toBeNull();
|
|
282
|
+
expect(empty.summary.average_rating).toBeNull();
|
|
283
|
+
expect(empty.summary.average_occupancy_minutes).toBeNull();
|
|
284
|
+
expect(empty.summary.tables_served_distinct).toBe(0);
|
|
285
|
+
expect(empty.by_hour).toHaveLength(24);
|
|
286
|
+
expect(empty.reservations.reservations).toBe(0);
|
|
287
|
+
expect(empty.reservations.average_party_size).toBeNull();
|
|
288
|
+
expect(empty.by_origin).toEqual([]);
|
|
289
|
+
expect(empty.scopes).toEqual([]);
|
|
290
|
+
expect((0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(undefined).summary.orders).toBe(0);
|
|
291
|
+
});
|
|
292
|
+
it('reports tenant ids and the scope level the documents covered', () => {
|
|
293
|
+
const documents = documentsFor([{}]);
|
|
294
|
+
const formatted = (0, tenant_dinein_formatter_1.formatMaterializedDineinReport)(documents);
|
|
295
|
+
expect(formatted.tenant_ids).toEqual([dinein_fixtures_1.DINEIN_TENANT]);
|
|
296
|
+
// the day documents are formatted at their own scope level
|
|
297
|
+
expect(formatted.scopes).toEqual([{ scope_context: 'localDate', scope_field: dinein_fixtures_1.DINEIN_DAY }]);
|
|
298
|
+
});
|
|
299
|
+
});
|