@managesome/eposmatic-toolkit 0.4.52 → 0.4.54
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 +106 -2
- package/esm/constants/enums/delivery.js +13 -0
- package/esm/helpers/materialized-reports/index.js +6 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
- package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
- package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
- package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
- package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
- package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
- package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +508 -0
- package/esm/helpers/materialized-reports/report-platform/index.js +4 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/budget.js +27 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +12 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +121 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +14 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/index.js +8 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +10 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +42 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +28 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/top-n.js +24 -0
- package/esm/helpers/materialized-reports/report-platform/registry.js +23 -0
- package/esm/helpers/materialized-reports/report-platform/validate-report-registry.js +214 -0
- package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/esm/schemas/models/applied_order_discounts.js +103 -0
- package/esm/schemas/models/index.js +12 -10
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
- package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
- package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/esm/schemas/types/applied_order_discounts.js +1 -0
- package/esm/schemas/types/index.js +14 -12
- package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
- package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
- package/lib/constants/enums/delivery.d.ts +9 -0
- package/lib/constants/enums/delivery.js +14 -1
- package/lib/helpers/materialized-reports/index.d.ts +6 -0
- package/lib/helpers/materialized-reports/index.js +6 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
- package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
- package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
- package/lib/helpers/materialized-reports/report-platform/definition.d.ts +133 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +511 -0
- package/lib/helpers/materialized-reports/report-platform/index.d.ts +4 -0
- package/lib/helpers/materialized-reports/report-platform/index.js +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.d.ts +40 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +130 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.d.ts +22 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +17 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.js +24 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +47 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.d.ts +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.js +29 -0
- package/lib/helpers/materialized-reports/report-platform/registry.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/registry.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.js +218 -0
- package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/lib/helpers/order/payment-collection.d.ts +25 -0
- package/lib/helpers/order/payment-collection.js +51 -0
- package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
- package/lib/schemas/models/applied_order_discounts.js +106 -0
- package/lib/schemas/models/index.d.ts +12 -10
- package/lib/schemas/models/index.js +12 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
- package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
- package/lib/schemas/types/applied_order_discounts.js +2 -0
- package/lib/schemas/types/index.d.ts +14 -12
- package/lib/schemas/types/index.js +14 -12
- package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
- package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.js +229 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.js +99 -0
- package/lib/tests/materialized-reports/characterization/fixtures.d.ts +30 -0
- package/lib/tests/materialized-reports/characterization/fixtures.js +402 -0
- package/lib/tests/materialized-reports/characterization/golden.d.ts +18 -0
- package/lib/tests/materialized-reports/characterization/golden.js +127 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.js +69 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.js +102 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.js +177 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +214 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.js +103 -0
- package/lib/tests/offer-item-resolution.test.js +1 -4
- package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
- package/lib/tests/payment-collection-timestamps.test.js +71 -0
- package/package.json +6 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_reports_1 = require("../../../helpers/materialized-reports");
|
|
5
|
+
const golden_1 = require("./golden");
|
|
6
|
+
const fixtures_1 = require("./fixtures");
|
|
7
|
+
/**
|
|
8
|
+
* PREP TIME characterization — coverage counters, entry rows, targets and
|
|
9
|
+
* formatter.
|
|
10
|
+
*
|
|
11
|
+
* Current behaviour captured deliberately:
|
|
12
|
+
* - entries are ONE DOCUMENT PER SCOPE (no page partitioning, no `#N`);
|
|
13
|
+
* - the item reads are month-capped (31 effective days) at the ROUTE, not here;
|
|
14
|
+
* - MEASURED / UNMEASURED / zero-minute rows and every target source are kept.
|
|
15
|
+
*/
|
|
16
|
+
describe('characterization: Prep Time', () => {
|
|
17
|
+
const fixtures = (0, fixtures_1.buildCharacterizationFixtures)();
|
|
18
|
+
const compile = (defaultPrepMinutes, takeawayTimeMs) => (0, materialized_reports_1.compileTenantPrepTimeReports)({
|
|
19
|
+
tenantId: fixtures_1.CHARACTERIZATION_TENANT_ID,
|
|
20
|
+
brandId: fixtures_1.CHARACTERIZATION_BRAND_ID,
|
|
21
|
+
localDate: fixtures_1.CHARACTERIZATION_DAY,
|
|
22
|
+
orders: fixtures.dayOrders,
|
|
23
|
+
tenantDefaultMinutes: defaultPrepMinutes,
|
|
24
|
+
tenantTakeawayTimeMs: takeawayTimeMs,
|
|
25
|
+
computedAt: fixtures_1.CHARACTERIZATION_COMPUTED_AT,
|
|
26
|
+
});
|
|
27
|
+
const withDefault = compile(12, 900000);
|
|
28
|
+
it('compiles coverage + entries with TENANT_DEFAULT / DINE_IN_PREP targets', () => {
|
|
29
|
+
expect(withDefault).not.toBeNull();
|
|
30
|
+
(0, golden_1.expectGolden)('prep.compile.tenant-default', withDefault);
|
|
31
|
+
const dayEntries = withDefault.entries.filter((entry) => entry.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && entry.scope_field === fixtures_1.CHARACTERIZATION_DAY);
|
|
32
|
+
// One document per scope, not per source day page.
|
|
33
|
+
expect(dayEntries).toHaveLength(1);
|
|
34
|
+
expect(dayEntries[0]).not.toHaveProperty('page');
|
|
35
|
+
const targetSources = new Set(dayEntries[0].prep_time_entries == null
|
|
36
|
+
? []
|
|
37
|
+
: Object.values(dayEntries[0].prep_time_entries)
|
|
38
|
+
.flatMap((section) => section.rows ?? [])
|
|
39
|
+
.map((row) => row.target_source));
|
|
40
|
+
expect(targetSources.has('DINE_IN_PREP')).toBe(true);
|
|
41
|
+
expect(targetSources.has('TENANT_DEFAULT')).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('captures the TAKEAWAY_TIME target when no default prep is configured', () => {
|
|
44
|
+
const takeaway = compile(0, 900000);
|
|
45
|
+
(0, golden_1.expectGolden)('prep.compile.takeaway-time', takeaway);
|
|
46
|
+
const rows = collectRows(takeaway);
|
|
47
|
+
expect(rows.some((row) => row.target_source === 'TAKEAWAY_TIME')).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it('captures the NONE target when no target source is configured', () => {
|
|
50
|
+
const none = compile(0, 0);
|
|
51
|
+
(0, golden_1.expectGolden)('prep.compile.no-target', none);
|
|
52
|
+
const rows = collectRows(none);
|
|
53
|
+
expect(rows.some((row) => row.target_source === 'NONE')).toBe(true);
|
|
54
|
+
expect(rows.some((row) => row.anchor === 'MEASURED')).toBe(true);
|
|
55
|
+
expect(rows.some((row) => row.anchor === 'UNMEASURED')).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
it('builds the flat projection for every stored scope', () => {
|
|
58
|
+
const rows = [];
|
|
59
|
+
const scopes = [];
|
|
60
|
+
for (const entry of withDefault.entries) {
|
|
61
|
+
const flattened = (0, materialized_reports_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES, entry, null);
|
|
62
|
+
rows.push(...flattened.rows);
|
|
63
|
+
const scope = (0, materialized_reports_1.buildMaterializedDrilldownScope)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES, entry, flattened.rows, null);
|
|
64
|
+
if (scope != null)
|
|
65
|
+
scopes.push(scope);
|
|
66
|
+
}
|
|
67
|
+
(0, golden_1.expectGolden)('prep.flat', { rows, scopes });
|
|
68
|
+
expect(rows.length).toBeGreaterThan(0);
|
|
69
|
+
});
|
|
70
|
+
it('formats the raw day documents and the aggregated read record', () => {
|
|
71
|
+
const dayDoc = withDefault.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE &&
|
|
72
|
+
report.scope_field === fixtures_1.CHARACTERIZATION_DAY);
|
|
73
|
+
(0, golden_1.expectGolden)('prep.formatted.raw-day', (0, materialized_reports_1.getFormattedTenantPrepTimeReporting)([dayDoc]));
|
|
74
|
+
(0, golden_1.expectGolden)('prep.formatted.raw-day-filtered', (0, materialized_reports_1.getFormattedTenantPrepTimeReporting)([dayDoc], {
|
|
75
|
+
platforms: ['POS_DINE-IN', 'POS_TAKE-AWAY'],
|
|
76
|
+
order_statuses: ['COMPLETED'],
|
|
77
|
+
}));
|
|
78
|
+
const aggregated = {
|
|
79
|
+
tenant_id: dayDoc.tenant_id,
|
|
80
|
+
brand_id: dayDoc.brand_id,
|
|
81
|
+
max_iteration: dayDoc.iteration ?? 1,
|
|
82
|
+
max_updated_at: dayDoc.updatedAt ?? null,
|
|
83
|
+
matched_documents: 1,
|
|
84
|
+
sale_type_key_filters: dayDoc.sale_type_key_filters,
|
|
85
|
+
prep_time_counters: dayDoc.prep_time_counters ?? {},
|
|
86
|
+
prep_time_counter_rows: dayDoc.prep_time_counter_rows ?? [],
|
|
87
|
+
schema_version: dayDoc.schema_version ?? 1,
|
|
88
|
+
first_scope_field: dayDoc.scope_field,
|
|
89
|
+
last_scope_field: dayDoc.scope_field,
|
|
90
|
+
};
|
|
91
|
+
(0, golden_1.expectGolden)('prep.formatted.aggregated', (0, materialized_reports_1.getFormattedTenantPrepTimeAggregatedReporting)([aggregated]));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
function collectRows(compiled) {
|
|
95
|
+
const rows = [];
|
|
96
|
+
for (const entry of compiled.entries) {
|
|
97
|
+
for (const section of Object.values((entry.prep_time_entries ?? {}))) {
|
|
98
|
+
rows.push(...(section.rows ?? []));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return rows;
|
|
102
|
+
}
|
|
@@ -26,6 +26,7 @@ const delivery = (over = {}) => ({
|
|
|
26
26
|
order_id: 'order-1',
|
|
27
27
|
rider_id: 'rider-1',
|
|
28
28
|
rider_name: 'Sam',
|
|
29
|
+
order_status: 'COMPLETED',
|
|
29
30
|
status: 'COMPLETED',
|
|
30
31
|
createdAt: new Date('2026-09-14T10:05:00.000Z'),
|
|
31
32
|
updatedAt: new Date('2026-09-14T10:35:00.000Z'),
|
|
@@ -36,20 +37,28 @@ const delivery = (over = {}) => ({
|
|
|
36
37
|
localHour: 10,
|
|
37
38
|
...over,
|
|
38
39
|
});
|
|
39
|
-
const KEY = 'POS_WALK-IN:Istanbul';
|
|
40
|
+
const KEY = 'COMPLETED:POS_WALK-IN:Istanbul';
|
|
40
41
|
describe('M4 key grammar', () => {
|
|
41
|
-
it('round-trips platform:city', () => {
|
|
42
|
-
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('POS', 'Istanbul')).toBe('POS:Istanbul');
|
|
43
|
-
expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)('POS:Istanbul')).toEqual({
|
|
42
|
+
it('round-trips order_status:platform:city', () => {
|
|
43
|
+
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMPLETED', 'POS', 'Istanbul')).toBe('COMPLETED:POS:Istanbul');
|
|
44
|
+
expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)('COMPLETED:POS:Istanbul')).toEqual({
|
|
45
|
+
order_status: 'COMPLETED',
|
|
46
|
+
platform: 'POS',
|
|
47
|
+
city: 'Istanbul',
|
|
48
|
+
});
|
|
44
49
|
});
|
|
45
50
|
it('falls back to UNKNOWN rather than dropping a row with no dimension', () => {
|
|
46
|
-
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(null, 'Istanbul')).toBe('UNKNOWN:Istanbul');
|
|
47
|
-
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('POS', '')).toBe('POS:UNKNOWN');
|
|
48
|
-
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(undefined, undefined)).toBe('UNKNOWN:UNKNOWN');
|
|
51
|
+
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(null, 'POS', 'Istanbul')).toBe('UNKNOWN:POS:Istanbul');
|
|
52
|
+
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMPLETED', 'POS', '')).toBe('COMPLETED:POS:UNKNOWN');
|
|
53
|
+
expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(undefined, undefined, undefined)).toBe('UNKNOWN:UNKNOWN:UNKNOWN');
|
|
49
54
|
});
|
|
50
55
|
it('never lets the separator inside a component', () => {
|
|
51
|
-
const key = (0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('PO:S', 'Is:tanbul');
|
|
52
|
-
expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)(key)).toEqual({
|
|
56
|
+
const key = (0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMP:LETED', 'PO:S', 'Is:tanbul');
|
|
57
|
+
expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)(key)).toEqual({
|
|
58
|
+
order_status: 'COMP-LETED',
|
|
59
|
+
platform: 'PO-S',
|
|
60
|
+
city: 'Is-tanbul',
|
|
61
|
+
});
|
|
53
62
|
});
|
|
54
63
|
});
|
|
55
64
|
describe('M4 adoption', () => {
|
|
@@ -107,18 +116,46 @@ describe('M4 accumulation', () => {
|
|
|
107
116
|
expect((0, materialized_delivery_classification_helpers_1.deliveryDistanceBucketKey)(1999)).toBe('under_2km');
|
|
108
117
|
expect((0, materialized_delivery_classification_helpers_1.deliveryDistanceBucketKey)(25000)).toBe('over_25km');
|
|
109
118
|
});
|
|
110
|
-
it('builds the rider leaderboard and the area
|
|
119
|
+
it('builds the rider leaderboard and the ORDER-hour area demand heat', () => {
|
|
120
|
+
// One accumulator per ORDER_STATUS:PLATFORM:CITY key - the unit the compile builds.
|
|
121
|
+
const istanbul = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
|
|
122
|
+
const ankara = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
|
|
123
|
+
(0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(istanbul, order('order-1', { localHour: 10 }), KEY);
|
|
124
|
+
(0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(istanbul, order('order-2', { localHour: 10 }), KEY);
|
|
125
|
+
(0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(ankara, order('order-3', { localHour: 14 }), 'COMPLETED:POS:Ankara');
|
|
126
|
+
(0, materialized_delivery_classification_helpers_1.addDelivery)(istanbul, delivery({ _id: 'a', order_id: 'order-1' }), order('order-1', { localHour: 10 }), KEY);
|
|
127
|
+
(0, materialized_delivery_classification_helpers_1.addDelivery)(istanbul, delivery({ _id: 'b', order_id: 'order-2' }), order('order-2', { localHour: 10 }), KEY);
|
|
128
|
+
(0, materialized_delivery_classification_helpers_1.addDelivery)(ankara, delivery({ _id: 'c', order_id: 'order-3' }), order('order-3', { localHour: 14 }), 'COMPLETED:POS:Ankara');
|
|
129
|
+
const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(istanbul);
|
|
130
|
+
const ankaraCounters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(ankara);
|
|
131
|
+
expect(counters.riders['rider-1'].count).toBe(2);
|
|
132
|
+
expect(counters.riders['rider-1'].rider_revenue_amount).toBe(1400);
|
|
133
|
+
// areas are keyed by CITY from the JOINED key, and the hour is the ORDER's localHour.
|
|
134
|
+
expect(counters.areas['Istanbul'].by_hour['10']).toBe(2);
|
|
135
|
+
expect(ankaraCounters.areas['Ankara'].by_hour['14']).toBe(1);
|
|
136
|
+
// the area row separates ORDERS from RECORDS.
|
|
137
|
+
expect(counters.areas['Istanbul'].delivery_orders).toBe(2);
|
|
138
|
+
expect(counters.areas['Istanbul'].app_orders).toBe(2);
|
|
139
|
+
expect(counters.areas['Istanbul'].delivery_records).toBe(2);
|
|
140
|
+
expect(ankaraCounters.areas['Ankara'].delivery_records).toBe(1);
|
|
141
|
+
});
|
|
142
|
+
it('buckets demand by the ORDER local hour, never by a delivery-side clock', () => {
|
|
111
143
|
const acc = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
(0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({
|
|
144
|
+
// The delivery document happens to be stamped at 18:00 UTC, but the tenant-local
|
|
145
|
+
// order hour is 02 and that is the only hour the report may use.
|
|
146
|
+
(0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ createdAt: new Date('2026-09-14T18:05:00.000Z') }), order('order-1', { localHour: 2 }), KEY);
|
|
147
|
+
(0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(acc, order('order-1', { localHour: 2 }), KEY);
|
|
115
148
|
const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(acc);
|
|
116
|
-
expect(counters.
|
|
117
|
-
expect(counters.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
expect(counters.areas['Istanbul'].by_hour['02']).toBe(1);
|
|
150
|
+
expect(counters.areas['Istanbul'].by_hour['18']).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
it('sums refunds from the payment rows, the only declared refund source', () => {
|
|
153
|
+
const acc = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
|
|
154
|
+
(0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(acc, order('order-1', {
|
|
155
|
+
payments: [{ amount_refunded: 120 }, { amount_refunded: 80 }, { amount_refunded: 0 }],
|
|
156
|
+
}), KEY);
|
|
157
|
+
const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(acc);
|
|
158
|
+
expect(counters.money.refund_amount).toBe(200);
|
|
122
159
|
});
|
|
123
160
|
it('marks a proxy completion as NOT exact, and an explicit one as exact', () => {
|
|
124
161
|
const proxy = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_document_size_1 = require("../../helpers/materialized-reports/materialized-document-size");
|
|
5
|
+
const materialized_delivery_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-delivery-compile-helpers");
|
|
6
|
+
/**
|
|
7
|
+
* DELIVERY BSON budgets.
|
|
8
|
+
*
|
|
9
|
+
* The previous revision used a single 15 MiB "almost the Mongo limit" budget. That is not
|
|
10
|
+
* a budget: the report document must stay small over time, one entry page is bounded by
|
|
11
|
+
* one day, and a geo cell is a tiny aggregate. Each shape gets its own named budget, and
|
|
12
|
+
* the failure names the collection + day + scope.
|
|
13
|
+
*/
|
|
14
|
+
const TENANT = 'tenant-budget';
|
|
15
|
+
const BRAND = 'brand-budget';
|
|
16
|
+
const DAY = '2026-09-14';
|
|
17
|
+
const order = (id) => ({
|
|
18
|
+
_id: id,
|
|
19
|
+
tenant_id: TENANT,
|
|
20
|
+
platform: 'POS_DELIVERY',
|
|
21
|
+
order_number: 1,
|
|
22
|
+
createdAt: new Date(`${DAY}T10:00:00.000Z`),
|
|
23
|
+
localDate: DAY,
|
|
24
|
+
localHour: 10,
|
|
25
|
+
net_sale_amount: 5000,
|
|
26
|
+
amount_collected: 5000,
|
|
27
|
+
delivery_details: { city: 'Istanbul', state: 'Istanbul', delivery_cost: 300 },
|
|
28
|
+
});
|
|
29
|
+
const compile = () => (0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)({
|
|
30
|
+
tenantId: TENANT,
|
|
31
|
+
brandId: BRAND,
|
|
32
|
+
localDate: DAY,
|
|
33
|
+
orders: [order('o1')],
|
|
34
|
+
deliveries: [
|
|
35
|
+
{
|
|
36
|
+
_id: 'd1',
|
|
37
|
+
tenant_id: TENANT,
|
|
38
|
+
order_id: 'o1',
|
|
39
|
+
rider_id: 'rider-1',
|
|
40
|
+
rider_name: 'Sam',
|
|
41
|
+
status: 'COMPLETED',
|
|
42
|
+
createdAt: new Date(`${DAY}T10:05:00.000Z`),
|
|
43
|
+
updatedAt: new Date(`${DAY}T10:30:00.000Z`),
|
|
44
|
+
delivered_at: new Date(`${DAY}T10:28:00.000Z`),
|
|
45
|
+
distance_in_meters_from_store: 3000,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
computedAt: new Date(`${DAY}T23:00:00.000Z`),
|
|
49
|
+
});
|
|
50
|
+
describe('delivery BSON budgets', () => {
|
|
51
|
+
it('uses the owner-approved 15 MiB report/page budgets and 2 MiB geo budget', () => {
|
|
52
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
|
|
53
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
|
|
54
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES).toBe(2 * 1024 * 1024);
|
|
55
|
+
// MongoDB's hard limit is 16 MiB; the practical budget leaves headroom.
|
|
56
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES).toBeLessThan(16 * 1024 * 1024);
|
|
57
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES).toBeLessThan(16 * 1024 * 1024);
|
|
58
|
+
});
|
|
59
|
+
it('fails a REPORT document above the 15 MiB budget and names it', () => {
|
|
60
|
+
const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES + 1024) };
|
|
61
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(oversized)).toBeGreaterThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES);
|
|
62
|
+
expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
|
|
63
|
+
label: `materialized_tenant_delivery_reports:${TENANT}:${DAY}`,
|
|
64
|
+
maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES,
|
|
65
|
+
})).toThrow(/materialized_tenant_delivery_reports:tenant-budget:2026-09-14/);
|
|
66
|
+
});
|
|
67
|
+
it('fails an ENTRY PAGE above the 15 MiB budget and names the day + scope', () => {
|
|
68
|
+
const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES + 1024) };
|
|
69
|
+
expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
|
|
70
|
+
label: `materialized_tenant_delivery_entries:${TENANT}:${DAY}:localMonth:2026-09:page=${DAY}`,
|
|
71
|
+
maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES,
|
|
72
|
+
})).toThrow(/materialized_tenant_delivery_entries:tenant-budget:2026-09-14:localMonth:2026-09:page=2026-09-14/);
|
|
73
|
+
});
|
|
74
|
+
it('fails a GEO CELL above 2 MiB and names the cell', () => {
|
|
75
|
+
const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES + 1024) };
|
|
76
|
+
expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
|
|
77
|
+
label: 'materialized_tenant_delivery_geo_cells:tenant-budget:localDate:2026-09-14:88194ad33dfffff',
|
|
78
|
+
maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES,
|
|
79
|
+
})).toThrow(/materialized_tenant_delivery_geo_cells:tenant-budget/);
|
|
80
|
+
});
|
|
81
|
+
it('a normal day is comfortably inside every budget', () => {
|
|
82
|
+
const compiled = compile();
|
|
83
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(compiled.reports[0])).toBeLessThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES);
|
|
84
|
+
for (const page of compiled.entries) {
|
|
85
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(page)).toBeLessThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
it('REQUIRES an explicit budget (there is no silent global default)', () => {
|
|
89
|
+
expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)({ a: 1 }, { collection: 'x' })).toThrow(/explicit maxBytes budget is required/);
|
|
90
|
+
});
|
|
91
|
+
});
|