@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,419 @@
|
|
|
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 dinein_fixtures_1 = require("./dinein-fixtures");
|
|
6
|
+
/**
|
|
7
|
+
* Dinein close-day plan — day write, period re-fold, page replacement, stale
|
|
8
|
+
* deletion, watermark guard and the deterministic overflow row.
|
|
9
|
+
*/
|
|
10
|
+
const dayOf = (day, amountEarned) => (0, dinein_fixtures_1.dineinOrder)({
|
|
11
|
+
_id: 'order-' + day,
|
|
12
|
+
localDate: day,
|
|
13
|
+
amount_earned: amountEarned,
|
|
14
|
+
// A later source edit is what advances the watermark; two identical
|
|
15
|
+
// watermarks must skip the rewrite (see the guard test).
|
|
16
|
+
updatedAt: day + 'T13:35:00.000Z',
|
|
17
|
+
});
|
|
18
|
+
const reportFor = (result, scope, field) => result.reports.find((doc) => String(doc.scope_context) === scope && doc.scope_field === field);
|
|
19
|
+
describe('dinein close-day plan', () => {
|
|
20
|
+
it('writes the day document plus one row per touched period', () => {
|
|
21
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 10000)] });
|
|
22
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
23
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
24
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
25
|
+
reports: result.reports,
|
|
26
|
+
entries: result.entries,
|
|
27
|
+
reason: 'NEW_DAY',
|
|
28
|
+
computedAt: new Date('2026-10-01T23:30:00.000Z'),
|
|
29
|
+
});
|
|
30
|
+
expect(plan).not.toBeNull();
|
|
31
|
+
const scopes = plan.writes.map((write) => String(write.report.scope_context)).sort();
|
|
32
|
+
expect(scopes).toEqual([...materialized_dinein_close_day_helpers_1.MATERIALIZED_DINEIN_PERIOD_SCOPES, MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE].sort());
|
|
33
|
+
// day + week + ISO week + month + quarter + semester + year
|
|
34
|
+
expect(plan.writes).toHaveLength(7);
|
|
35
|
+
expect(plan.entryWrites).toHaveLength(4);
|
|
36
|
+
expect(plan.writes.every((write) => write.iteration != null)).toBe(true);
|
|
37
|
+
expect(plan.writes.every((write) => write.report.iteration === 1)).toBe(true);
|
|
38
|
+
expect(plan.entryWrites.every((write) => write.iteration != null)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('re-folds a period from its whole day set (close -> read parity)', () => {
|
|
41
|
+
const dayOne = '2026-10-01';
|
|
42
|
+
const dayTwo = '2026-10-02';
|
|
43
|
+
const first = (0, dinein_fixtures_1.compileDay)({ localDate: dayOne, orders: [dayOf(dayOne, 10000)] });
|
|
44
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
45
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
46
|
+
localDate: dayOne,
|
|
47
|
+
reports: first.reports,
|
|
48
|
+
entries: first.entries,
|
|
49
|
+
reason: 'NEW_DAY',
|
|
50
|
+
});
|
|
51
|
+
const storedReports = firstPlan.writes.map((write) => write.report);
|
|
52
|
+
const second = (0, dinein_fixtures_1.compileDay)({ localDate: dayTwo, orders: [dayOf(dayTwo, 25000)] });
|
|
53
|
+
const secondPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
54
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
55
|
+
localDate: dayTwo,
|
|
56
|
+
reports: second.reports,
|
|
57
|
+
entries: second.entries,
|
|
58
|
+
existing: storedReports,
|
|
59
|
+
reason: 'NEW_DAY',
|
|
60
|
+
});
|
|
61
|
+
const month = secondPlan.writes.find((write) => write.report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH &&
|
|
62
|
+
write.report.scope_field === '2026-10');
|
|
63
|
+
const monthCounters = month.report.dinein_counters['COMPLETED:POS_DINE-IN'];
|
|
64
|
+
expect(monthCounters.orders).toBe(2);
|
|
65
|
+
expect(monthCounters.sales).toBe(35000);
|
|
66
|
+
// the day documents are the source of the fold
|
|
67
|
+
expect(monthCounters.by_hour['18'].sales).toBe(35000);
|
|
68
|
+
});
|
|
69
|
+
it('re-folds reservation counters at the period level', () => {
|
|
70
|
+
const dayOne = '2026-10-01';
|
|
71
|
+
const dayTwo = '2026-10-02';
|
|
72
|
+
const first = (0, dinein_fixtures_1.compileDay)({ localDate: dayOne, orders: [], reservations: [(0, dinein_fixtures_1.dineinReservation)()] });
|
|
73
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
74
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
75
|
+
localDate: dayOne,
|
|
76
|
+
reports: first.reports,
|
|
77
|
+
entries: first.entries,
|
|
78
|
+
reason: 'NEW_DAY',
|
|
79
|
+
});
|
|
80
|
+
const second = (0, dinein_fixtures_1.compileDay)({
|
|
81
|
+
localDate: dayTwo,
|
|
82
|
+
orders: [],
|
|
83
|
+
reservations: [
|
|
84
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
85
|
+
reservation_time: '2026-10-02T19:00:00.000Z',
|
|
86
|
+
source_local_date: dayTwo,
|
|
87
|
+
updatedAt: '2026-10-02T09:00:00.000Z',
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
92
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
93
|
+
localDate: dayTwo,
|
|
94
|
+
reports: second.reports,
|
|
95
|
+
entries: second.entries,
|
|
96
|
+
existing: firstPlan.writes.map((write) => write.report),
|
|
97
|
+
reason: 'NEW_DAY',
|
|
98
|
+
});
|
|
99
|
+
const month = plan.writes.find((write) => write.report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH &&
|
|
100
|
+
write.report.scope_field === '2026-10');
|
|
101
|
+
expect(month.report.reservation_counters.reservations).toBe(2);
|
|
102
|
+
expect(month.report.reservation_counters.reservation_confirmed).toBe(2);
|
|
103
|
+
expect(month.report.dinein_counters).toEqual({});
|
|
104
|
+
});
|
|
105
|
+
it('deletes the day documents and pages an emptied day used to own', () => {
|
|
106
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 10000)] });
|
|
107
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
108
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
109
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
110
|
+
reports: result.reports,
|
|
111
|
+
entries: result.entries,
|
|
112
|
+
reason: 'NEW_DAY',
|
|
113
|
+
});
|
|
114
|
+
const storedReports = firstPlan.writes.map((write) => write.report);
|
|
115
|
+
const storedEntries = firstPlan.entryWrites.map((write) => write.report);
|
|
116
|
+
const emptied = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
117
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
118
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
119
|
+
reports: [],
|
|
120
|
+
entries: [],
|
|
121
|
+
existing: storedReports,
|
|
122
|
+
existingEntries: storedEntries,
|
|
123
|
+
reason: 'RECLOSE',
|
|
124
|
+
force: true,
|
|
125
|
+
});
|
|
126
|
+
// the day document is stale; the periods it was alone in are deleted too
|
|
127
|
+
expect(emptied.staleDocuments.some((doc) => String(doc.scope_context) === 'localDate')).toBe(true);
|
|
128
|
+
expect(emptied.staleEntryDocuments).toHaveLength(4);
|
|
129
|
+
expect(emptied.writes).toHaveLength(0);
|
|
130
|
+
});
|
|
131
|
+
it('skips an unchanged document unless the plan is forced', () => {
|
|
132
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 10000)] });
|
|
133
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
134
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
135
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
136
|
+
reports: result.reports,
|
|
137
|
+
entries: result.entries,
|
|
138
|
+
reason: 'NEW_DAY',
|
|
139
|
+
computedAt: new Date('2026-10-01T23:30:00.000Z'),
|
|
140
|
+
});
|
|
141
|
+
const storedReports = firstPlan.writes.map((write) => write.report);
|
|
142
|
+
const storedEntries = firstPlan.entryWrites.map((write) => write.report);
|
|
143
|
+
const unchanged = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
144
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
145
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
146
|
+
reports: result.reports,
|
|
147
|
+
entries: result.entries,
|
|
148
|
+
existing: storedReports,
|
|
149
|
+
existingEntries: storedEntries,
|
|
150
|
+
reason: 'RECLOSE',
|
|
151
|
+
computedAt: new Date('2026-10-01T23:45:00.000Z'),
|
|
152
|
+
});
|
|
153
|
+
// Same watermark: the day + period counters are skipped, not rewritten.
|
|
154
|
+
expect(unchanged.writes).toHaveLength(0);
|
|
155
|
+
expect(unchanged.skippedDocuments.length).toBeGreaterThan(0);
|
|
156
|
+
const forced = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
157
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
158
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
159
|
+
reports: result.reports,
|
|
160
|
+
entries: result.entries,
|
|
161
|
+
existing: storedReports,
|
|
162
|
+
existingEntries: storedEntries,
|
|
163
|
+
reason: 'RECLOSE',
|
|
164
|
+
force: true,
|
|
165
|
+
});
|
|
166
|
+
expect(forced.writes.length).toBe(7);
|
|
167
|
+
expect(forced.entryWrites).toHaveLength(4);
|
|
168
|
+
});
|
|
169
|
+
it('keeps the period documents out of the day scope and stamps the right scope fields', () => {
|
|
170
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 10000)] });
|
|
171
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
172
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
173
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
174
|
+
reports: result.reports,
|
|
175
|
+
entries: result.entries,
|
|
176
|
+
reason: 'NEW_DAY',
|
|
177
|
+
});
|
|
178
|
+
for (const write of plan.writes) {
|
|
179
|
+
if (String(write.report.scope_context) === 'localDate') {
|
|
180
|
+
expect(write.report.day_index).toBe('THU');
|
|
181
|
+
expect(write.report.scope_field).toBe(dinein_fixtures_1.DINEIN_DAY);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
expect(write.report.day_index).toBeNull();
|
|
185
|
+
}
|
|
186
|
+
expect(write.report.sale_type_key_filters).toEqual(['ORDER_STATUS', 'PLATFORM']);
|
|
187
|
+
}
|
|
188
|
+
expect(plan.writes.every((write) => write.report.schema_version === 1)).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
it('re-bounds a folded period map with a deterministic overflow row', () => {
|
|
191
|
+
const orders = [];
|
|
192
|
+
for (let index = 0; index < 260; index += 1) {
|
|
193
|
+
orders.push((0, dinein_fixtures_1.dineinOrder)({
|
|
194
|
+
_id: 't-' + String(index).padStart(4, '0'),
|
|
195
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
196
|
+
dinein_details: {
|
|
197
|
+
table_id: 't-' + String(index).padStart(4, '0'),
|
|
198
|
+
table_name: 'T-' + String(index),
|
|
199
|
+
floor_id: 'floor-main',
|
|
200
|
+
start_time: '2026-10-01T13:00:00.000Z',
|
|
201
|
+
courses: null,
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
const compiled = (0, dinein_fixtures_1.compileDay)({ orders });
|
|
206
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
207
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
208
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
209
|
+
reports: compiled.reports,
|
|
210
|
+
entries: compiled.entries,
|
|
211
|
+
reason: 'NEW_DAY',
|
|
212
|
+
});
|
|
213
|
+
const day = plan.writes.find((write) => String(write.report.scope_context) === 'localDate');
|
|
214
|
+
const counters = day.report.dinein_counters['COMPLETED:POS_DINE-IN'];
|
|
215
|
+
expect(Object.keys(counters.by_table).length).toBeLessThanOrEqual(201);
|
|
216
|
+
expect(counters.by_table.__OTHER__).toBeDefined();
|
|
217
|
+
expect(counters.orders).toBe(260);
|
|
218
|
+
// deterministic across two plan builds of the same input
|
|
219
|
+
const again = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
220
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
221
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
222
|
+
reports: compiled.reports,
|
|
223
|
+
entries: compiled.entries,
|
|
224
|
+
reason: 'NEW_DAY',
|
|
225
|
+
});
|
|
226
|
+
const againDay = again.writes.find((write) => String(write.report.scope_context) === 'localDate');
|
|
227
|
+
expect(JSON.stringify(againDay.report.dinein_counters)).toBe(JSON.stringify(day.report.dinein_counters));
|
|
228
|
+
});
|
|
229
|
+
it('merges the bounded snapshots across the period day documents', () => {
|
|
230
|
+
const reservations = [];
|
|
231
|
+
for (let index = 0; index < 8; index += 1) {
|
|
232
|
+
reservations.push((0, dinein_fixtures_1.dineinReservation)({
|
|
233
|
+
_id: 'day1-r-' + index,
|
|
234
|
+
reservation_time: new Date(`2026-10-01T${String(10 + index).padStart(2, '0')}:00:00.000Z`),
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
const dayOne = (0, dinein_fixtures_1.compileDay)({
|
|
238
|
+
localDate: '2026-10-01',
|
|
239
|
+
orders: [
|
|
240
|
+
(0, dinein_fixtures_1.dineinOrder)({
|
|
241
|
+
_id: 'day1-edit',
|
|
242
|
+
localDate: '2026-10-01',
|
|
243
|
+
iterations: [
|
|
244
|
+
{ categories: [{ items: [{ _id: 'l', quantity: 1 }] }] },
|
|
245
|
+
{ categories: [{ items: [{ _id: 'l', quantity: 1 }] }] },
|
|
246
|
+
{ categories: [{ items: [{ _id: 'l', quantity: 1 }] }] },
|
|
247
|
+
],
|
|
248
|
+
categories: [{ items: [{ _id: 'l', quantity: 2 }] }],
|
|
249
|
+
}),
|
|
250
|
+
],
|
|
251
|
+
reservations,
|
|
252
|
+
});
|
|
253
|
+
const dayTwo = '2026-10-02';
|
|
254
|
+
const second = (0, dinein_fixtures_1.compileDay)({
|
|
255
|
+
localDate: dayTwo,
|
|
256
|
+
orders: [
|
|
257
|
+
(0, dinein_fixtures_1.dineinOrder)({
|
|
258
|
+
_id: 'day2-edit',
|
|
259
|
+
localDate: dayTwo,
|
|
260
|
+
updatedAt: dayTwo + 'T13:35:00.000Z',
|
|
261
|
+
iterations: [{ categories: [{ items: [{ _id: 'l', quantity: 1 }] }] }],
|
|
262
|
+
categories: [{ items: [{ _id: 'l', quantity: 3 }] }],
|
|
263
|
+
}),
|
|
264
|
+
],
|
|
265
|
+
reservations: [
|
|
266
|
+
(0, dinein_fixtures_1.dineinReservation)({
|
|
267
|
+
_id: 'day2-r',
|
|
268
|
+
reservation_time: new Date('2026-10-02T09:00:00.000Z'),
|
|
269
|
+
updatedAt: dayTwo + 'T08:00:00.000Z',
|
|
270
|
+
source_local_date: dayTwo,
|
|
271
|
+
}),
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
275
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
276
|
+
localDate: '2026-10-01',
|
|
277
|
+
reports: dayOne.reports,
|
|
278
|
+
entries: dayOne.entries,
|
|
279
|
+
reason: 'NEW_DAY',
|
|
280
|
+
});
|
|
281
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
282
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
283
|
+
localDate: dayTwo,
|
|
284
|
+
reports: second.reports,
|
|
285
|
+
entries: second.entries,
|
|
286
|
+
existing: firstPlan.writes.map((write) => write.report),
|
|
287
|
+
reason: 'NEW_DAY',
|
|
288
|
+
});
|
|
289
|
+
const month = plan.writes.find((write) => write.report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH &&
|
|
290
|
+
write.report.scope_field === '2026-10');
|
|
291
|
+
// Bounded to the top 10 and deduped across both days.
|
|
292
|
+
expect(month.report.upcoming_reservations).toHaveLength(9);
|
|
293
|
+
expect(new Set(month.report.upcoming_reservations.map((row) => row.reservation_id)).size).toBe(9);
|
|
294
|
+
// Soonest first across the whole period.
|
|
295
|
+
expect(month.report.upcoming_reservations[0].reservation_time).toBe('2026-10-01T10:00:00.000Z');
|
|
296
|
+
// Ranked by edits across days: day 1 has 3 edits, day 2 has 1.
|
|
297
|
+
expect(month.report.top_edited_checks.map((row) => row.order_id)).toEqual(['day1-edit', 'day2-edit']);
|
|
298
|
+
expect(month.report.top_edited_checks[0].edits).toBe(3);
|
|
299
|
+
// Reservation hours fold additively into the period block.
|
|
300
|
+
expect(month.report.reservation_counters.reservations).toBe(9);
|
|
301
|
+
expect(month.report.reservation_counters.by_hour['10']).toEqual({
|
|
302
|
+
reservations: 1,
|
|
303
|
+
reservation_covers: 4,
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
it('exposes exactly the period day scope fields a fold needs', () => {
|
|
307
|
+
const days = (0, materialized_dinein_close_day_helpers_1.getMaterializedDineinReportPeriodDayScopeFields)(dinein_fixtures_1.DINEIN_DAY);
|
|
308
|
+
expect(days).not.toBeNull();
|
|
309
|
+
expect(days).toContain(dinein_fixtures_1.DINEIN_DAY);
|
|
310
|
+
expect(days.length).toBeGreaterThanOrEqual(365);
|
|
311
|
+
expect((0, materialized_dinein_close_day_helpers_1.getMaterializedDineinReportPeriodDayScopeFields)('2026-13-01')).toBeNull();
|
|
312
|
+
});
|
|
313
|
+
it('returns null for invalid input and for a legacy page without identity', () => {
|
|
314
|
+
expect((0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)(null)).toBeNull();
|
|
315
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 10000)] });
|
|
316
|
+
expect((0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
317
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
318
|
+
reports: result.reports,
|
|
319
|
+
entries: [],
|
|
320
|
+
reason: 'NEW_DAY',
|
|
321
|
+
existingEntries: [{ ...result.entries[0], page: '' }],
|
|
322
|
+
})).toBeNull();
|
|
323
|
+
});
|
|
324
|
+
it('folds the reservation block additively without touching the keyed counters', () => {
|
|
325
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
326
|
+
orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 5000)],
|
|
327
|
+
reservations: [(0, dinein_fixtures_1.dineinReservation)()],
|
|
328
|
+
});
|
|
329
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
330
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
331
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
332
|
+
reports: result.reports,
|
|
333
|
+
entries: result.entries,
|
|
334
|
+
reason: 'NEW_DAY',
|
|
335
|
+
});
|
|
336
|
+
const quarter = plan.writes.find((write) => String(write.report.scope_context) === 'localQuarter');
|
|
337
|
+
expect(quarter.report.reservation_counters.reservations).toBe(1);
|
|
338
|
+
expect(quarter.report.dinein_counters['COMPLETED:POS_DINE-IN'].sales).toBe(5000);
|
|
339
|
+
});
|
|
340
|
+
it('does not fabricate a session for a check with no fingerprint at plan time', () => {
|
|
341
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 5000)] });
|
|
342
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
343
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
344
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
345
|
+
reports: result.reports,
|
|
346
|
+
entries: result.entries,
|
|
347
|
+
reason: 'NEW_DAY',
|
|
348
|
+
});
|
|
349
|
+
const day = plan.writes.find((write) => String(write.report.scope_context) === 'localDate');
|
|
350
|
+
const counters = day.report.dinein_counters['COMPLETED:POS_DINE-IN'];
|
|
351
|
+
expect(counters.table_sessions).toBe(0);
|
|
352
|
+
expect(counters.covers).toBe(0);
|
|
353
|
+
expect(counters.occupancy_minutes_sum).toBe(0);
|
|
354
|
+
});
|
|
355
|
+
it('attributes a late fingerprint to the order day, not to the close day', () => {
|
|
356
|
+
const lateOrder = (0, dinein_fixtures_1.dineinOrder)({
|
|
357
|
+
_id: 'late',
|
|
358
|
+
createdAt: '2026-10-01T22:00:00.000Z',
|
|
359
|
+
dinein_details: {
|
|
360
|
+
table_id: 'table-t04',
|
|
361
|
+
table_name: 'T-04',
|
|
362
|
+
floor_id: 'floor-main',
|
|
363
|
+
start_time: '2026-10-01T22:00:00.000Z',
|
|
364
|
+
courses: null,
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
const result = (0, dinein_fixtures_1.compileDay)({
|
|
368
|
+
orders: [lateOrder],
|
|
369
|
+
// the table closed after midnight
|
|
370
|
+
fingerprints: [(0, dinein_fixtures_1.dineinFingerprint)('late', { createdAt: '2026-10-02T00:30:00.000Z' })],
|
|
371
|
+
});
|
|
372
|
+
const counters = result.reports[0].dinein_counters['COMPLETED:POS_DINE-IN'];
|
|
373
|
+
expect(counters.table_sessions).toBe(1);
|
|
374
|
+
expect(counters.occupancy_minutes_sum).toBe(150);
|
|
375
|
+
expect(result.reports[0].scope_field).toBe(dinein_fixtures_1.DINEIN_DAY);
|
|
376
|
+
});
|
|
377
|
+
it('reports a period document only when it still has a day or a reservation', () => {
|
|
378
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 5000)] });
|
|
379
|
+
const firstPlan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
380
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
381
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
382
|
+
reports: result.reports,
|
|
383
|
+
entries: result.entries,
|
|
384
|
+
reason: 'NEW_DAY',
|
|
385
|
+
});
|
|
386
|
+
// Only the day document + pages are fetched as "existing" here, so every
|
|
387
|
+
// period the day touches is (re)created from that single day.
|
|
388
|
+
const stored = firstPlan.writes.filter((write) => String(write.report.scope_context) === 'localDate');
|
|
389
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
390
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
391
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
392
|
+
reports: result.reports,
|
|
393
|
+
entries: result.entries,
|
|
394
|
+
existing: stored.map((write) => write.report),
|
|
395
|
+
reason: 'NEW_DAY',
|
|
396
|
+
force: true,
|
|
397
|
+
});
|
|
398
|
+
const year = plan.writes.find((write) => String(write.report.scope_context) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR);
|
|
399
|
+
expect(year.report.scope_field).toBe('2026');
|
|
400
|
+
expect(year.report.dinein_counters['COMPLETED:POS_DINE-IN'].orders).toBe(1);
|
|
401
|
+
});
|
|
402
|
+
it('keeps a period document invisible to the schema gate with the declared key filters', () => {
|
|
403
|
+
const result = (0, dinein_fixtures_1.compileDay)({ orders: [dayOf(dinein_fixtures_1.DINEIN_DAY, 5000)] });
|
|
404
|
+
const plan = (0, materialized_dinein_close_day_helpers_1.buildTenantDineinCloseDayPlan)({
|
|
405
|
+
tenantId: dinein_fixtures_1.DINEIN_TENANT,
|
|
406
|
+
localDate: dinein_fixtures_1.DINEIN_DAY,
|
|
407
|
+
reports: result.reports,
|
|
408
|
+
entries: result.entries,
|
|
409
|
+
reason: 'NEW_DAY',
|
|
410
|
+
});
|
|
411
|
+
for (const write of plan.writes) {
|
|
412
|
+
expect(write.report.sale_type_key_filters).toEqual(['ORDER_STATUS', 'PLATFORM']);
|
|
413
|
+
expect(write.report.tenant_id).toBe(dinein_fixtures_1.DINEIN_TENANT);
|
|
414
|
+
expect(write.report.source_watermark).toBeInstanceOf(Date);
|
|
415
|
+
}
|
|
416
|
+
expect(reportFor(result, 'localDate', dinein_fixtures_1.DINEIN_DAY)).toBeDefined();
|
|
417
|
+
expect(plan.entryWrites.every((write) => write.report.dinein_entries != null)).toBe(true);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_report_drilldown_rows_1 = require("../../schemas/models/materialized_report_drilldown_rows");
|
|
5
|
+
const materialized_tenant_dinein_entries_1 = require("../../schemas/models/materialized_tenant_dinein_entries");
|
|
6
|
+
const materialized_tenant_dinein_reports_1 = require("../../schemas/models/materialized_tenant_dinein_reports");
|
|
7
|
+
const materialized_day_readiness_1 = require("../../helpers/materialized-reports/materialized-day-readiness");
|
|
8
|
+
const materialized_index_bootstrap_1 = require("../../helpers/materialized-reports/materialized-index-bootstrap");
|
|
9
|
+
const materialized_report_drilldown_rows_2 = require("../../helpers/materialized-reports/materialized-report-drilldown-rows");
|
|
10
|
+
const registry_1 = require("../../helpers/materialized-reports/report-platform/registry");
|
|
11
|
+
const validate_report_registry_1 = require("../../helpers/materialized-reports/report-platform/validate-report-registry");
|
|
12
|
+
const report_contract_1 = require("../../helpers/reporting-contract/report-contract");
|
|
13
|
+
/**
|
|
14
|
+
* The Dinein CONTRACT: report key, route segment, capabilities, collections,
|
|
15
|
+
* indexes, scopes, budgets, readiness key and the flat drill-down projection.
|
|
16
|
+
*/
|
|
17
|
+
describe('dinein contract', () => {
|
|
18
|
+
it('registers the report key, route segment and capabilities', () => {
|
|
19
|
+
expect(report_contract_1.REPORT_KEY_ENUM.DINEIN).toBe('DINEIN');
|
|
20
|
+
expect(report_contract_1.REPORT_ROUTE_SEGMENTS[report_contract_1.REPORT_KEY_ENUM.DINEIN]).toBe('dinein');
|
|
21
|
+
expect(report_contract_1.REPORT_CAPABILITIES[report_contract_1.REPORT_KEY_ENUM.DINEIN]).toEqual({
|
|
22
|
+
live: true,
|
|
23
|
+
historical: true,
|
|
24
|
+
details: true,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('publishes a production definition with the frozen adapters and scopes', () => {
|
|
28
|
+
const definition = (0, registry_1.getReportDefinition)(report_contract_1.REPORT_KEY_ENUM.DINEIN);
|
|
29
|
+
expect(definition).not.toBeNull();
|
|
30
|
+
expect(definition.segment).toBe('dinein');
|
|
31
|
+
expect(definition.status).toBe('PRODUCTION');
|
|
32
|
+
expect(definition.reportType).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_REPORTS);
|
|
33
|
+
expect(definition.report.name).toBe('materialized_tenant_dinein_reports');
|
|
34
|
+
expect(definition.report.schemaVersion).toBe(materialized_tenant_dinein_reports_1.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION);
|
|
35
|
+
expect(definition.entries.name).toBe('materialized_tenant_dinein_entries');
|
|
36
|
+
expect(definition.entries.schemaVersion).toBe(materialized_tenant_dinein_entries_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION);
|
|
37
|
+
expect(definition.reportScopes).toEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES);
|
|
38
|
+
expect(definition.entryScopes).toEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES);
|
|
39
|
+
expect(definition.maxEntryScope).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH);
|
|
40
|
+
expect(definition.adapters).toEqual({
|
|
41
|
+
writer: 'materializeDineinReport',
|
|
42
|
+
live: 'getLiveTenantDineinReports',
|
|
43
|
+
historical: 'getMaterializedTenantDineinReports',
|
|
44
|
+
details: 'getMaterializedDineinDetailsPage',
|
|
45
|
+
});
|
|
46
|
+
expect(definition.filters).toEqual(expect.arrayContaining([
|
|
47
|
+
expect.objectContaining({ id: 'ORDER_STATUS', appliesTo: 'BOTH' }),
|
|
48
|
+
expect.objectContaining({ id: 'PLATFORM', appliesTo: 'BOTH' }),
|
|
49
|
+
expect.objectContaining({ id: 'origins', appliesTo: 'DETAILS' }),
|
|
50
|
+
expect.objectContaining({ id: 'table_ids', appliesTo: 'DETAILS' }),
|
|
51
|
+
expect.objectContaining({ id: 'floor_ids', appliesTo: 'DETAILS' }),
|
|
52
|
+
expect.objectContaining({ id: 'split_types', appliesTo: 'DETAILS' }),
|
|
53
|
+
expect.objectContaining({ id: 'offline', appliesTo: 'DETAILS' }),
|
|
54
|
+
]));
|
|
55
|
+
expect((0, validate_report_registry_1.validateReportRegistry)().errors).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
it('declares the two collections and their unique page identities', () => {
|
|
58
|
+
expect(materialized_tenant_dinein_reports_1.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME).toBe('materialized_tenant_dinein_reports');
|
|
59
|
+
expect(materialized_tenant_dinein_entries_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME).toBe('materialized_tenant_dinein_entries');
|
|
60
|
+
expect(materialized_tenant_dinein_reports_1.MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS).toEqual([
|
|
61
|
+
{
|
|
62
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
|
|
63
|
+
name: 'tenant_id__scope_context__scope_field__day_index',
|
|
64
|
+
unique: true,
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
expect(materialized_tenant_dinein_entries_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS).toEqual([
|
|
68
|
+
{
|
|
69
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, page: 1 },
|
|
70
|
+
name: 'tenant_id__scope_context__scope_field__page',
|
|
71
|
+
unique: true,
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
// The single DAY page key: the day scope needs no per-day partition.
|
|
75
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_PAGE_ALL).toBe('all');
|
|
76
|
+
});
|
|
77
|
+
it('declares both collections in the (manual) index bootstrap', () => {
|
|
78
|
+
expect(materialized_index_bootstrap_1.MATERIALIZED_REPORT_INDEX_COLLECTIONS).toContain('materialized_tenant_dinein_reports');
|
|
79
|
+
expect(materialized_index_bootstrap_1.MATERIALIZED_REPORT_INDEX_COLLECTIONS).toContain('materialized_tenant_dinein_entries');
|
|
80
|
+
});
|
|
81
|
+
it('declares the 15 MiB budgets and the seven report / four entry scopes', () => {
|
|
82
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
|
|
83
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
|
|
84
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES).toEqual([
|
|
85
|
+
'localDate',
|
|
86
|
+
'localWeek',
|
|
87
|
+
'localWeekOfYear',
|
|
88
|
+
'localMonth',
|
|
89
|
+
'localQuarter',
|
|
90
|
+
'localSemester',
|
|
91
|
+
'localYear',
|
|
92
|
+
]);
|
|
93
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES).toEqual(['localDate', 'localWeek', 'localWeekOfYear', 'localMonth']);
|
|
94
|
+
// no hour scope: the hour dimension is an in-document map
|
|
95
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES).not.toContain(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR);
|
|
96
|
+
});
|
|
97
|
+
it('declares the 24 hour keys and the frozen split-parent reason', () => {
|
|
98
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS).toHaveLength(24);
|
|
99
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS[0]).toBe('0');
|
|
100
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS[23]).toBe('23');
|
|
101
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_SPLIT_PARENT_DELETE_REASON).toBe('Auto Deleted on Split');
|
|
102
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_UNKNOWN_TOKEN).toBe('UNKNOWN');
|
|
103
|
+
});
|
|
104
|
+
it('adds DINEIN to the readiness contract (COMMITTED / NEEDS_RECONCILIATION only)', () => {
|
|
105
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_READINESS_REPORT_KEYS).toContain('DINEIN');
|
|
106
|
+
expect((0, materialized_day_readiness_1.isMaterializedReadinessReportKey)('DINEIN')).toBe(true);
|
|
107
|
+
expect(Object.values(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_READINESS_STATUS_ENUM).sort()).toEqual([
|
|
108
|
+
'COMMITTED',
|
|
109
|
+
'NEEDS_RECONCILIATION',
|
|
110
|
+
]);
|
|
111
|
+
const document = (0, materialized_day_readiness_1.buildMaterializedDayReadinessDocument)({
|
|
112
|
+
tenantId: 'tenant-1',
|
|
113
|
+
localDate: '2026-10-01',
|
|
114
|
+
reportKey: 'DINEIN',
|
|
115
|
+
status: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_READINESS_STATUS_ENUM.COMMITTED,
|
|
116
|
+
runId: 'run-1',
|
|
117
|
+
committedAt: new Date('2026-10-01T23:00:00.000Z'),
|
|
118
|
+
});
|
|
119
|
+
expect(document.report_key).toBe('DINEIN');
|
|
120
|
+
expect(document.schema_version).toBe(1);
|
|
121
|
+
});
|
|
122
|
+
it('projects a dinein entry page into flat drill-down rows with the {time, order_id} identity', () => {
|
|
123
|
+
const entry = {
|
|
124
|
+
tenant_id: 'tenant-1',
|
|
125
|
+
brand_id: 'brand-1',
|
|
126
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
127
|
+
scope_field: '2026-10-01',
|
|
128
|
+
day_index: 'THU',
|
|
129
|
+
computed_at: new Date('2026-10-01T23:00:00.000Z'),
|
|
130
|
+
dinein_entries: {
|
|
131
|
+
'COMPLETED:POS_DINE-IN': {
|
|
132
|
+
rows: [
|
|
133
|
+
{
|
|
134
|
+
order_id: 'order-1',
|
|
135
|
+
order_number: 2418,
|
|
136
|
+
localDate: '2026-10-01',
|
|
137
|
+
time: '2026-10-01T13:00:00.000Z',
|
|
138
|
+
table_id: 'table-t04',
|
|
139
|
+
table_name: 'T-04',
|
|
140
|
+
floor_id: 'floor-main',
|
|
141
|
+
covers: 4,
|
|
142
|
+
status: 'COMPLETED',
|
|
143
|
+
platform: 'POS_DINE-IN',
|
|
144
|
+
origin: 'POS_DIRECT',
|
|
145
|
+
split_type: null,
|
|
146
|
+
split_role: 'NONE',
|
|
147
|
+
offline: false,
|
|
148
|
+
rating: 5,
|
|
149
|
+
sales: 21400,
|
|
150
|
+
service_charge: 1240,
|
|
151
|
+
items: 3,
|
|
152
|
+
edits: 0,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const projected = (0, materialized_report_drilldown_rows_2.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES, entry, '2026-10-01');
|
|
159
|
+
expect(projected.skipped).toBe(0);
|
|
160
|
+
expect(projected.rows).toHaveLength(1);
|
|
161
|
+
expect(projected.rows[0]).toMatchObject({
|
|
162
|
+
tenant_id: 'tenant-1',
|
|
163
|
+
report_type: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES,
|
|
164
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
165
|
+
scope_field: '2026-10-01',
|
|
166
|
+
key: 'COMPLETED:POS_DINE-IN',
|
|
167
|
+
order_id: 'order-1',
|
|
168
|
+
cursor_id: 'order-1',
|
|
169
|
+
source_local_date: '2026-10-01',
|
|
170
|
+
schema_version: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
171
|
+
});
|
|
172
|
+
expect(projected.rows[0].time).toEqual(new Date('2026-10-01T13:00:00.000Z'));
|
|
173
|
+
expect(projected.rows[0].data.rating).toBe(5);
|
|
174
|
+
});
|
|
175
|
+
it('skips an entry row without a usable time instead of inventing one', () => {
|
|
176
|
+
const projected = (0, materialized_report_drilldown_rows_2.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES, {
|
|
177
|
+
tenant_id: 'tenant-1',
|
|
178
|
+
scope_context: 'localDate',
|
|
179
|
+
scope_field: '2026-10-01',
|
|
180
|
+
dinein_entries: { 'COMPLETED:POS_DINE-IN': { rows: [{ order_id: 'order-1', time: null }] } },
|
|
181
|
+
}, '2026-10-01');
|
|
182
|
+
expect(projected.rows).toHaveLength(0);
|
|
183
|
+
expect(projected.skipped).toBe(1);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -51,6 +51,8 @@ const deliveryEntryModel = __importStar(require("../../../schemas/models/materia
|
|
|
51
51
|
const deliveryGeoModel = __importStar(require("../../../schemas/models/materialized_tenant_delivery_geo_cells"));
|
|
52
52
|
const dialerReportModel = __importStar(require("../../../schemas/models/materialized_tenant_dialer_reports"));
|
|
53
53
|
const dialerEntryModel = __importStar(require("../../../schemas/models/materialized_tenant_dialer_entries"));
|
|
54
|
+
const dineinReportModel = __importStar(require("../../../schemas/models/materialized_tenant_dinein_reports"));
|
|
55
|
+
const dineinEntryModel = __importStar(require("../../../schemas/models/materialized_tenant_dinein_entries"));
|
|
54
56
|
const flatModel = __importStar(require("../../../schemas/models/materialized_report_drilldown_rows"));
|
|
55
57
|
const definition_1 = require("../../../helpers/materialized-reports/report-platform/definition");
|
|
56
58
|
const registry_1 = require("../../../helpers/materialized-reports/report-platform/registry");
|
|
@@ -122,6 +124,16 @@ const MODEL_BY_COLLECTION = {
|
|
|
122
124
|
schemaVersion: dialerEntryModel.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION,
|
|
123
125
|
indexOptions: dialerEntryModel.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS,
|
|
124
126
|
},
|
|
127
|
+
materialized_tenant_dinein_reports: {
|
|
128
|
+
collectionName: dineinReportModel.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME,
|
|
129
|
+
schemaVersion: dineinReportModel.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION,
|
|
130
|
+
indexOptions: dineinReportModel.MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS,
|
|
131
|
+
},
|
|
132
|
+
materialized_tenant_dinein_entries: {
|
|
133
|
+
collectionName: dineinEntryModel.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME,
|
|
134
|
+
schemaVersion: dineinEntryModel.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION,
|
|
135
|
+
indexOptions: dineinEntryModel.MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS,
|
|
136
|
+
},
|
|
125
137
|
materialized_report_drilldown_rows: {
|
|
126
138
|
collectionName: flatModel.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME,
|
|
127
139
|
schemaVersion: flatModel.MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
@@ -146,9 +158,10 @@ describe('report registry conformance', () => {
|
|
|
146
158
|
report_contract_1.REPORT_KEY_ENUM.PREP_TIME,
|
|
147
159
|
report_contract_1.REPORT_KEY_ENUM.DELIVERY,
|
|
148
160
|
report_contract_1.REPORT_KEY_ENUM.DIALER,
|
|
161
|
+
report_contract_1.REPORT_KEY_ENUM.DINEIN,
|
|
149
162
|
]);
|
|
150
|
-
expect((0, registry_1.getProductionReportDefinitions)()).toHaveLength(
|
|
151
|
-
expect(new Set(definition_1.PRODUCTION_REPORT_DEFINITIONS.map((definition) => definition.key)).size).toBe(
|
|
163
|
+
expect((0, registry_1.getProductionReportDefinitions)()).toHaveLength(6);
|
|
164
|
+
expect(new Set(definition_1.PRODUCTION_REPORT_DEFINITIONS.map((definition) => definition.key)).size).toBe(6);
|
|
152
165
|
expect(definition_1.PRODUCTION_REPORT_DEFINITIONS.every((definition) => definition.status === 'PRODUCTION')).toBe(true);
|
|
153
166
|
});
|
|
154
167
|
it('covers every REPORT_KEY with a definition or an explicit exemption', () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|