@managesome/eposmatic-toolkit 0.4.54 → 0.4.56
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 +91 -0
- package/esm/helpers/materialized-reports/index.js +7 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +18 -0
- package/esm/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +100 -0
- package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +328 -0
- package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +180 -0
- package/esm/helpers/materialized-reports/materialized-dialer-entry-pages.js +222 -0
- package/esm/helpers/materialized-reports/materialized-dialer-key-helpers.js +82 -0
- package/esm/helpers/materialized-reports/materialized-dialer-masking.js +54 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
- package/esm/helpers/materialized-reports/report-platform/definition.js +85 -1
- package/esm/helpers/materialized-reports/tenant-dialer-formatter.js +95 -0
- package/esm/helpers/reporting-contract/report-contract.js +3 -0
- package/esm/schemas/models/index.js +3 -0
- package/esm/schemas/models/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/models/materialized_tenant_dialer_entries.js +65 -0
- package/esm/schemas/models/materialized_tenant_dialer_reports.js +66 -0
- package/esm/schemas/models/tenant_dialer_events.js +133 -0
- package/esm/schemas/types/index.js +3 -0
- package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/types/materialized_tenant_dialer_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_dialer_reports.js +7 -0
- package/esm/schemas/types/tenant_dialer_events.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +72 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +93 -1
- package/lib/helpers/materialized-reports/index.d.ts +7 -0
- package/lib/helpers/materialized-reports/index.js +7 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +1 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +19 -0
- package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.d.ts +39 -0
- package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +110 -0
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.d.ts +90 -0
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +340 -0
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.d.ts +67 -0
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +183 -0
- package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.d.ts +97 -0
- package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.js +235 -0
- package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.d.ts +51 -0
- package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.js +90 -0
- package/lib/helpers/materialized-reports/materialized-dialer-masking.d.ts +35 -0
- package/lib/helpers/materialized-reports/materialized-dialer-masking.js +57 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
- package/lib/helpers/materialized-reports/report-platform/definition.js +84 -0
- package/lib/helpers/materialized-reports/tenant-dialer-formatter.d.ts +91 -0
- package/lib/helpers/materialized-reports/tenant-dialer-formatter.js +98 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
- package/lib/helpers/reporting-contract/report-contract.js +3 -0
- package/lib/schemas/models/index.d.ts +3 -0
- package/lib/schemas/models/index.js +3 -0
- package/lib/schemas/models/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +107 -0
- package/lib/schemas/models/materialized_tenant_dialer_entries.js +68 -0
- package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +100 -0
- package/lib/schemas/models/materialized_tenant_dialer_reports.js +69 -0
- package/lib/schemas/models/tenant-activity-logs.d.ts +3 -3
- package/lib/schemas/models/tenant_dialer_events.d.ts +130 -0
- package/lib/schemas/models/tenant_dialer_events.js +136 -0
- package/lib/schemas/models/warehouse-activity-logs.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +3 -0
- package/lib/schemas/types/index.js +3 -0
- package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
- package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/types/materialized_tenant_dialer_entries.d.ts +83 -0
- package/lib/schemas/types/materialized_tenant_dialer_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_dialer_reports.d.ts +77 -0
- package/lib/schemas/types/materialized_tenant_dialer_reports.js +10 -0
- package/lib/schemas/types/tenant_dialer_events.d.ts +35 -0
- package/lib/schemas/types/tenant_dialer_events.js +2 -0
- package/lib/tests/materialized-reports/materialized-dialer-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-compile.test.js +213 -0
- package/lib/tests/materialized-reports/materialized-dialer-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-formatter.test.js +159 -0
- package/lib/tests/materialized-reports/materialized-dialer-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-plan.test.js +223 -0
- package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.js +183 -0
- package/lib/tests/materialized-reports/materialized-wipe-tooling.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-wipe-tooling.test.js +37 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +16 -3
- package/lib/tests/tenant-dialer-events-schema.test.d.ts +1 -0
- package/lib/tests/tenant-dialer-events-schema.test.js +191 -0
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_tenant_dialer_entries_1 = require("../../schemas/models/materialized_tenant_dialer_entries");
|
|
5
|
+
const materialized_tenant_dialer_reports_1 = require("../../schemas/models/materialized_tenant_dialer_reports");
|
|
6
|
+
const definition_1 = require("../../helpers/materialized-reports/report-platform/definition");
|
|
7
|
+
const validate_report_registry_1 = require("../../helpers/materialized-reports/report-platform/validate-report-registry");
|
|
8
|
+
const report_contract_1 = require("../../helpers/reporting-contract/report-contract");
|
|
9
|
+
/**
|
|
10
|
+
* Dialer schema + registry contract.
|
|
11
|
+
*
|
|
12
|
+
* Indexes are DECLARED here, never created: the model must not call `.index()`
|
|
13
|
+
* and no service runs `ensureIndexes`. Applying them is an owner deploy step.
|
|
14
|
+
*/
|
|
15
|
+
describe('dialer schema contract', () => {
|
|
16
|
+
it('declares the two primary collections and their unique identities', () => {
|
|
17
|
+
expect(materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME).toBe('materialized_tenant_dialer_reports');
|
|
18
|
+
expect(materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME).toBe('materialized_tenant_dialer_entries');
|
|
19
|
+
expect(materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION).toBe(1);
|
|
20
|
+
expect(materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION).toBe(1);
|
|
21
|
+
expect(materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_INDEXES.tenant_id__scope_context__scope_field__day_index).toEqual({
|
|
22
|
+
tenant_id: 1,
|
|
23
|
+
scope_context: 1,
|
|
24
|
+
scope_field: 1,
|
|
25
|
+
day_index: 1,
|
|
26
|
+
});
|
|
27
|
+
expect(materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS).toEqual([
|
|
28
|
+
{
|
|
29
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
|
|
30
|
+
name: 'tenant_id__scope_context__scope_field__day_index',
|
|
31
|
+
unique: true,
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
expect(materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_INDEXES.tenant_id__scope_context__scope_field__page).toEqual({
|
|
35
|
+
tenant_id: 1,
|
|
36
|
+
scope_context: 1,
|
|
37
|
+
scope_field: 1,
|
|
38
|
+
page: 1,
|
|
39
|
+
});
|
|
40
|
+
expect(materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS).toEqual([
|
|
41
|
+
{
|
|
42
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, page: 1 },
|
|
43
|
+
name: 'tenant_id__scope_context__scope_field__page',
|
|
44
|
+
unique: true,
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
it('declares its scopes, key filters and report types', () => {
|
|
49
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_SCOPES).toEqual([
|
|
50
|
+
'localDate',
|
|
51
|
+
'localWeek',
|
|
52
|
+
'localWeekOfYear',
|
|
53
|
+
'localMonth',
|
|
54
|
+
'localQuarter',
|
|
55
|
+
'localSemester',
|
|
56
|
+
'localYear',
|
|
57
|
+
]);
|
|
58
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_SCOPES).toEqual(['localDate', 'localWeek', 'localWeekOfYear', 'localMonth']);
|
|
59
|
+
expect(MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS).toEqual(['ACTION', 'POS_ID', 'STAFF_ID']);
|
|
60
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_REPORTS).toBe('TENANT_DIALER_REPORTS');
|
|
61
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES).toBe('TENANT_DIALER_ENTRIES');
|
|
62
|
+
});
|
|
63
|
+
it('declares the identity fields and defaults on the models', () => {
|
|
64
|
+
const reportPaths = Object.keys(materialized_tenant_dialer_reports_1.MaterializedTenantDialerReportSchema.paths);
|
|
65
|
+
expect(reportPaths).toEqual(expect.arrayContaining([
|
|
66
|
+
'tenant_id',
|
|
67
|
+
'brand_id',
|
|
68
|
+
'scope_context',
|
|
69
|
+
'scope_field',
|
|
70
|
+
'day_index',
|
|
71
|
+
'sale_type_key_filters',
|
|
72
|
+
'dialer_counters',
|
|
73
|
+
'schema_version',
|
|
74
|
+
'source_watermark',
|
|
75
|
+
'computed_at',
|
|
76
|
+
]));
|
|
77
|
+
expect(materialized_tenant_dialer_reports_1.MaterializedTenantDialerReportSchema.path('sale_type_key_filters').defaultValue()).toEqual(MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS);
|
|
78
|
+
const entryPaths = Object.keys(materialized_tenant_dialer_entries_1.MaterializedTenantDialerEntriesSchema.paths);
|
|
79
|
+
expect(entryPaths).toEqual(expect.arrayContaining(['page', 'dialer_entries', 'schema_version', 'source_watermark', 'computed_at']));
|
|
80
|
+
expect(entryPaths).not.toContain('sale_type_key_filters');
|
|
81
|
+
});
|
|
82
|
+
it('keeps the approved raw contract: no duration, order attribution, geo or raw phone', () => {
|
|
83
|
+
const reportPaths = Object.keys(materialized_tenant_dialer_reports_1.MaterializedTenantDialerReportSchema.paths);
|
|
84
|
+
const entryPaths = Object.keys(materialized_tenant_dialer_entries_1.MaterializedTenantDialerEntriesSchema.paths);
|
|
85
|
+
for (const forbidden of [
|
|
86
|
+
'duration',
|
|
87
|
+
'duration_seconds',
|
|
88
|
+
'call_duration',
|
|
89
|
+
'answer_rate',
|
|
90
|
+
'missed_rate',
|
|
91
|
+
'order_id',
|
|
92
|
+
'phone_number',
|
|
93
|
+
'staff_phone',
|
|
94
|
+
'location',
|
|
95
|
+
'h3_cell',
|
|
96
|
+
]) {
|
|
97
|
+
expect(reportPaths).not.toContain(forbidden);
|
|
98
|
+
expect(entryPaths).not.toContain(forbidden);
|
|
99
|
+
}
|
|
100
|
+
// The entry row carries MASKED phones only.
|
|
101
|
+
const rowShape = {
|
|
102
|
+
event_id: 'e',
|
|
103
|
+
request_id: 'r',
|
|
104
|
+
action: 'INCOMING_CALL',
|
|
105
|
+
phone_number_masked: '+********4567',
|
|
106
|
+
staff_id: null,
|
|
107
|
+
staff_phone_masked: null,
|
|
108
|
+
pos_id: 'POS-01',
|
|
109
|
+
created_at: '2026-09-14T05:00:00.000Z',
|
|
110
|
+
local_date: '2026-09-14',
|
|
111
|
+
local_hour: 10,
|
|
112
|
+
};
|
|
113
|
+
expect(Object.keys(rowShape).sort()).toEqual([
|
|
114
|
+
'action',
|
|
115
|
+
'created_at',
|
|
116
|
+
'event_id',
|
|
117
|
+
'local_date',
|
|
118
|
+
'local_hour',
|
|
119
|
+
'phone_number_masked',
|
|
120
|
+
'pos_id',
|
|
121
|
+
'request_id',
|
|
122
|
+
'staff_id',
|
|
123
|
+
'staff_phone_masked',
|
|
124
|
+
]);
|
|
125
|
+
// No geo projection is registered for this report.
|
|
126
|
+
expect(definition_1.REPORT_DEFINITIONS[report_contract_1.REPORT_KEY_ENUM.DIALER].projections).toEqual([definition_1.REPORT_PROJECTION.FLAT_DRILLDOWN]);
|
|
127
|
+
expect(definition_1.REPORT_DEFINITIONS[report_contract_1.REPORT_KEY_ENUM.DIALER].sideCollections.map((collection) => collection.name)).toEqual([
|
|
128
|
+
'materialized_report_drilldown_rows',
|
|
129
|
+
'materialized_report_drilldown_scopes',
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('dialer report definition', () => {
|
|
134
|
+
const definition = definition_1.REPORT_DEFINITIONS[report_contract_1.REPORT_KEY_ENUM.DIALER];
|
|
135
|
+
it('is a registered production report with the shared contract', () => {
|
|
136
|
+
expect(definition).toBeDefined();
|
|
137
|
+
expect(definition.status).toBe(definition_1.REPORT_DEFINITION_STATUS.PRODUCTION);
|
|
138
|
+
expect(definition.segment).toBe('dialer');
|
|
139
|
+
expect(report_contract_1.REPORT_ROUTE_SEGMENTS[report_contract_1.REPORT_KEY_ENUM.DIALER]).toBe('dialer');
|
|
140
|
+
expect(report_contract_1.REPORT_CAPABILITIES[report_contract_1.REPORT_KEY_ENUM.DIALER]).toEqual({
|
|
141
|
+
live: true,
|
|
142
|
+
historical: true,
|
|
143
|
+
details: true,
|
|
144
|
+
});
|
|
145
|
+
expect(definition.capabilities).toEqual(report_contract_1.REPORT_CAPABILITIES[report_contract_1.REPORT_KEY_ENUM.DIALER]);
|
|
146
|
+
});
|
|
147
|
+
it('declares page-per-source-day entries with deterministic sub-pages and a flat projection', () => {
|
|
148
|
+
expect(definition.entryStorage).toBe(definition_1.REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY);
|
|
149
|
+
expect(definition.entrySplit).toBe(definition_1.REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES);
|
|
150
|
+
expect(definition.maxReportScope).toBe('localYear');
|
|
151
|
+
expect(definition.maxEntryScope).toBe('localMonth');
|
|
152
|
+
expect(definition.projections).toEqual([definition_1.REPORT_PROJECTION.FLAT_DRILLDOWN]);
|
|
153
|
+
expect(definition.entryScopes).toEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_SCOPES);
|
|
154
|
+
expect(definition.reportScopes).toEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_SCOPES);
|
|
155
|
+
});
|
|
156
|
+
it('declares server-side key filter dimensions and the report adapter ids', () => {
|
|
157
|
+
expect(definition.filters.map((filter) => filter.id)).toEqual(expect.arrayContaining(['ACTION', 'POS_ID', 'STAFF_ID', 'DETAILS_VIEW']));
|
|
158
|
+
for (const id of ['ACTION', 'POS_ID', 'STAFF_ID']) {
|
|
159
|
+
const filter = definition.filters.find((entry) => entry.id === id);
|
|
160
|
+
expect(filter.mode).toBe('SERVER');
|
|
161
|
+
expect(filter.kind).toBe('KEY_COMPONENT');
|
|
162
|
+
expect(filter.appliesTo).toBe('BOTH');
|
|
163
|
+
}
|
|
164
|
+
expect(definition.adapters).toEqual({
|
|
165
|
+
writer: 'materializeDialerReport',
|
|
166
|
+
live: 'getLiveTenantDialerReports',
|
|
167
|
+
historical: 'getMaterializedTenantDialerReports',
|
|
168
|
+
details: 'getMaterializedDialerDetailsPage',
|
|
169
|
+
});
|
|
170
|
+
expect(definition.cursor).toBe('KEYSET_STRUCTURED');
|
|
171
|
+
});
|
|
172
|
+
it('keeps the declarative registry valid', () => {
|
|
173
|
+
const validation = (0, validate_report_registry_1.validateReportRegistry)();
|
|
174
|
+
expect(validation.errors).toEqual([]);
|
|
175
|
+
expect(validate_report_registry_1.REPORT_REGISTRY_VALIDATION.ok).toBe(true);
|
|
176
|
+
// Validator debt is declared explicitly (no new schema validator was written):
|
|
177
|
+
// the report, the entries, and the two shared flat side collections.
|
|
178
|
+
const dialerWarnings = validation.warnings.filter((warning) => warning.startsWith('DIALER:'));
|
|
179
|
+
expect(dialerWarnings).toHaveLength(4);
|
|
180
|
+
expect(dialerWarnings[0]).toContain('report validator debt');
|
|
181
|
+
expect(dialerWarnings[1]).toContain('entries validator debt');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const materialized_delivery_wipe_targets_1 = require("../../helpers/materialized-reports/materialized-delivery-wipe-targets");
|
|
4
|
+
/**
|
|
5
|
+
* PHASE 5 — operator wipe safety is pure and database-free. These tests only
|
|
6
|
+
* build/validate the target list; they never connect to MongoDB.
|
|
7
|
+
*/
|
|
8
|
+
describe('Delivery wipe target safety', () => {
|
|
9
|
+
it('accepts every real Delivery wipe target and only materialized collections', () => {
|
|
10
|
+
const targets = (0, materialized_delivery_wipe_targets_1.buildDeliveryMaterializationWipeTargets)('tenant-1');
|
|
11
|
+
expect(() => (0, materialized_delivery_wipe_targets_1.assertMaterializedWipeTargets)(targets)).not.toThrow();
|
|
12
|
+
for (const target of targets) {
|
|
13
|
+
expect(target.name.startsWith('materialized_')).toBe(true);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
it('refuses a source collection', () => {
|
|
17
|
+
expect(() => (0, materialized_delivery_wipe_targets_1.assertMaterializedWipeTargets)([{ name: 'orders', filter: { tenant_id: 'tenant-1' } }])).toThrow(/not a materialized/);
|
|
18
|
+
});
|
|
19
|
+
it('refuses a filter outside tenant/report identity', () => {
|
|
20
|
+
expect(() => (0, materialized_delivery_wipe_targets_1.assertMaterializedWipeTargets)([
|
|
21
|
+
{
|
|
22
|
+
name: 'materialized_tenant_delivery_reports',
|
|
23
|
+
filter: { tenant_id: 'tenant-1', order_id: 'order-1' },
|
|
24
|
+
},
|
|
25
|
+
])).toThrow(/forbidden key/);
|
|
26
|
+
});
|
|
27
|
+
it('builds tenant-scoped and all-tenant targets without source collections', () => {
|
|
28
|
+
for (const targets of [
|
|
29
|
+
(0, materialized_delivery_wipe_targets_1.buildDeliveryMaterializationWipeTargets)(),
|
|
30
|
+
(0, materialized_delivery_wipe_targets_1.buildDeliveryMaterializationWipeTargets)('tenant-1'),
|
|
31
|
+
]) {
|
|
32
|
+
expect(() => (0, materialized_delivery_wipe_targets_1.assertMaterializedWipeTargets)(targets)).not.toThrow();
|
|
33
|
+
expect(targets.map((target) => target.name)).not.toContain('orders');
|
|
34
|
+
expect(targets.map((target) => target.name)).not.toContain('deliveries');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -49,6 +49,8 @@ const prepEntryModel = __importStar(require("../../../schemas/models/materialize
|
|
|
49
49
|
const deliveryReportModel = __importStar(require("../../../schemas/models/materialized_tenant_delivery_reports"));
|
|
50
50
|
const deliveryEntryModel = __importStar(require("../../../schemas/models/materialized_tenant_delivery_entries"));
|
|
51
51
|
const deliveryGeoModel = __importStar(require("../../../schemas/models/materialized_tenant_delivery_geo_cells"));
|
|
52
|
+
const dialerReportModel = __importStar(require("../../../schemas/models/materialized_tenant_dialer_reports"));
|
|
53
|
+
const dialerEntryModel = __importStar(require("../../../schemas/models/materialized_tenant_dialer_entries"));
|
|
52
54
|
const flatModel = __importStar(require("../../../schemas/models/materialized_report_drilldown_rows"));
|
|
53
55
|
const definition_1 = require("../../../helpers/materialized-reports/report-platform/definition");
|
|
54
56
|
const registry_1 = require("../../../helpers/materialized-reports/report-platform/registry");
|
|
@@ -110,6 +112,16 @@ const MODEL_BY_COLLECTION = {
|
|
|
110
112
|
schemaVersion: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_SCHEMA_VERSION,
|
|
111
113
|
indexOptions: [],
|
|
112
114
|
},
|
|
115
|
+
materialized_tenant_dialer_reports: {
|
|
116
|
+
collectionName: dialerReportModel.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME,
|
|
117
|
+
schemaVersion: dialerReportModel.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION,
|
|
118
|
+
indexOptions: dialerReportModel.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS,
|
|
119
|
+
},
|
|
120
|
+
materialized_tenant_dialer_entries: {
|
|
121
|
+
collectionName: dialerEntryModel.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME,
|
|
122
|
+
schemaVersion: dialerEntryModel.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION,
|
|
123
|
+
indexOptions: dialerEntryModel.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS,
|
|
124
|
+
},
|
|
113
125
|
materialized_report_drilldown_rows: {
|
|
114
126
|
collectionName: flatModel.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME,
|
|
115
127
|
schemaVersion: flatModel.MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
@@ -127,15 +139,16 @@ const definitionCollections = () => definition_1.PRODUCTION_REPORT_DEFINITIONS.f
|
|
|
127
139
|
...definition.sideCollections,
|
|
128
140
|
]);
|
|
129
141
|
describe('report registry conformance', () => {
|
|
130
|
-
it('defines exactly the
|
|
142
|
+
it('defines exactly the production reports', () => {
|
|
131
143
|
expect(definition_1.PRODUCTION_REPORT_DEFINITIONS.map((definition) => definition.key)).toEqual([
|
|
132
144
|
report_contract_1.REPORT_KEY_ENUM.OVERVIEW,
|
|
133
145
|
report_contract_1.REPORT_KEY_ENUM.DISCOUNTS,
|
|
134
146
|
report_contract_1.REPORT_KEY_ENUM.PREP_TIME,
|
|
135
147
|
report_contract_1.REPORT_KEY_ENUM.DELIVERY,
|
|
148
|
+
report_contract_1.REPORT_KEY_ENUM.DIALER,
|
|
136
149
|
]);
|
|
137
|
-
expect((0, registry_1.getProductionReportDefinitions)()).toHaveLength(
|
|
138
|
-
expect(new Set(definition_1.PRODUCTION_REPORT_DEFINITIONS.map((definition) => definition.key)).size).toBe(
|
|
150
|
+
expect((0, registry_1.getProductionReportDefinitions)()).toHaveLength(5);
|
|
151
|
+
expect(new Set(definition_1.PRODUCTION_REPORT_DEFINITIONS.map((definition) => definition.key)).size).toBe(5);
|
|
139
152
|
expect(definition_1.PRODUCTION_REPORT_DEFINITIONS.every((definition) => definition.status === 'PRODUCTION')).toBe(true);
|
|
140
153
|
});
|
|
141
154
|
it('covers every REPORT_KEY with a definition or an explicit exemption', () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tenant_dialer_events_1 = require("../schemas/models/tenant_dialer_events");
|
|
9
|
+
const Model = mongoose_1.default.models[tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME] ??
|
|
10
|
+
mongoose_1.default.model(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME, tenant_dialer_events_1.TenantDialerEventSchema, tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME);
|
|
11
|
+
const LOCAL_TIME_FIELDS = [
|
|
12
|
+
'day_index',
|
|
13
|
+
'localSecond',
|
|
14
|
+
'localMinute',
|
|
15
|
+
'localHour',
|
|
16
|
+
'localDay',
|
|
17
|
+
'localWeek',
|
|
18
|
+
'localWeekOfYear',
|
|
19
|
+
'localMonth',
|
|
20
|
+
'localQuarter',
|
|
21
|
+
'localSemester',
|
|
22
|
+
'localYear',
|
|
23
|
+
'localDate',
|
|
24
|
+
'localTime',
|
|
25
|
+
'localDayOfYear',
|
|
26
|
+
];
|
|
27
|
+
/** Source fields only — a valid un-attributed event. Proves the `Partial` type. */
|
|
28
|
+
const baseRow = () => ({
|
|
29
|
+
_id: new mongoose_1.default.Types.ObjectId().toString(),
|
|
30
|
+
tenant_id: 'tenant-dialer-events',
|
|
31
|
+
request_id: 'call-123:INCOMING_CALL',
|
|
32
|
+
action: constants_1.DIALER_TYPES_ENUM.INCOMING_CALL,
|
|
33
|
+
phone_number: '+923001234567',
|
|
34
|
+
pos_id: 'pos-1',
|
|
35
|
+
staff_id: null,
|
|
36
|
+
staff_phone: null,
|
|
37
|
+
schema_version: 1,
|
|
38
|
+
createdAt: new Date('2026-03-10T20:30:45.000Z'),
|
|
39
|
+
updatedAt: new Date('2026-03-10T20:30:45.000Z'),
|
|
40
|
+
});
|
|
41
|
+
const localFields = () => ({
|
|
42
|
+
day_index: constants_1.DAY_INDEX_ENUM.TUE,
|
|
43
|
+
localSecond: 45,
|
|
44
|
+
localMinute: 30,
|
|
45
|
+
localHour: 1,
|
|
46
|
+
localDay: 2,
|
|
47
|
+
localWeek: 2,
|
|
48
|
+
localWeekOfYear: 11,
|
|
49
|
+
localMonth: 3,
|
|
50
|
+
localQuarter: 1,
|
|
51
|
+
localSemester: 1,
|
|
52
|
+
localYear: 2026,
|
|
53
|
+
localDate: '2026-03-10',
|
|
54
|
+
localTime: '01:30:45',
|
|
55
|
+
localDayOfYear: 69,
|
|
56
|
+
});
|
|
57
|
+
const attributedRow = () => ({ ...baseRow(), ...localFields() });
|
|
58
|
+
describe('tenant_dialer_events schema', () => {
|
|
59
|
+
it('exposes the agreed collection name', () => {
|
|
60
|
+
expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME).toBe('tenant_dialer_events');
|
|
61
|
+
});
|
|
62
|
+
it('is an un-attributed-valid Partial<ILocalTimeFields> event', () => {
|
|
63
|
+
// `baseRow()` has NO local-time fields and still satisfies the event type.
|
|
64
|
+
const unAttributed = baseRow();
|
|
65
|
+
expect(new Model(unAttributed).validateSync()).toBeUndefined();
|
|
66
|
+
for (const field of LOCAL_TIME_FIELDS) {
|
|
67
|
+
const path = tenant_dialer_events_1.TenantDialerEventSchema.path(field);
|
|
68
|
+
expect(path).toBeDefined();
|
|
69
|
+
expect(path.options.required).toBeFalsy();
|
|
70
|
+
expect(unAttributed).not.toHaveProperty(field);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
it('validates a fully attributed source event with every local-time field', () => {
|
|
74
|
+
const doc = new Model(attributedRow());
|
|
75
|
+
expect(doc.validateSync()).toBeUndefined();
|
|
76
|
+
const stored = doc.toObject();
|
|
77
|
+
expect(stored).toMatchObject({
|
|
78
|
+
tenant_id: 'tenant-dialer-events',
|
|
79
|
+
request_id: 'call-123:INCOMING_CALL',
|
|
80
|
+
action: constants_1.DIALER_TYPES_ENUM.INCOMING_CALL,
|
|
81
|
+
phone_number: '+923001234567',
|
|
82
|
+
pos_id: 'pos-1',
|
|
83
|
+
staff_id: null,
|
|
84
|
+
staff_phone: null,
|
|
85
|
+
schema_version: 1,
|
|
86
|
+
localDate: '2026-03-10',
|
|
87
|
+
localTime: '01:30:45',
|
|
88
|
+
day_index: constants_1.DAY_INDEX_ENUM.TUE,
|
|
89
|
+
localSecond: 45,
|
|
90
|
+
localMinute: 30,
|
|
91
|
+
localHour: 1,
|
|
92
|
+
localDay: 2,
|
|
93
|
+
localWeek: 2,
|
|
94
|
+
localWeekOfYear: 11,
|
|
95
|
+
localMonth: 3,
|
|
96
|
+
localQuarter: 1,
|
|
97
|
+
localSemester: 1,
|
|
98
|
+
localYear: 2026,
|
|
99
|
+
localDayOfYear: 69,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it('has NO received_at and NO running_day_missing', () => {
|
|
103
|
+
expect(tenant_dialer_events_1.TenantDialerEventSchema.path('received_at')).toBeUndefined();
|
|
104
|
+
expect(tenant_dialer_events_1.TenantDialerEventSchema.path('running_day_missing')).toBeUndefined();
|
|
105
|
+
expect(attributedRow()).not.toHaveProperty('received_at');
|
|
106
|
+
expect(attributedRow()).not.toHaveProperty('running_day_missing');
|
|
107
|
+
});
|
|
108
|
+
it('keeps createdAt as the canonical receipt time (required, immutable)', () => {
|
|
109
|
+
const path = tenant_dialer_events_1.TenantDialerEventSchema.path('createdAt');
|
|
110
|
+
expect(path).toBeDefined();
|
|
111
|
+
expect(path.options.required).toBeTruthy();
|
|
112
|
+
expect(path.options.immutable).toBe(true);
|
|
113
|
+
const row = { ...baseRow() };
|
|
114
|
+
delete row.createdAt;
|
|
115
|
+
// Defaults fill the canonical time when omitted on a direct create.
|
|
116
|
+
expect(new Model(row).createdAt).toBeInstanceOf(Date);
|
|
117
|
+
});
|
|
118
|
+
it('accepts every DIALER_TYPES_ENUM action', () => {
|
|
119
|
+
for (const action of constants_1.ALL_DIALER_TYPE_EVENTS) {
|
|
120
|
+
const doc = new Model({ ...baseRow(), action });
|
|
121
|
+
expect(doc.validateSync()).toBeUndefined();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
it('rejects an unknown action', () => {
|
|
125
|
+
const error = new Model({ ...baseRow(), action: 'NOT_A_DIALER_ACTION' }).validateSync();
|
|
126
|
+
expect(error?.errors).toHaveProperty('action');
|
|
127
|
+
});
|
|
128
|
+
it('rejects invalid local-time values but allows the fields to be absent', () => {
|
|
129
|
+
const badHour = new Model({ ...attributedRow(), localHour: 25 }).validateSync();
|
|
130
|
+
expect(badHour?.errors).toHaveProperty('localHour');
|
|
131
|
+
const badDate = new Model({ ...attributedRow(), localDate: undefined }).validateSync();
|
|
132
|
+
expect(badDate).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
it('does not weaken the required source fields', () => {
|
|
135
|
+
for (const field of ['tenant_id', 'request_id', 'action', 'phone_number', 'pos_id']) {
|
|
136
|
+
const row = { ...baseRow() };
|
|
137
|
+
delete row[field];
|
|
138
|
+
expect(new Model(row).validateSync()?.errors).toHaveProperty(field);
|
|
139
|
+
}
|
|
140
|
+
for (const field of [
|
|
141
|
+
'tenant_id',
|
|
142
|
+
'request_id',
|
|
143
|
+
'action',
|
|
144
|
+
'phone_number',
|
|
145
|
+
'pos_id',
|
|
146
|
+
'schema_version',
|
|
147
|
+
'createdAt',
|
|
148
|
+
'updatedAt',
|
|
149
|
+
]) {
|
|
150
|
+
const path = tenant_dialer_events_1.TenantDialerEventSchema.path(field);
|
|
151
|
+
expect(path).toBeDefined();
|
|
152
|
+
expect(path.options.required).toBeTruthy();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
it('keeps staff fields nullable', () => {
|
|
156
|
+
expect(new Model(baseRow()).get('staff_id')).toBeNull();
|
|
157
|
+
expect(new Model(baseRow()).get('staff_phone')).toBeNull();
|
|
158
|
+
expect(new Model({ ...baseRow(), staff_id: 'staff-1', staff_phone: '+923007654321' }).validateSync()).toBeUndefined();
|
|
159
|
+
});
|
|
160
|
+
it('enforces schema_version = 1', () => {
|
|
161
|
+
expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_SCHEMA_VERSION).toBe(1);
|
|
162
|
+
expect(new Model({ ...baseRow(), schema_version: 2 }).validateSync()?.errors).toHaveProperty('schema_version');
|
|
163
|
+
});
|
|
164
|
+
it('does NOT declare duration_seconds (derived later, never stored)', () => {
|
|
165
|
+
expect(tenant_dialer_events_1.TenantDialerEventSchema.path('duration_seconds')).toBeUndefined();
|
|
166
|
+
expect(attributedRow()).not.toHaveProperty('duration_seconds');
|
|
167
|
+
});
|
|
168
|
+
it('declares the unique ingestion index plus the two source-read indexes', () => {
|
|
169
|
+
expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_INDEXES).toEqual({
|
|
170
|
+
_id: { _id: 1 },
|
|
171
|
+
tenant_id__request_id: { tenant_id: 1, request_id: 1 },
|
|
172
|
+
tenant_id__localDate__action: { tenant_id: 1, localDate: 1, action: 1 },
|
|
173
|
+
tenant_id__phone_number__createdAt: { tenant_id: 1, phone_number: 1, createdAt: 1 },
|
|
174
|
+
});
|
|
175
|
+
expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_INDEX_OPTIONS).toEqual([
|
|
176
|
+
{
|
|
177
|
+
key: { tenant_id: 1, request_id: 1 },
|
|
178
|
+
name: 'tenant_id__request_id',
|
|
179
|
+
unique: true,
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
key: { tenant_id: 1, localDate: 1, action: 1 },
|
|
183
|
+
name: 'tenant_id__localDate__action',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
key: { tenant_id: 1, phone_number: 1, createdAt: 1 },
|
|
187
|
+
name: 'tenant_id__phone_number__createdAt',
|
|
188
|
+
},
|
|
189
|
+
]);
|
|
190
|
+
});
|
|
191
|
+
});
|