@managesome/eposmatic-toolkit 0.4.34 → 0.4.36
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 +25 -5
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +30 -9
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +98 -44
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +7 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +35 -10
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +3 -1
- package/esm/schemas/models/materialized_tenant_prep_time_entries.js +3 -2
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +17 -5
- package/lib/constants/MATERIALIZED_REPORTS.js +27 -7
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +10 -2
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +30 -9
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +13 -6
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +99 -44
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +6 -2
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.d.ts +19 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +37 -10
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +3 -1
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +3 -0
- package/lib/schemas/models/materialized_tenant_prep_time_entries.js +2 -1
- package/lib/schemas/types/materialized_tenant_prep_time_entries.d.ts +3 -0
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +9 -2
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +20 -1
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +22 -3
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +17 -6
- package/lib/tests/materialized-reports/materialized-prep-time-identity.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-identity.test.js +163 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +38 -0
- package/lib/tests/materialized-reports/materialized-report-drilldown-rows.test.js +19 -2
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_prep_time_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-prep-time-compile-helpers");
|
|
5
|
+
const materialized_prep_time_read_helpers_1 = require("../../helpers/materialized-reports/materialized-prep-time-read-helpers");
|
|
6
|
+
const DAY = '2026-09-20';
|
|
7
|
+
const AT = new Date(`${DAY}T10:00:00.000Z`);
|
|
8
|
+
const order = (id, items) => ({
|
|
9
|
+
_id: id,
|
|
10
|
+
tenant_id: 'tenant-1',
|
|
11
|
+
order_number: 1,
|
|
12
|
+
order_status: 'COMPLETED',
|
|
13
|
+
platform: 'POS_WALK-IN',
|
|
14
|
+
localDate: DAY,
|
|
15
|
+
localHour: 10,
|
|
16
|
+
createdAt: AT,
|
|
17
|
+
updatedAt: AT,
|
|
18
|
+
categories: [{ name: 'Mains', items }],
|
|
19
|
+
});
|
|
20
|
+
const item = (lineId, catalogueId, minutes, prepStarted) => ({
|
|
21
|
+
_id: lineId,
|
|
22
|
+
item_id: catalogueId,
|
|
23
|
+
name: 'Burger',
|
|
24
|
+
is_ready: true,
|
|
25
|
+
ready_minutes: minutes,
|
|
26
|
+
prep_started_at: prepStarted ? AT : null,
|
|
27
|
+
});
|
|
28
|
+
const readRows = (orders) => {
|
|
29
|
+
const compiled = (0, materialized_prep_time_compile_helpers_1.compileTenantPrepTimeReports)({
|
|
30
|
+
tenantId: 'tenant-1',
|
|
31
|
+
brandId: 'brand-1',
|
|
32
|
+
localDate: DAY,
|
|
33
|
+
orders,
|
|
34
|
+
computedAt: new Date(`${DAY}T23:00:00.000Z`),
|
|
35
|
+
});
|
|
36
|
+
const dayEntry = compiled.entries.find((entry) => entry.scope_context === 'localDate');
|
|
37
|
+
const rows = [];
|
|
38
|
+
for (const section of Object.values(dayEntry.prep_time_entries ?? {})) {
|
|
39
|
+
for (const row of section.rows) {
|
|
40
|
+
rows.push({
|
|
41
|
+
tenant_id: 'tenant-1',
|
|
42
|
+
order_id: row.order_id,
|
|
43
|
+
item_id: row.item_id,
|
|
44
|
+
item_name: row.item_name,
|
|
45
|
+
category_name: row.category_name,
|
|
46
|
+
anchor: row.anchor,
|
|
47
|
+
duration_minutes: row.duration_minutes,
|
|
48
|
+
delta_minutes: row.delta_minutes,
|
|
49
|
+
order_status: row.order_status,
|
|
50
|
+
platform: row.platform,
|
|
51
|
+
created_at: row.created_at,
|
|
52
|
+
source_local_date: DAY,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { compiled, rows };
|
|
57
|
+
};
|
|
58
|
+
describe('prep time catalogue identity and coverage population', () => {
|
|
59
|
+
it('groups two order lines of one catalogue item into one Item, with distinct orders', () => {
|
|
60
|
+
const first = order('order-a', [
|
|
61
|
+
item('line-a', 'menu-burger', 5, true),
|
|
62
|
+
item('line-b', 'menu-burger', null, false),
|
|
63
|
+
]);
|
|
64
|
+
const second = order('order-b', [item('line-c', 'menu-burger', 7, true)]);
|
|
65
|
+
const { rows } = readRows([first, second]);
|
|
66
|
+
const page = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeItemsPage)({
|
|
67
|
+
rows,
|
|
68
|
+
filters: { anchor: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED },
|
|
69
|
+
sort: 'late_desc',
|
|
70
|
+
});
|
|
71
|
+
expect(page.rows).toHaveLength(1);
|
|
72
|
+
// Rows follow the LISTED anchor view (MEASURED), so this row's served
|
|
73
|
+
// population is the measured subset; coverage spans both anchors.
|
|
74
|
+
expect(page.rows[0]).toMatchObject({
|
|
75
|
+
item_id: 'menu-burger',
|
|
76
|
+
orders_count: 2,
|
|
77
|
+
served_count: 2,
|
|
78
|
+
measured_count: 2,
|
|
79
|
+
unmeasured_count: 0,
|
|
80
|
+
avg_minutes: 6,
|
|
81
|
+
});
|
|
82
|
+
expect(page.coverage).toEqual({
|
|
83
|
+
served_count: 3,
|
|
84
|
+
measured_count: 2,
|
|
85
|
+
unmeasured_count: 1,
|
|
86
|
+
coverage_percent: 66.7,
|
|
87
|
+
});
|
|
88
|
+
const unmeasured = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeItemsPage)({
|
|
89
|
+
rows,
|
|
90
|
+
filters: { anchor: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED },
|
|
91
|
+
sort: 'late_desc',
|
|
92
|
+
});
|
|
93
|
+
expect(unmeasured.rows).toHaveLength(1);
|
|
94
|
+
expect(unmeasured.rows[0]).toMatchObject({
|
|
95
|
+
item_id: 'menu-burger',
|
|
96
|
+
served_count: 1,
|
|
97
|
+
measured_count: 0,
|
|
98
|
+
unmeasured_count: 1,
|
|
99
|
+
avg_minutes: null,
|
|
100
|
+
on_time_percent: null,
|
|
101
|
+
});
|
|
102
|
+
// Measured + Unmeasured row populations add back to the coverage denominator.
|
|
103
|
+
expect(page.rows[0].served_count + unmeasured.rows[0].served_count).toBe(page.coverage.served_count);
|
|
104
|
+
});
|
|
105
|
+
it('keeps all three events distinct for the item drill-down and uses the catalogue item_id', () => {
|
|
106
|
+
const first = order('order-a', [
|
|
107
|
+
item('line-a', 'menu-burger', 5, true),
|
|
108
|
+
item('line-b', 'menu-burger', null, false),
|
|
109
|
+
]);
|
|
110
|
+
const second = order('order-b', [item('line-c', 'menu-burger', 7, true)]);
|
|
111
|
+
const { compiled } = readRows([first, second]);
|
|
112
|
+
const dayEntry = compiled.entries.find((entry) => entry.scope_context === 'localDate');
|
|
113
|
+
const events = Object.values(dayEntry.prep_time_entries ?? {}).flatMap((section) => section.rows);
|
|
114
|
+
expect(events.map((event) => event.item_id)).toEqual([
|
|
115
|
+
'menu-burger',
|
|
116
|
+
'menu-burger',
|
|
117
|
+
'menu-burger',
|
|
118
|
+
]);
|
|
119
|
+
expect(events.map((event) => event.order_id)).toEqual([
|
|
120
|
+
'order-a',
|
|
121
|
+
'order-a',
|
|
122
|
+
'order-b',
|
|
123
|
+
]);
|
|
124
|
+
expect(new Set(events.map((event) => event.entry_key)).size).toBe(3);
|
|
125
|
+
expect(events.map((event) => event.line_id)).toEqual(['line-a', 'line-b', 'line-c']);
|
|
126
|
+
});
|
|
127
|
+
it('makes Items, Categories and Series coverage agree on a no-signal population', () => {
|
|
128
|
+
const mixed = order('order-a', [
|
|
129
|
+
item('line-a', 'menu-burger', 5, true),
|
|
130
|
+
item('line-b', 'menu-fries', null, false),
|
|
131
|
+
item('line-c', 'menu-cola', null, false),
|
|
132
|
+
]);
|
|
133
|
+
const { compiled, rows } = readRows([mixed]);
|
|
134
|
+
const dayReport = compiled.reports.find((report) => report.scope_context === 'localDate');
|
|
135
|
+
const counters = dayReport.prep_time_counters['COMPLETED:POS_WALK-IN'];
|
|
136
|
+
expect(counters.coverage).toMatchObject({ item_count: 3, own_anchor_count: 1 });
|
|
137
|
+
const items = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeItemsPage)({
|
|
138
|
+
rows,
|
|
139
|
+
filters: { anchor: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED },
|
|
140
|
+
sort: 'late_desc',
|
|
141
|
+
});
|
|
142
|
+
const categories = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeCategoriesResult)({ rows });
|
|
143
|
+
const series = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeSeriesResult)({ rows });
|
|
144
|
+
const expected = {
|
|
145
|
+
served_count: 3,
|
|
146
|
+
measured_count: 1,
|
|
147
|
+
unmeasured_count: 2,
|
|
148
|
+
coverage_percent: 33.3,
|
|
149
|
+
};
|
|
150
|
+
expect(items.coverage).toEqual(expected);
|
|
151
|
+
expect(categories.coverage).toEqual(expected);
|
|
152
|
+
expect(series.coverage).toEqual(expected);
|
|
153
|
+
expect(items.rows).toHaveLength(1);
|
|
154
|
+
expect(items.rows[0]).toMatchObject({ served_count: 1, measured_count: 1 });
|
|
155
|
+
const unmeasured = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeItemsPage)({
|
|
156
|
+
rows,
|
|
157
|
+
filters: { anchor: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED },
|
|
158
|
+
sort: 'late_desc',
|
|
159
|
+
});
|
|
160
|
+
expect(unmeasured.rows).toHaveLength(2);
|
|
161
|
+
expect(unmeasured.rows.reduce((total, row) => total + row.served_count, 0)).toBe(2);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -76,13 +76,30 @@ describe('buildTenantPrepTimeCloseDayPlan', () => {
|
|
|
76
76
|
const periodWrites = plan.writes.filter((write) => write.report.scope_context !== 'localDate');
|
|
77
77
|
expect(periodWrites.map((write) => write.report.scope_context).sort()).toEqual([
|
|
78
78
|
'localMonth',
|
|
79
|
+
'localQuarter',
|
|
80
|
+
'localSemester',
|
|
79
81
|
'localWeek',
|
|
80
82
|
'localWeekOfYear',
|
|
83
|
+
'localYear',
|
|
81
84
|
]);
|
|
82
85
|
for (const write of periodWrites) {
|
|
83
86
|
expect(write.report.prep_time_counters[KEY].coverage.item_count).toBe(3);
|
|
84
87
|
}
|
|
85
88
|
});
|
|
89
|
+
it('FOLDS ENTRY rows only for the month-capped item periods', () => {
|
|
90
|
+
const plan = build({
|
|
91
|
+
reports: [report('localDate', '2026-09-14', { coverage: { item_count: 1 } })],
|
|
92
|
+
entries: [entry('localDate', '2026-09-14', { prep_time_entries: { [KEY]: { rows: [entryRowFixture()] } } })],
|
|
93
|
+
});
|
|
94
|
+
const periodEntryScopes = plan.entryWrites
|
|
95
|
+
.filter((write) => write.report.scope_context !== 'localDate')
|
|
96
|
+
.map((write) => write.report.scope_context)
|
|
97
|
+
.sort();
|
|
98
|
+
expect(periodEntryScopes).toEqual(['localMonth', 'localWeek', 'localWeekOfYear']);
|
|
99
|
+
expect(periodEntryScopes).not.toContain('localQuarter');
|
|
100
|
+
expect(periodEntryScopes).not.toContain('localSemester');
|
|
101
|
+
expect(periodEntryScopes).not.toContain('localYear');
|
|
102
|
+
});
|
|
86
103
|
it('ACCUMULATES two closed days into the same month', () => {
|
|
87
104
|
// Day 13 is already stored; day 14 is being closed now.
|
|
88
105
|
const storedDay13 = report('localDate', '2026-09-13', { coverage: { item_count: 2 } });
|
|
@@ -172,6 +189,27 @@ describe('buildTenantPrepTimeCloseDayPlan', () => {
|
|
|
172
189
|
});
|
|
173
190
|
});
|
|
174
191
|
/** A day/period entry document (rows are irrelevant to the iteration contract). */
|
|
192
|
+
const entryRowFixture = () => ({
|
|
193
|
+
entry_key: 'item:1',
|
|
194
|
+
order_id: 'order-1',
|
|
195
|
+
item_id: '1',
|
|
196
|
+
item_name: 'Burger',
|
|
197
|
+
category_name: 'Mains',
|
|
198
|
+
anchor: 'MEASURED',
|
|
199
|
+
duration_minutes: 9,
|
|
200
|
+
prep_started_at: new Date('2026-09-14T10:00:00.000Z'),
|
|
201
|
+
ready_at: new Date('2026-09-14T10:09:00.000Z'),
|
|
202
|
+
is_ready: true,
|
|
203
|
+
target_at: null,
|
|
204
|
+
target_source: null,
|
|
205
|
+
delta_minutes: null,
|
|
206
|
+
staff_id: null,
|
|
207
|
+
staff_name: null,
|
|
208
|
+
order_status: 'COMPLETED',
|
|
209
|
+
platform: 'POS_WALK-IN',
|
|
210
|
+
created_at: new Date('2026-09-14T09:55:00.000Z'),
|
|
211
|
+
local_hour: '2026-09-14 10',
|
|
212
|
+
});
|
|
175
213
|
const entry = (scope, field, over = {}) => ({
|
|
176
214
|
_id: scope + '|' + field,
|
|
177
215
|
tenant_id: 'tenant-a',
|
|
@@ -34,14 +34,31 @@ describe('flat drill-down row projection', () => {
|
|
|
34
34
|
expect(result.rows[0].time).toEqual(new Date('2026-09-14T10:00:00.000Z'));
|
|
35
35
|
expect(result.rows[0].data).toMatchObject({ kind: 'DISCOUNT' });
|
|
36
36
|
});
|
|
37
|
-
test('projects prep rows with
|
|
37
|
+
test('projects prep rows with the row entry_key as the cursor tie-break', () => {
|
|
38
38
|
const result = (0, materialized_report_drilldown_rows_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES, {
|
|
39
39
|
...base,
|
|
40
40
|
prep_time_entries: {
|
|
41
41
|
K: { rows: [row({ item_id: 'item-1', entry_key: 'prep:1' })] },
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
|
-
expect(result.rows[0].cursor_id).toBe('
|
|
44
|
+
expect(result.rows[0].cursor_id).toBe('prep:1');
|
|
45
|
+
});
|
|
46
|
+
test('keeps two order lines of one catalogue item distinct in the flat projection', () => {
|
|
47
|
+
const result = (0, materialized_report_drilldown_rows_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES, {
|
|
48
|
+
...base,
|
|
49
|
+
prep_time_entries: {
|
|
50
|
+
K: {
|
|
51
|
+
rows: [
|
|
52
|
+
row({ item_id: 'menu-1', entry_key: 'item:menu-1:line-a' }),
|
|
53
|
+
row({ item_id: 'menu-1', entry_key: 'item:menu-1:line-b' }),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
expect(result.rows.map((entry) => entry.cursor_id)).toEqual([
|
|
59
|
+
'item:menu-1:line-a',
|
|
60
|
+
'item:menu-1:line-b',
|
|
61
|
+
]);
|
|
45
62
|
});
|
|
46
63
|
test('projects cash rows as drawer-ledger rows (no order id)', () => {
|
|
47
64
|
const result = (0, materialized_report_drilldown_rows_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES, {
|