@managesome/eposmatic-toolkit 0.4.45 → 0.4.46
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 +2 -5
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +8 -16
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +7 -9
- package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +5 -7
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +2 -5
- package/lib/constants/MATERIALIZED_REPORTS.js +2 -5
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +1 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +8 -16
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +7 -9
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +0 -2
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.js +5 -7
- package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +5 -9
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +28 -33
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +1 -2
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +11 -13
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +0 -1
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +1 -2
- package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.js +2 -5
- package/package.json +1 -1
|
@@ -529,14 +529,11 @@ export const MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = 0;
|
|
|
529
529
|
* -> NONE
|
|
530
530
|
*
|
|
531
531
|
* Explicit `estimated_takeaway_time` / `estimated_delivery_time` are NOT part
|
|
532
|
-
* of this hierarchy.
|
|
533
|
-
*
|
|
534
|
-
* row so a reader can always tell which rule produced the target.
|
|
532
|
+
* of this hierarchy. There is no legacy target source; all materialized data is
|
|
533
|
+
* new and pre-launch. The source is labelled per row.
|
|
535
534
|
*/
|
|
536
535
|
export var MATERIALIZED_PREP_TIME_TARGET_ENUM;
|
|
537
536
|
(function (MATERIALIZED_PREP_TIME_TARGET_ENUM) {
|
|
538
|
-
/** Legacy-only: an explicit estimate written by an older implementation. */
|
|
539
|
-
MATERIALIZED_PREP_TIME_TARGET_ENUM["PROMISE"] = "PROMISE";
|
|
540
537
|
/** Dine-in target from `dinein_details.prep_minutes` (MINUTES). */
|
|
541
538
|
MATERIALIZED_PREP_TIME_TARGET_ENUM["DINE_IN_PREP"] = "DINE_IN_PREP";
|
|
542
539
|
/** Tenant `default_prep_minutes` (MINUTES), anchored to the punch instant. */
|
|
@@ -121,8 +121,7 @@ export function freshMaterializedPrepTimeCounters() {
|
|
|
121
121
|
order_count: 0,
|
|
122
122
|
},
|
|
123
123
|
duration: { min: 0, max: 0, sum: 0, count: 0, instant_count: 0, buckets },
|
|
124
|
-
|
|
125
|
-
promise_set_count: 0,
|
|
124
|
+
target: {
|
|
126
125
|
default_baseline_count: 0,
|
|
127
126
|
on_time_count: 0,
|
|
128
127
|
late_count: 0,
|
|
@@ -270,12 +269,12 @@ export function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes =
|
|
|
270
269
|
}
|
|
271
270
|
if (target_at != null) {
|
|
272
271
|
deltaMinutes = Math.round((readyAt.getTime() - target_at.getTime()) / 60000);
|
|
273
|
-
counters.
|
|
272
|
+
counters.target.delta_sum += deltaMinutes;
|
|
274
273
|
if (deltaMinutes <= MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA) {
|
|
275
|
-
counters.
|
|
274
|
+
counters.target.on_time_count += 1;
|
|
276
275
|
}
|
|
277
276
|
else {
|
|
278
|
-
counters.
|
|
277
|
+
counters.target.late_count += 1;
|
|
279
278
|
counters.late_items.count += 1;
|
|
280
279
|
if (deltaMinutes > counters.late_items.worst_delta) {
|
|
281
280
|
counters.late_items.worst_delta = deltaMinutes;
|
|
@@ -287,20 +286,13 @@ export function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes =
|
|
|
287
286
|
counters.coverage.fallback_anchor_count += 1;
|
|
288
287
|
}
|
|
289
288
|
}
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
// DOES produce is a default-baseline target (DINE_IN_PREP /
|
|
293
|
-
// TENANT_DEFAULT / TAKEAWAY_TIME). A row with no target is NONE.
|
|
289
|
+
// Every target is DINE_IN_PREP / TENANT_DEFAULT / TAKEAWAY_TIME; a row
|
|
290
|
+
// with no target is NONE.
|
|
294
291
|
if (target_at != null) {
|
|
295
|
-
|
|
296
|
-
counters.promise.promise_set_count += 1;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
counters.promise.default_baseline_count += 1;
|
|
300
|
-
}
|
|
292
|
+
counters.target.default_baseline_count += 1;
|
|
301
293
|
}
|
|
302
294
|
else {
|
|
303
|
-
counters.
|
|
295
|
+
counters.target.no_target_count += 1;
|
|
304
296
|
}
|
|
305
297
|
// CATALOGUE item id: the grouping identity the Items tab reads. The
|
|
306
298
|
// order-line id is a DIFFERENT identity and is preserved as line_id, so
|
|
@@ -35,15 +35,13 @@ export function mergeMaterializedPrepTimeCounters(target, source) {
|
|
|
35
35
|
target.duration.max = Math.max(target.duration.max, source.duration.max);
|
|
36
36
|
}
|
|
37
37
|
// ---- target / on-time (all additive; delta_sum is SIGNED) ----
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
target.
|
|
42
|
-
target.
|
|
43
|
-
target.
|
|
44
|
-
target.
|
|
45
|
-
target.promise.delta_sum += source.promise.delta_sum;
|
|
46
|
-
target.promise.no_target_count += source.promise.no_target_count;
|
|
38
|
+
// Target-grading counters; every target is DINE_IN_PREP /
|
|
39
|
+
// TENANT_DEFAULT / TAKEAWAY_TIME.
|
|
40
|
+
target.target.default_baseline_count += source.target.default_baseline_count;
|
|
41
|
+
target.target.on_time_count += source.target.on_time_count;
|
|
42
|
+
target.target.late_count += source.target.late_count;
|
|
43
|
+
target.target.delta_sum += source.target.delta_sum;
|
|
44
|
+
target.target.no_target_count += source.target.no_target_count;
|
|
47
45
|
// ---- late items ----
|
|
48
46
|
target.late_items.count += source.late_items.count;
|
|
49
47
|
target.late_items.worst_delta = Math.max(target.late_items.worst_delta, source.late_items.worst_delta);
|
|
@@ -54,7 +54,6 @@ const emptySummary = () => ({
|
|
|
54
54
|
instant_percent: null,
|
|
55
55
|
on_time_count: 0,
|
|
56
56
|
late_count: 0,
|
|
57
|
-
promise_baseline_count: 0,
|
|
58
57
|
default_baseline_count: 0,
|
|
59
58
|
unmeasurable_count: 0,
|
|
60
59
|
});
|
|
@@ -68,7 +67,7 @@ const buildBuckets = (counters) => {
|
|
|
68
67
|
const buildSummary = (counters) => {
|
|
69
68
|
const coverage = counters.coverage;
|
|
70
69
|
const duration = counters.duration;
|
|
71
|
-
const
|
|
70
|
+
const target = counters.target;
|
|
72
71
|
const buckets = buildBuckets(counters);
|
|
73
72
|
return {
|
|
74
73
|
items: coverage.item_count,
|
|
@@ -82,11 +81,10 @@ const buildSummary = (counters) => {
|
|
|
82
81
|
median_bucket: percentileBucket(buckets, 0.5),
|
|
83
82
|
p90_bucket: percentileBucket(buckets, 0.9),
|
|
84
83
|
instant_percent: duration.count > 0 ? toPercent(duration.instant_count, duration.count) : null,
|
|
85
|
-
on_time_count:
|
|
86
|
-
late_count:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
unmeasurable_count: promise.no_target_count,
|
|
84
|
+
on_time_count: target.on_time_count,
|
|
85
|
+
late_count: target.late_count,
|
|
86
|
+
default_baseline_count: target.default_baseline_count,
|
|
87
|
+
unmeasurable_count: target.no_target_count,
|
|
90
88
|
};
|
|
91
89
|
};
|
|
92
90
|
const emptyPage = (tenantIds) => {
|
|
@@ -428,13 +428,10 @@ export declare const MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = 0;
|
|
|
428
428
|
* -> NONE
|
|
429
429
|
*
|
|
430
430
|
* Explicit `estimated_takeaway_time` / `estimated_delivery_time` are NOT part
|
|
431
|
-
* of this hierarchy.
|
|
432
|
-
*
|
|
433
|
-
* row so a reader can always tell which rule produced the target.
|
|
431
|
+
* of this hierarchy. There is no legacy target source; all materialized data is
|
|
432
|
+
* new and pre-launch. The source is labelled per row.
|
|
434
433
|
*/
|
|
435
434
|
export declare enum MATERIALIZED_PREP_TIME_TARGET_ENUM {
|
|
436
|
-
/** Legacy-only: an explicit estimate written by an older implementation. */
|
|
437
|
-
PROMISE = "PROMISE",
|
|
438
435
|
/** Dine-in target from `dinein_details.prep_minutes` (MINUTES). */
|
|
439
436
|
DINE_IN_PREP = "DINE_IN_PREP",
|
|
440
437
|
/** Tenant `default_prep_minutes` (MINUTES), anchored to the punch instant. */
|
|
@@ -533,14 +533,11 @@ exports.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = 0;
|
|
|
533
533
|
* -> NONE
|
|
534
534
|
*
|
|
535
535
|
* Explicit `estimated_takeaway_time` / `estimated_delivery_time` are NOT part
|
|
536
|
-
* of this hierarchy.
|
|
537
|
-
*
|
|
538
|
-
* row so a reader can always tell which rule produced the target.
|
|
536
|
+
* of this hierarchy. There is no legacy target source; all materialized data is
|
|
537
|
+
* new and pre-launch. The source is labelled per row.
|
|
539
538
|
*/
|
|
540
539
|
var MATERIALIZED_PREP_TIME_TARGET_ENUM;
|
|
541
540
|
(function (MATERIALIZED_PREP_TIME_TARGET_ENUM) {
|
|
542
|
-
/** Legacy-only: an explicit estimate written by an older implementation. */
|
|
543
|
-
MATERIALIZED_PREP_TIME_TARGET_ENUM["PROMISE"] = "PROMISE";
|
|
544
541
|
/** Dine-in target from `dinein_details.prep_minutes` (MINUTES). */
|
|
545
542
|
MATERIALIZED_PREP_TIME_TARGET_ENUM["DINE_IN_PREP"] = "DINE_IN_PREP";
|
|
546
543
|
/** Tenant `default_prep_minutes` (MINUTES), anchored to the punch instant. */
|
|
@@ -45,7 +45,7 @@ export interface IPrepTimeOrderSource {
|
|
|
45
45
|
}[];
|
|
46
46
|
/**
|
|
47
47
|
* Explicit estimates are present on the SOURCE order but are deliberately NOT
|
|
48
|
-
* part of the M2 target hierarchy (they are
|
|
48
|
+
* part of the M2 target hierarchy (they are an order estimate, not the prep-time
|
|
49
49
|
* baseline). Kept in the shape so callers can pass a full order object.
|
|
50
50
|
*/
|
|
51
51
|
delivery_details?: {
|
|
@@ -129,8 +129,7 @@ function freshMaterializedPrepTimeCounters() {
|
|
|
129
129
|
order_count: 0,
|
|
130
130
|
},
|
|
131
131
|
duration: { min: 0, max: 0, sum: 0, count: 0, instant_count: 0, buckets },
|
|
132
|
-
|
|
133
|
-
promise_set_count: 0,
|
|
132
|
+
target: {
|
|
134
133
|
default_baseline_count: 0,
|
|
135
134
|
on_time_count: 0,
|
|
136
135
|
late_count: 0,
|
|
@@ -279,12 +278,12 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
|
|
|
279
278
|
}
|
|
280
279
|
if (target_at != null) {
|
|
281
280
|
deltaMinutes = Math.round((readyAt.getTime() - target_at.getTime()) / 60000);
|
|
282
|
-
counters.
|
|
281
|
+
counters.target.delta_sum += deltaMinutes;
|
|
283
282
|
if (deltaMinutes <= MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA) {
|
|
284
|
-
counters.
|
|
283
|
+
counters.target.on_time_count += 1;
|
|
285
284
|
}
|
|
286
285
|
else {
|
|
287
|
-
counters.
|
|
286
|
+
counters.target.late_count += 1;
|
|
288
287
|
counters.late_items.count += 1;
|
|
289
288
|
if (deltaMinutes > counters.late_items.worst_delta) {
|
|
290
289
|
counters.late_items.worst_delta = deltaMinutes;
|
|
@@ -296,20 +295,13 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
|
|
|
296
295
|
counters.coverage.fallback_anchor_count += 1;
|
|
297
296
|
}
|
|
298
297
|
}
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
// DOES produce is a default-baseline target (DINE_IN_PREP /
|
|
302
|
-
// TENANT_DEFAULT / TAKEAWAY_TIME). A row with no target is NONE.
|
|
298
|
+
// Every target is DINE_IN_PREP / TENANT_DEFAULT / TAKEAWAY_TIME; a row
|
|
299
|
+
// with no target is NONE.
|
|
303
300
|
if (target_at != null) {
|
|
304
|
-
|
|
305
|
-
counters.promise.promise_set_count += 1;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
counters.promise.default_baseline_count += 1;
|
|
309
|
-
}
|
|
301
|
+
counters.target.default_baseline_count += 1;
|
|
310
302
|
}
|
|
311
303
|
else {
|
|
312
|
-
counters.
|
|
304
|
+
counters.target.no_target_count += 1;
|
|
313
305
|
}
|
|
314
306
|
// CATALOGUE item id: the grouping identity the Items tab reads. The
|
|
315
307
|
// order-line id is a DIFFERENT identity and is preserved as line_id, so
|
|
@@ -42,15 +42,13 @@ function mergeMaterializedPrepTimeCounters(target, source) {
|
|
|
42
42
|
target.duration.max = Math.max(target.duration.max, source.duration.max);
|
|
43
43
|
}
|
|
44
44
|
// ---- target / on-time (all additive; delta_sum is SIGNED) ----
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
target.
|
|
49
|
-
target.
|
|
50
|
-
target.
|
|
51
|
-
target.
|
|
52
|
-
target.promise.delta_sum += source.promise.delta_sum;
|
|
53
|
-
target.promise.no_target_count += source.promise.no_target_count;
|
|
45
|
+
// Target-grading counters; every target is DINE_IN_PREP /
|
|
46
|
+
// TENANT_DEFAULT / TAKEAWAY_TIME.
|
|
47
|
+
target.target.default_baseline_count += source.target.default_baseline_count;
|
|
48
|
+
target.target.on_time_count += source.target.on_time_count;
|
|
49
|
+
target.target.late_count += source.target.late_count;
|
|
50
|
+
target.target.delta_sum += source.target.delta_sum;
|
|
51
|
+
target.target.no_target_count += source.target.no_target_count;
|
|
54
52
|
// ---- late items ----
|
|
55
53
|
target.late_items.count += source.late_items.count;
|
|
56
54
|
target.late_items.worst_delta = Math.max(target.late_items.worst_delta, source.late_items.worst_delta);
|
|
@@ -48,8 +48,6 @@ export interface IFormattedPrepTimeSummary {
|
|
|
48
48
|
instant_percent: number | null;
|
|
49
49
|
on_time_count: number;
|
|
50
50
|
late_count: number;
|
|
51
|
-
/** LEGACY-only; the current target hierarchy never produces PROMISE. */
|
|
52
|
-
promise_baseline_count: number;
|
|
53
51
|
/** DINE_IN_PREP / TENANT_DEFAULT / TAKEAWAY_TIME targets. */
|
|
54
52
|
default_baseline_count: number;
|
|
55
53
|
unmeasurable_count: number;
|
|
@@ -58,7 +58,6 @@ const emptySummary = () => ({
|
|
|
58
58
|
instant_percent: null,
|
|
59
59
|
on_time_count: 0,
|
|
60
60
|
late_count: 0,
|
|
61
|
-
promise_baseline_count: 0,
|
|
62
61
|
default_baseline_count: 0,
|
|
63
62
|
unmeasurable_count: 0,
|
|
64
63
|
});
|
|
@@ -72,7 +71,7 @@ const buildBuckets = (counters) => {
|
|
|
72
71
|
const buildSummary = (counters) => {
|
|
73
72
|
const coverage = counters.coverage;
|
|
74
73
|
const duration = counters.duration;
|
|
75
|
-
const
|
|
74
|
+
const target = counters.target;
|
|
76
75
|
const buckets = buildBuckets(counters);
|
|
77
76
|
return {
|
|
78
77
|
items: coverage.item_count,
|
|
@@ -86,11 +85,10 @@ const buildSummary = (counters) => {
|
|
|
86
85
|
median_bucket: percentileBucket(buckets, 0.5),
|
|
87
86
|
p90_bucket: percentileBucket(buckets, 0.9),
|
|
88
87
|
instant_percent: duration.count > 0 ? toPercent(duration.instant_count, duration.count) : null,
|
|
89
|
-
on_time_count:
|
|
90
|
-
late_count:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
unmeasurable_count: promise.no_target_count,
|
|
88
|
+
on_time_count: target.on_time_count,
|
|
89
|
+
late_count: target.late_count,
|
|
90
|
+
default_baseline_count: target.default_baseline_count,
|
|
91
|
+
unmeasurable_count: target.no_target_count,
|
|
94
92
|
};
|
|
95
93
|
};
|
|
96
94
|
const emptyPage = (tenantIds) => {
|
|
@@ -60,15 +60,11 @@ export interface IMaterializedPrepTimeDuration {
|
|
|
60
60
|
* tolerance is `MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA` (0 for v1), kept as a
|
|
61
61
|
* constant so a grace window can be applied to the SAME materialized data later.
|
|
62
62
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* time) NEVER produces `PROMISE`; every target it produces is a default
|
|
66
|
-
* baseline.
|
|
63
|
+
* Every target comes from the current hierarchy (dine-in prep / tenant default /
|
|
64
|
+
* converted takeaway time); there is no legacy baseline.
|
|
67
65
|
*/
|
|
68
|
-
export interface
|
|
69
|
-
/**
|
|
70
|
-
promise_set_count: number;
|
|
71
|
-
/** Items graded against the tenant baseline (DINE_IN_PREP / TENANT_DEFAULT / TAKEAWAY_TIME). */
|
|
66
|
+
export interface IMaterializedPrepTimeTargetGrading {
|
|
67
|
+
/** Items graded against a baseline (DINE_IN_PREP / TENANT_DEFAULT / TAKEAWAY_TIME). */
|
|
72
68
|
default_baseline_count: number;
|
|
73
69
|
on_time_count: number;
|
|
74
70
|
late_count: number;
|
|
@@ -82,7 +78,7 @@ export interface IMaterializedPrepTimeCounters {
|
|
|
82
78
|
coverage: IMaterializedPrepTimeCoverage;
|
|
83
79
|
/** MEASURED items only. */
|
|
84
80
|
duration: IMaterializedPrepTimeDuration;
|
|
85
|
-
|
|
81
|
+
target: IMaterializedPrepTimeTargetGrading;
|
|
86
82
|
/** Late rows (measured, delta > tolerance). Details live in the entries collection. */
|
|
87
83
|
late_items: {
|
|
88
84
|
count: number;
|
|
@@ -157,7 +157,7 @@ describe('resolveMaterializedPrepTimeTarget (target hierarchy)', () => {
|
|
|
157
157
|
expect(noTenantTarget.target_at).toBeNull();
|
|
158
158
|
const tenantDefault = (0, materialized_prep_time_classification_helpers_1.resolveMaterializedPrepTimeTarget)(withEstimate, 15, null);
|
|
159
159
|
expect(tenantDefault.target_source).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TENANT_DEFAULT);
|
|
160
|
-
// 09:55 + 15 = 10:10 - NOT the 10:40
|
|
160
|
+
// 09:55 + 15 = 10:10 - NOT the 10:40 target.
|
|
161
161
|
expect(tenantDefault.target_at?.toISOString()).toBe('2026-09-13T10:10:00.000Z');
|
|
162
162
|
});
|
|
163
163
|
it('reports NONE when createdAt is unusable', () => {
|
|
@@ -314,11 +314,10 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
314
314
|
context,
|
|
315
315
|
tenantDefaultMinutes: 15,
|
|
316
316
|
});
|
|
317
|
-
expect(result.counters.
|
|
318
|
-
expect(result.counters.
|
|
319
|
-
expect(result.counters.
|
|
320
|
-
expect(result.counters.
|
|
321
|
-
expect(result.counters.promise.promise_set_count).toBe(0);
|
|
317
|
+
expect(result.counters.target.on_time_count).toBe(1);
|
|
318
|
+
expect(result.counters.target.late_count).toBe(0);
|
|
319
|
+
expect(result.counters.target.delta_sum).toBe(-5);
|
|
320
|
+
expect(result.counters.target.default_baseline_count).toBe(1);
|
|
322
321
|
});
|
|
323
322
|
it('grades LATE with a SIGNED delta and tracks worst_delta', () => {
|
|
324
323
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
@@ -329,9 +328,9 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
329
328
|
context,
|
|
330
329
|
tenantDefaultMinutes: 15,
|
|
331
330
|
});
|
|
332
|
-
expect(result.counters.
|
|
333
|
-
expect(result.counters.
|
|
334
|
-
expect(result.counters.
|
|
331
|
+
expect(result.counters.target.late_count).toBe(1);
|
|
332
|
+
expect(result.counters.target.on_time_count).toBe(0);
|
|
333
|
+
expect(result.counters.target.delta_sum).toBe(10);
|
|
335
334
|
expect(result.counters.late_items.count).toBe(1);
|
|
336
335
|
expect(result.counters.late_items.worst_delta).toBe(10);
|
|
337
336
|
});
|
|
@@ -340,12 +339,11 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
340
339
|
order: order({ categories: [{ name: 'Mains', items: [item()] }] }),
|
|
341
340
|
context,
|
|
342
341
|
});
|
|
343
|
-
expect(result.counters.
|
|
344
|
-
expect(result.counters.
|
|
345
|
-
expect(result.counters.
|
|
342
|
+
expect(result.counters.target.no_target_count).toBe(1);
|
|
343
|
+
expect(result.counters.target.on_time_count).toBe(0);
|
|
344
|
+
expect(result.counters.target.late_count).toBe(0);
|
|
346
345
|
expect(result.counters.late_items.count).toBe(0);
|
|
347
|
-
expect(result.counters.
|
|
348
|
-
expect(result.counters.promise.promise_set_count).toBe(0);
|
|
346
|
+
expect(result.counters.target.default_baseline_count).toBe(0);
|
|
349
347
|
});
|
|
350
348
|
it('counts a DEFAULT baseline separately from a promise (decision e2)', () => {
|
|
351
349
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
@@ -353,11 +351,10 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
353
351
|
context,
|
|
354
352
|
tenantDefaultMinutes: 20,
|
|
355
353
|
});
|
|
356
|
-
expect(result.counters.
|
|
357
|
-
expect(result.counters.
|
|
358
|
-
expect(result.counters.promise.on_time_count).toBe(1);
|
|
354
|
+
expect(result.counters.target.default_baseline_count).toBe(1);
|
|
355
|
+
expect(result.counters.target.on_time_count).toBe(1);
|
|
359
356
|
});
|
|
360
|
-
it('counts a DINE_IN_PREP target in default_baseline_count
|
|
357
|
+
it('counts a DINE_IN_PREP target in default_baseline_count', () => {
|
|
361
358
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
362
359
|
// ready 10:09; dine-in prep 20 -> target 10:15 -> -6 on time.
|
|
363
360
|
order: order({
|
|
@@ -370,10 +367,9 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
370
367
|
tenantTakeawayTimeMs: 1800000,
|
|
371
368
|
});
|
|
372
369
|
expect(result.entries[0].target_source).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.DINE_IN_PREP);
|
|
373
|
-
expect(result.counters.
|
|
374
|
-
expect(result.counters.
|
|
375
|
-
expect(result.counters.
|
|
376
|
-
expect(result.counters.promise.delta_sum).toBe(-6);
|
|
370
|
+
expect(result.counters.target.default_baseline_count).toBe(1);
|
|
371
|
+
expect(result.counters.target.on_time_count).toBe(1);
|
|
372
|
+
expect(result.counters.target.delta_sum).toBe(-6);
|
|
377
373
|
});
|
|
378
374
|
it('grades against the CONVERTED takeaway_time target, never raw milliseconds', () => {
|
|
379
375
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
@@ -388,10 +384,9 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
388
384
|
expect(result.entries[0].target_source).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TAKEAWAY_TIME);
|
|
389
385
|
expect(result.entries[0].target_at?.toISOString()).toBe('2026-09-13T09:56:00.000Z');
|
|
390
386
|
expect(result.entries[0].delta_minutes).toBe(13);
|
|
391
|
-
expect(result.counters.
|
|
392
|
-
expect(result.counters.
|
|
393
|
-
expect(result.counters.
|
|
394
|
-
expect(result.counters.promise.promise_set_count).toBe(0);
|
|
387
|
+
expect(result.counters.target.late_count).toBe(1);
|
|
388
|
+
expect(result.counters.target.delta_sum).toBe(13);
|
|
389
|
+
expect(result.counters.target.default_baseline_count).toBe(1);
|
|
395
390
|
});
|
|
396
391
|
it('grades ON TIME against a converted 30-minute takeaway_time target', () => {
|
|
397
392
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
@@ -401,9 +396,9 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
401
396
|
tenantTakeawayTimeMs: 1800000,
|
|
402
397
|
});
|
|
403
398
|
expect(result.entries[0].target_source).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TAKEAWAY_TIME);
|
|
404
|
-
expect(result.counters.
|
|
405
|
-
expect(result.counters.
|
|
406
|
-
expect(result.counters.
|
|
399
|
+
expect(result.counters.target.on_time_count).toBe(1);
|
|
400
|
+
expect(result.counters.target.late_count).toBe(0);
|
|
401
|
+
expect(result.counters.target.delta_sum).toBe(-16);
|
|
407
402
|
});
|
|
408
403
|
it('default 0 with no takeaway counts NO TARGET (never an instant default)', () => {
|
|
409
404
|
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
@@ -411,12 +406,12 @@ describe('accumulateOrderPrepTime - target grading', () => {
|
|
|
411
406
|
context,
|
|
412
407
|
tenantDefaultMinutes: 0,
|
|
413
408
|
});
|
|
414
|
-
expect(result.counters.
|
|
409
|
+
expect(result.counters.target.no_target_count).toBe(1);
|
|
415
410
|
expect(result.entries[0].target_at).toBeNull();
|
|
416
411
|
expect(result.entries[0].target_source).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.NONE);
|
|
417
|
-
expect(result.counters.
|
|
418
|
-
expect(result.counters.
|
|
419
|
-
expect(result.counters.
|
|
412
|
+
expect(result.counters.target.default_baseline_count).toBe(0);
|
|
413
|
+
expect(result.counters.target.on_time_count).toBe(0);
|
|
414
|
+
expect(result.counters.target.late_count).toBe(0);
|
|
420
415
|
});
|
|
421
416
|
});
|
|
422
417
|
describe('accumulateOrderPrepTime - drill-down rows', () => {
|
|
@@ -50,17 +50,17 @@ describe('mergeMaterializedPrepTimeCounters', () => {
|
|
|
50
50
|
source.duration.sum = 21;
|
|
51
51
|
source.duration.instant_count = 1;
|
|
52
52
|
source.duration.buckets['6-10'] = 3;
|
|
53
|
-
source.
|
|
54
|
-
source.
|
|
55
|
-
source.
|
|
53
|
+
source.target.on_time_count = 2;
|
|
54
|
+
source.target.late_count = 1;
|
|
55
|
+
source.target.delta_sum = -4;
|
|
56
56
|
(0, materialized_prep_time_compile_helpers_1.mergeMaterializedPrepTimeCounters)(target, source);
|
|
57
57
|
expect(target.coverage.item_count).toBe(5);
|
|
58
58
|
expect(target.coverage.own_anchor_count).toBe(3);
|
|
59
59
|
expect(target.duration.count).toBe(3);
|
|
60
60
|
expect(target.duration.sum).toBe(21);
|
|
61
61
|
expect(target.duration.buckets['6-10']).toBe(3);
|
|
62
|
-
expect(target.
|
|
63
|
-
expect(target.
|
|
62
|
+
expect(target.target.on_time_count).toBe(2);
|
|
63
|
+
expect(target.target.delta_sum).toBe(-4);
|
|
64
64
|
});
|
|
65
65
|
it('FOLDS min instead of summing it', () => {
|
|
66
66
|
const target = (0, materialized_prep_time_classification_helpers_1.freshMaterializedPrepTimeCounters)();
|
|
@@ -228,10 +228,9 @@ describe('compileTenantPrepTimeReports', () => {
|
|
|
228
228
|
expect(row.delta_minutes).toBe(13);
|
|
229
229
|
const dateReport = result.reports.find((doc) => doc.scope_context === 'localDate');
|
|
230
230
|
const counters = dateReport.prep_time_counters['COMPLETED:POS_WALK-IN'];
|
|
231
|
-
expect(counters.
|
|
232
|
-
expect(counters.
|
|
233
|
-
expect(counters.
|
|
234
|
-
expect(counters.promise.delta_sum).toBe(13);
|
|
231
|
+
expect(counters.target.default_baseline_count).toBe(1);
|
|
232
|
+
expect(counters.target.late_count).toBe(1);
|
|
233
|
+
expect(counters.target.delta_sum).toBe(13);
|
|
235
234
|
});
|
|
236
235
|
it('threads the dine-in prep target and the tenant default into the compiled counters', () => {
|
|
237
236
|
const dineIn = order({
|
|
@@ -245,10 +244,9 @@ describe('compileTenantPrepTimeReports', () => {
|
|
|
245
244
|
expect(row.target_at?.toISOString()).toBe('2026-09-13T10:15:00.000Z');
|
|
246
245
|
const dateReport = result.reports.find((doc) => doc.scope_context === 'localDate');
|
|
247
246
|
const counters = dateReport.prep_time_counters['COMPLETED:POS_DINE-IN'];
|
|
248
|
-
expect(counters.
|
|
249
|
-
expect(counters.
|
|
250
|
-
expect(counters.
|
|
251
|
-
expect(counters.promise.delta_sum).toBe(-6);
|
|
247
|
+
expect(counters.target.default_baseline_count).toBe(1);
|
|
248
|
+
expect(counters.target.on_time_count).toBe(1);
|
|
249
|
+
expect(counters.target.delta_sum).toBe(-6);
|
|
252
250
|
});
|
|
253
251
|
it('rejects malformed input without throwing', () => {
|
|
254
252
|
expect((0, materialized_prep_time_compile_helpers_1.compileTenantPrepTimeReports)(null)).toBeNull();
|
|
@@ -86,7 +86,6 @@ describe('prep time report constants (M2)', () => {
|
|
|
86
86
|
});
|
|
87
87
|
it('labels every on-time baseline and allows NONE (decision e2)', () => {
|
|
88
88
|
expect(MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_PREP_TIME_TARGETS).toEqual([
|
|
89
|
-
MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.PROMISE,
|
|
90
89
|
MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.DINE_IN_PREP,
|
|
91
90
|
MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TENANT_DEFAULT,
|
|
92
91
|
MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TAKEAWAY_TIME,
|
|
@@ -22,8 +22,7 @@ const counter = (over = {}) => {
|
|
|
22
22
|
order_count: 0,
|
|
23
23
|
},
|
|
24
24
|
duration: { min: 0, max: 0, sum: 0, count: 0, instant_count: 0, buckets },
|
|
25
|
-
|
|
26
|
-
promise_set_count: 0,
|
|
25
|
+
target: {
|
|
27
26
|
default_baseline_count: 0,
|
|
28
27
|
on_time_count: 0,
|
|
29
28
|
late_count: 0,
|
|
@@ -166,8 +165,7 @@ describe('prep time formatter - promise and late', () => {
|
|
|
166
165
|
doc({
|
|
167
166
|
prep_time_counters: {
|
|
168
167
|
[KEY]: counter({
|
|
169
|
-
|
|
170
|
-
promise_set_count: 5,
|
|
168
|
+
target: {
|
|
171
169
|
default_baseline_count: 2,
|
|
172
170
|
on_time_count: 4,
|
|
173
171
|
late_count: 3,
|
|
@@ -180,7 +178,6 @@ describe('prep time formatter - promise and late', () => {
|
|
|
180
178
|
}),
|
|
181
179
|
]);
|
|
182
180
|
const summary = result[0][0].summary;
|
|
183
|
-
expect(summary.promise_baseline_count).toBe(5);
|
|
184
181
|
expect(summary.default_baseline_count).toBe(2);
|
|
185
182
|
expect(summary.unmeasurable_count).toBe(8);
|
|
186
183
|
expect(summary.on_time_count).toBe(4);
|