@managesome/eposmatic-toolkit 0.4.35 → 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/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +30 -9
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +3 -1
- package/esm/schemas/models/materialized_tenant_prep_time_entries.js +1 -0
- 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-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 +1 -0
- 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-compile.test.js +12 -2
- 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-report-drilldown-rows.test.js +19 -2
- package/package.json +1 -1
|
@@ -96,8 +96,21 @@ export function resolveMaterializedPrepTimeTarget(order, tenantDefaultMinutes) {
|
|
|
96
96
|
}
|
|
97
97
|
return { target_at: null, target_source: MATERIALIZED_PREP_TIME_TARGET_ENUM.NONE };
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Stable identity of ONE served item row inside its order - part of the page
|
|
101
|
+
* cursor and the flat projection identity.
|
|
102
|
+
*
|
|
103
|
+
* The catalogue item id is the GROUPING key; the order-line id keeps two lines
|
|
104
|
+
* of the same catalogue item distinct. A line is appended only when it differs
|
|
105
|
+
* from the catalogue id, so the common (and legacy) one-line shape is stable.
|
|
106
|
+
*/
|
|
107
|
+
export const buildMaterializedPrepTimeEntryKey = (itemId, lineId) => {
|
|
108
|
+
const parts = [String(itemId ?? 'unknown')];
|
|
109
|
+
if (lineId != null && String(lineId) !== '' && String(lineId) !== String(itemId ?? '')) {
|
|
110
|
+
parts.push(String(lineId));
|
|
111
|
+
}
|
|
112
|
+
return 'item:' + parts.join(':');
|
|
113
|
+
};
|
|
101
114
|
/**
|
|
102
115
|
* Accumulates ONE order's items into the prep counters + drill-down rows.
|
|
103
116
|
*
|
|
@@ -191,12 +204,19 @@ export function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes =
|
|
|
191
204
|
else {
|
|
192
205
|
counters.promise.no_target_count += 1;
|
|
193
206
|
}
|
|
194
|
-
|
|
207
|
+
// CATALOGUE item id: the grouping identity the Items tab reads. The
|
|
208
|
+
// order-line id is a DIFFERENT identity and is preserved as line_id, so
|
|
209
|
+
// two lines of one menu item remain two served events.
|
|
210
|
+
const lineId = item?._id != null ? String(item._id) : null;
|
|
211
|
+
const catalogueItemId = item?.item_id != null && String(item.item_id) !== ''
|
|
212
|
+
? String(item.item_id)
|
|
213
|
+
: lineId;
|
|
195
214
|
const row = {
|
|
196
|
-
entry_key: buildMaterializedPrepTimeEntryKey(
|
|
215
|
+
entry_key: buildMaterializedPrepTimeEntryKey(catalogueItemId, lineId),
|
|
197
216
|
order_id: orderId,
|
|
198
217
|
order_number: order.order_number ?? null,
|
|
199
|
-
item_id:
|
|
218
|
+
item_id: catalogueItemId,
|
|
219
|
+
line_id: lineId,
|
|
200
220
|
item_name: item?.name != null ? String(item.name) : null,
|
|
201
221
|
category_name: category?.name != null ? String(category.name) : null,
|
|
202
222
|
anchor,
|
|
@@ -214,10 +234,11 @@ export function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes =
|
|
|
214
234
|
created_at: createdAt,
|
|
215
235
|
local_hour: context.local_hour_label,
|
|
216
236
|
};
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
|
|
237
|
+
// EVERY served item becomes a row - including an item with no prep
|
|
238
|
+
// signal. Coverage uses ALL served items as its denominator; a no-signal
|
|
239
|
+
// row is an UNMEASURED row with null duration and is visible in the
|
|
240
|
+
// Unmeasured view.
|
|
241
|
+
entries.push(row);
|
|
221
242
|
}
|
|
222
243
|
}
|
|
223
244
|
if (tracked > 0)
|
|
@@ -25,7 +25,9 @@ const ROW_SPECS = {
|
|
|
25
25
|
rowsKey: 'prep_time_entries',
|
|
26
26
|
time: (row) => row.created_at,
|
|
27
27
|
orderId: (row) => row.order_id,
|
|
28
|
-
|
|
28
|
+
// ROW identity, not the catalogue item id: two lines of the same menu item
|
|
29
|
+
// in one order must both survive the unique flat-row identity.
|
|
30
|
+
cursorId: (row) => row.entry_key,
|
|
29
31
|
},
|
|
30
32
|
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES]: {
|
|
31
33
|
rowsKey: 'cash_entries',
|
|
@@ -27,6 +27,7 @@ const PrepTimeEntrySchema = new Schema({
|
|
|
27
27
|
order_id: { type: String, required: true },
|
|
28
28
|
order_number: { type: Number, default: null },
|
|
29
29
|
item_id: { type: String, default: null },
|
|
30
|
+
line_id: { type: String, default: null },
|
|
30
31
|
item_name: { type: String, default: null },
|
|
31
32
|
category_name: { type: String, default: null },
|
|
32
33
|
// ---- measurement ----
|
|
@@ -36,6 +36,7 @@ export interface IPrepTimeOrderSource {
|
|
|
36
36
|
name?: string | null;
|
|
37
37
|
items?: {
|
|
38
38
|
_id?: string;
|
|
39
|
+
item_id?: string | null;
|
|
39
40
|
name?: string | null;
|
|
40
41
|
is_ready?: boolean;
|
|
41
42
|
ready_minutes?: number | string | null;
|
|
@@ -76,8 +77,15 @@ export declare function resolveMaterializedPrepTimeTarget(order: Pick<IPrepTimeO
|
|
|
76
77
|
target_at: Date | null;
|
|
77
78
|
target_source: MATERIALIZED_PREP_TIME_TARGET_ENUM;
|
|
78
79
|
};
|
|
79
|
-
/**
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Stable identity of ONE served item row inside its order - part of the page
|
|
82
|
+
* cursor and the flat projection identity.
|
|
83
|
+
*
|
|
84
|
+
* The catalogue item id is the GROUPING key; the order-line id keeps two lines
|
|
85
|
+
* of the same catalogue item distinct. A line is appended only when it differs
|
|
86
|
+
* from the catalogue id, so the common (and legacy) one-line shape is stable.
|
|
87
|
+
*/
|
|
88
|
+
export declare const buildMaterializedPrepTimeEntryKey: (itemId: string | null, lineId?: string | null) => string;
|
|
81
89
|
export interface IAccumulateOrderPrepTimeResult {
|
|
82
90
|
counters: IMaterializedPrepTimeCounters;
|
|
83
91
|
entries: IMaterializedPrepTimeEntry[];
|
|
@@ -104,8 +104,21 @@ function resolveMaterializedPrepTimeTarget(order, tenantDefaultMinutes) {
|
|
|
104
104
|
}
|
|
105
105
|
return { target_at: null, target_source: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.NONE };
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
108
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Stable identity of ONE served item row inside its order - part of the page
|
|
109
|
+
* cursor and the flat projection identity.
|
|
110
|
+
*
|
|
111
|
+
* The catalogue item id is the GROUPING key; the order-line id keeps two lines
|
|
112
|
+
* of the same catalogue item distinct. A line is appended only when it differs
|
|
113
|
+
* from the catalogue id, so the common (and legacy) one-line shape is stable.
|
|
114
|
+
*/
|
|
115
|
+
const buildMaterializedPrepTimeEntryKey = (itemId, lineId) => {
|
|
116
|
+
const parts = [String(itemId ?? 'unknown')];
|
|
117
|
+
if (lineId != null && String(lineId) !== '' && String(lineId) !== String(itemId ?? '')) {
|
|
118
|
+
parts.push(String(lineId));
|
|
119
|
+
}
|
|
120
|
+
return 'item:' + parts.join(':');
|
|
121
|
+
};
|
|
109
122
|
exports.buildMaterializedPrepTimeEntryKey = buildMaterializedPrepTimeEntryKey;
|
|
110
123
|
/**
|
|
111
124
|
* Accumulates ONE order's items into the prep counters + drill-down rows.
|
|
@@ -200,12 +213,19 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
|
|
|
200
213
|
else {
|
|
201
214
|
counters.promise.no_target_count += 1;
|
|
202
215
|
}
|
|
203
|
-
|
|
216
|
+
// CATALOGUE item id: the grouping identity the Items tab reads. The
|
|
217
|
+
// order-line id is a DIFFERENT identity and is preserved as line_id, so
|
|
218
|
+
// two lines of one menu item remain two served events.
|
|
219
|
+
const lineId = item?._id != null ? String(item._id) : null;
|
|
220
|
+
const catalogueItemId = item?.item_id != null && String(item.item_id) !== ''
|
|
221
|
+
? String(item.item_id)
|
|
222
|
+
: lineId;
|
|
204
223
|
const row = {
|
|
205
|
-
entry_key: (0, exports.buildMaterializedPrepTimeEntryKey)(
|
|
224
|
+
entry_key: (0, exports.buildMaterializedPrepTimeEntryKey)(catalogueItemId, lineId),
|
|
206
225
|
order_id: orderId,
|
|
207
226
|
order_number: order.order_number ?? null,
|
|
208
|
-
item_id:
|
|
227
|
+
item_id: catalogueItemId,
|
|
228
|
+
line_id: lineId,
|
|
209
229
|
item_name: item?.name != null ? String(item.name) : null,
|
|
210
230
|
category_name: category?.name != null ? String(category.name) : null,
|
|
211
231
|
anchor,
|
|
@@ -223,10 +243,11 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
|
|
|
223
243
|
created_at: createdAt,
|
|
224
244
|
local_hour: context.local_hour_label,
|
|
225
245
|
};
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
|
|
246
|
+
// EVERY served item becomes a row - including an item with no prep
|
|
247
|
+
// signal. Coverage uses ALL served items as its denominator; a no-signal
|
|
248
|
+
// row is an UNMEASURED row with null duration and is visible in the
|
|
249
|
+
// Unmeasured view.
|
|
250
|
+
entries.push(row);
|
|
230
251
|
}
|
|
231
252
|
}
|
|
232
253
|
if (tracked > 0)
|
|
@@ -31,7 +31,9 @@ const ROW_SPECS = {
|
|
|
31
31
|
rowsKey: 'prep_time_entries',
|
|
32
32
|
time: (row) => row.created_at,
|
|
33
33
|
orderId: (row) => row.order_id,
|
|
34
|
-
|
|
34
|
+
// ROW identity, not the catalogue item id: two lines of the same menu item
|
|
35
|
+
// in one order must both survive the unique flat-row identity.
|
|
36
|
+
cursorId: (row) => row.entry_key,
|
|
35
37
|
},
|
|
36
38
|
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES]: {
|
|
37
39
|
rowsKey: 'cash_entries',
|
|
@@ -37,6 +37,7 @@ declare const PrepTimeEntrySchema: Schema<any, import("mongoose").Model<any, any
|
|
|
37
37
|
item_name: string;
|
|
38
38
|
created_at: NativeDate;
|
|
39
39
|
local_hour: string;
|
|
40
|
+
line_id: string;
|
|
40
41
|
category_name: string;
|
|
41
42
|
duration_minutes: number;
|
|
42
43
|
ready_at: NativeDate;
|
|
@@ -58,6 +59,7 @@ declare const PrepTimeEntrySchema: Schema<any, import("mongoose").Model<any, any
|
|
|
58
59
|
item_name: string;
|
|
59
60
|
created_at: NativeDate;
|
|
60
61
|
local_hour: string;
|
|
62
|
+
line_id: string;
|
|
61
63
|
category_name: string;
|
|
62
64
|
duration_minutes: number;
|
|
63
65
|
ready_at: NativeDate;
|
|
@@ -79,6 +81,7 @@ declare const PrepTimeEntrySchema: Schema<any, import("mongoose").Model<any, any
|
|
|
79
81
|
item_name: string;
|
|
80
82
|
created_at: NativeDate;
|
|
81
83
|
local_hour: string;
|
|
84
|
+
line_id: string;
|
|
82
85
|
category_name: string;
|
|
83
86
|
duration_minutes: number;
|
|
84
87
|
ready_at: NativeDate;
|
|
@@ -30,6 +30,7 @@ const PrepTimeEntrySchema = new mongoose_1.Schema({
|
|
|
30
30
|
order_id: { type: String, required: true },
|
|
31
31
|
order_number: { type: Number, default: null },
|
|
32
32
|
item_id: { type: String, default: null },
|
|
33
|
+
line_id: { type: String, default: null },
|
|
33
34
|
item_name: { type: String, default: null },
|
|
34
35
|
category_name: { type: String, default: null },
|
|
35
36
|
// ---- measurement ----
|
|
@@ -23,7 +23,10 @@ export interface IMaterializedPrepTimeEntry {
|
|
|
23
23
|
entry_key: string;
|
|
24
24
|
order_id: string;
|
|
25
25
|
order_number?: number | null;
|
|
26
|
+
/** CATALOGUE/menu item id - the grouping identity of the Items read. */
|
|
26
27
|
item_id: string | null;
|
|
28
|
+
/** ORDER-LINE id - the row/event identity inside the order. */
|
|
29
|
+
line_id: string | null;
|
|
27
30
|
item_name: string | null;
|
|
28
31
|
category_name: string | null;
|
|
29
32
|
/** Which population this row belongs to - the split that makes the report correct. */
|
|
@@ -263,7 +263,7 @@ describe('accumulateOrderPrepTime - promise grading', () => {
|
|
|
263
263
|
});
|
|
264
264
|
});
|
|
265
265
|
describe('accumulateOrderPrepTime - drill-down rows', () => {
|
|
266
|
-
it('emits a row
|
|
266
|
+
it('emits a row for EVERY served item, each stating its anchor', () => {
|
|
267
267
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
268
268
|
order: order({
|
|
269
269
|
categories: [
|
|
@@ -279,11 +279,18 @@ describe('accumulateOrderPrepTime - drill-down rows', () => {
|
|
|
279
279
|
}),
|
|
280
280
|
context,
|
|
281
281
|
});
|
|
282
|
-
expect(result.entries).toHaveLength(
|
|
282
|
+
expect(result.entries).toHaveLength(3);
|
|
283
283
|
const measured = result.entries.find((row) => row.item_id === 'm1');
|
|
284
284
|
const fallback = result.entries.find((row) => row.item_id === 'f1');
|
|
285
|
+
const untracked = result.entries.find((row) => row.item_id === 'nothing');
|
|
285
286
|
expect(measured.anchor).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED);
|
|
286
287
|
expect(fallback.anchor).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED);
|
|
288
|
+
// No prep signal still becomes a ROW: the Items/Series coverage must use the
|
|
289
|
+
// same served population as the Summary.
|
|
290
|
+
expect(untracked.anchor).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED);
|
|
291
|
+
expect(untracked.duration_minutes).toBeNull();
|
|
292
|
+
expect(untracked.ready_at).toBeNull();
|
|
293
|
+
expect(untracked.delta_minutes).toBeNull();
|
|
287
294
|
// The ready instant is RECONSTRUCTED for the measured row only.
|
|
288
295
|
expect(measured.ready_at?.toISOString()).toBe('2026-09-13T10:09:00.000Z');
|
|
289
296
|
expect(fallback.ready_at).toBeNull();
|
|
@@ -185,8 +185,18 @@ describe('compileTenantPrepTimeReports', () => {
|
|
|
185
185
|
expect(counters.coverage.tracked_count).toBe(0);
|
|
186
186
|
expect(counters.coverage.own_anchor_count).toBe(0);
|
|
187
187
|
expect(counters.duration.count).toBe(0);
|
|
188
|
-
//
|
|
189
|
-
|
|
188
|
+
// One row per served item, even with no prep signal: the entry population
|
|
189
|
+
// must match the Summary's coverage denominator.
|
|
190
|
+
const dateEntries = result.entries.find((doc) => doc.scope_context === 'localDate');
|
|
191
|
+
const rows = dateEntries.prep_time_entries['COMPLETED:POS_WALK-IN'].rows;
|
|
192
|
+
expect(rows).toHaveLength(1);
|
|
193
|
+
expect(rows[0]).toMatchObject({
|
|
194
|
+
anchor: 'UNMEASURED',
|
|
195
|
+
duration_minutes: null,
|
|
196
|
+
prep_started_at: null,
|
|
197
|
+
ready_at: null,
|
|
198
|
+
delta_minutes: null,
|
|
199
|
+
});
|
|
190
200
|
});
|
|
191
201
|
it('counts a served-but-unobserved item in coverage but NOT in duration', () => {
|
|
192
202
|
const unobserved = order({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|
|
@@ -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, {
|