@managesome/eposmatic-toolkit 0.4.2 → 0.4.3

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.
@@ -149,10 +149,13 @@ export declare function convertMaterializedTenantSalesOverviewReportJsonToBson(r
149
149
  *
150
150
  * Returns `null` (never throws) when the inputs cannot be summed — empty list
151
151
  * or mismatched tenant / brand / schema version / key filters. `null` means a
152
- * data issue the caller must surface.
152
+ * data issue the caller must surface. Pass `allowTenantMismatch: true` for the
153
+ * brand-level combined read (cross-tenant sums; same brand / schema version /
154
+ * key filters required).
153
155
  */
154
156
  export declare function sumMaterializedTenantSalesOverviewReports(reports: IMaterializedTenantSalesOverviewReport[], options?: {
155
157
  computedAt?: Date;
158
+ allowTenantMismatch?: boolean;
156
159
  }): IMaterializedTenantSalesOverviewReport | null;
157
160
  /**
158
161
  * Subtracts `subtrahend`'s metric tree from `minuend` — the first half of the
@@ -648,6 +648,14 @@ const canMergeMaterializedReports = (base, other) => base.tenant_id === other.te
648
648
  base.brand_id === other.brand_id &&
649
649
  base.schema_version === other.schema_version &&
650
650
  base.sale_type_key_filters.join(':') === other.sale_type_key_filters.join(':');
651
+ /**
652
+ * Same brand / schema version / key filters — mergeable ACROSS tenants (the
653
+ * brand-level combined read). Order ids are unique across tenants, so the
654
+ * `(order_id, payment_id)` bill de-dupe stays correct.
655
+ */
656
+ const canMergeMaterializedReportsIgnoringTenant = (base, other) => base.brand_id === other.brand_id &&
657
+ base.schema_version === other.schema_version &&
658
+ base.sale_type_key_filters.join(':') === other.sale_type_key_filters.join(':');
651
659
  /** Sums one report's metric tree into a mutable accumulator. */
652
660
  const applyReportAddition = (metrics, report) => {
653
661
  for (const [key, metric] of Object.entries(normalizeMaterializedSaleTypeMetrics(report.sale_type_metrics))) {
@@ -725,15 +733,21 @@ const dedupeAllBillLedgers = (metrics) => {
725
733
  *
726
734
  * Returns `null` (never throws) when the inputs cannot be summed — empty list
727
735
  * or mismatched tenant / brand / schema version / key filters. `null` means a
728
- * data issue the caller must surface.
736
+ * data issue the caller must surface. Pass `allowTenantMismatch: true` for the
737
+ * brand-level combined read (cross-tenant sums; same brand / schema version /
738
+ * key filters required).
729
739
  */
730
740
  function sumMaterializedTenantSalesOverviewReports(reports, options = {}) {
731
741
  if (!Array.isArray(reports) || reports.length === 0) {
732
742
  return null;
733
743
  }
744
+ const allowTenantMismatch = options.allowTenantMismatch === true;
734
745
  const [base, ...rest] = reports;
735
746
  for (const report of rest) {
736
- if (!canMergeMaterializedReports(base, report)) {
747
+ const mergeable = allowTenantMismatch
748
+ ? canMergeMaterializedReportsIgnoringTenant(base, report)
749
+ : canMergeMaterializedReports(base, report);
750
+ if (!mergeable) {
737
751
  return null;
738
752
  }
739
753
  }
@@ -1,7 +1,7 @@
1
1
  import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_TYPE_ENUM } from '../../constants';
2
2
  /**
3
3
  * Request body contracts for the materialized reports READ APIs
4
- * (operations-service, mounted at `/materialized-reports`) — shared between
4
+ * (operations-service, mounted at `/reports`) — shared between
5
5
  * the backend service and the reports frontend so both sides agree on the
6
6
  * wire shape.
7
7
  *
@@ -12,7 +12,7 @@ import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_TYPE_ENUM } from '.
12
12
  * `IMaterializedTenantReportIteration`) — amounts are INTEGER CENTS.
13
13
  */
14
14
  /**
15
- * Body of `POST /materialized-reports/overview` — materialized sales overview
15
+ * Body of `POST /reports/overview` — materialized sales overview
16
16
  * documents (`materialized_tenant_sales_overview_reports`).
17
17
  *
18
18
  * The scope query is either the exact `scope_field`, or the inclusive
@@ -41,7 +41,7 @@ export interface IGetMaterializedTenantSalesOverviewReportsBody {
41
41
  to?: string;
42
42
  }
43
43
  /**
44
- * Body of `POST /materialized-reports/iterations` — the latest stored versions
44
+ * Body of `POST /reports/iterations` — the latest stored versions
45
45
  * of ONE report document from `materialized_tenant_reports_iterations` (the
46
46
  * shared version history of every materialized report collection). Rows
47
47
  * return newest-first, each carrying the full post-write `snapshot`.
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../../constants");
4
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
5
+ const materialized_reports_read_helpers_1 = require("../../helpers/materialized-reports/materialized-reports-read-helpers");
6
+ const tenant_sales_overview_formatter_1 = require("../../helpers/materialized-reports/tenant-sales-overview-formatter");
7
+ const ORDER_STATUS_DIM = MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS;
8
+ const PLATFORM_DIM = MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM;
9
+ const makeOrderMetric = (over = {}) => ({
10
+ count: 1,
11
+ gross_amount: 10000,
12
+ discount_amount: 0,
13
+ discount_by_type: { special_discount: 0, loyalty_discount: 0, voucher_discount: 0 },
14
+ gst_amount: 0,
15
+ tax_amount: 0,
16
+ tip_amount: 0,
17
+ tax_invoice_provider_charges: 0,
18
+ delivery_charges: 0,
19
+ ...over,
20
+ });
21
+ const makePayment = (over = {}) => ({
22
+ payment_type: 'CASH',
23
+ count: 1,
24
+ gross_amount: 9000,
25
+ amount_due: 10000,
26
+ amount_paid: 9000,
27
+ amount_refunded: 0,
28
+ card_charges: 0,
29
+ ...over,
30
+ });
31
+ // Ledger counters are recomputed from the itemized bills during the merge —
32
+ // fixtures only need to carry the bills.
33
+ const makeCreditBills = (issuedBills = [], receivedBills = []) => ({
34
+ issued: { count: 0, amount: 0, settled_count: 0, settled_amount: 0, bills: issuedBills },
35
+ received: { count: 0, amount: 0, bills: receivedBills },
36
+ });
37
+ const makeKeyMetrics = (orders, over = {}) => ({
38
+ [constants_1.REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: { orders, payments: [] },
39
+ [constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: { orders: makeOrderMetric(), payments: [] },
40
+ [constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: makeCreditBills(),
41
+ ...over,
42
+ });
43
+ const makeDoc = (over = {}) => ({
44
+ _id: 'doc',
45
+ tenant_id: 't1',
46
+ brand_id: 'b1',
47
+ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
48
+ scope_field: '2026-10-01',
49
+ day_index: constants_1.DAY_INDEX_ENUM.THU,
50
+ sale_type_key_filters: [ORDER_STATUS_DIM, PLATFORM_DIM],
51
+ sale_type_metrics: {},
52
+ iteration: 1,
53
+ schema_version: 1,
54
+ source_watermark: new Date('2026-10-01T10:00:00.000Z'),
55
+ computed_at: new Date('2026-10-01T10:00:00.000Z'),
56
+ createdAt: new Date('2026-10-01T10:00:00.000Z'),
57
+ updatedAt: new Date('2026-10-01T10:00:00.000Z'),
58
+ ...over,
59
+ });
60
+ const issuedBill = {
61
+ order_id: 'o1',
62
+ payment_id: 'p1',
63
+ amount: 11000,
64
+ received_amount: 0,
65
+ issued_at: new Date('2026-10-01T18:00:00.000Z'),
66
+ settled_at: null,
67
+ };
68
+ // Same receipt recorded in two documents — the merge must count it ONCE.
69
+ const receivedBill = {
70
+ order_id: 'o9',
71
+ payment_id: 'p9',
72
+ amount: 11000,
73
+ received_amount: 11000,
74
+ issued_local_date: '2026-09-30',
75
+ };
76
+ const docA = makeDoc({
77
+ _id: 'docA',
78
+ tenant_id: 't1',
79
+ scope_field: '2026-10-01',
80
+ day_index: constants_1.DAY_INDEX_ENUM.THU,
81
+ sale_type_metrics: {
82
+ 'COMPLETED:POS_WALK-IN': {
83
+ [constants_1.REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: {
84
+ orders: makeOrderMetric({
85
+ count: 2,
86
+ gross_amount: 20000,
87
+ discount_amount: 1000,
88
+ discount_by_type: { special_discount: 400, loyalty_discount: 300, voucher_discount: 300 },
89
+ gst_amount: 600,
90
+ tip_amount: 100,
91
+ delivery_charges: 200,
92
+ }),
93
+ payments: [
94
+ makePayment({ payment_type: 'CASH', count: 1, gross_amount: 9000 }),
95
+ makePayment({ payment_type: 'PAY_LATER', count: 1, gross_amount: 11000 }),
96
+ ],
97
+ },
98
+ [constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: {
99
+ orders: makeOrderMetric({ count: 1, gross_amount: 9000 }),
100
+ payments: [],
101
+ },
102
+ [constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: makeCreditBills([issuedBill], [receivedBill]),
103
+ },
104
+ 'CANCELLED:POS_WALK-IN': makeKeyMetrics(makeOrderMetric({ count: 1, gross_amount: 5000 })),
105
+ },
106
+ });
107
+ const docB = makeDoc({
108
+ _id: 'docB',
109
+ tenant_id: 't2',
110
+ scope_field: '2026-10-02',
111
+ day_index: constants_1.DAY_INDEX_ENUM.FRI,
112
+ sale_type_metrics: {
113
+ 'COMPLETED:POS_TAKE-AWAY': {
114
+ [constants_1.REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: {
115
+ orders: makeOrderMetric({ count: 3, gross_amount: 30000 }),
116
+ payments: [makePayment({ payment_type: 'CARD', count: 1, gross_amount: 3000 })],
117
+ },
118
+ [constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: {
119
+ orders: makeOrderMetric({ count: 3, gross_amount: 30000 }),
120
+ payments: [],
121
+ },
122
+ [constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: makeCreditBills(),
123
+ },
124
+ // Same receipt under the SAME key as in docA — the overlapping-compile case
125
+ // (e.g. a day document and a period document both carrying the key); the
126
+ // merge de-duplicates it by (order_id, payment_id).
127
+ 'COMPLETED:POS_WALK-IN': {
128
+ [constants_1.REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: {
129
+ orders: makeOrderMetric({ count: 0, gross_amount: 0 }),
130
+ payments: [],
131
+ },
132
+ [constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: {
133
+ orders: makeOrderMetric({ count: 0, gross_amount: 0 }),
134
+ payments: [],
135
+ },
136
+ [constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: makeCreditBills([], [receivedBill]),
137
+ },
138
+ },
139
+ });
140
+ const makeHourDoc = (scopeField, count) => makeDoc({
141
+ _id: `hour-${scopeField}`,
142
+ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
143
+ scope_field: scopeField,
144
+ day_index: constants_1.DAY_INDEX_ENUM.THU,
145
+ sale_type_metrics: {
146
+ 'COMPLETED:POS_WALK-IN': makeKeyMetrics(makeOrderMetric({ count })),
147
+ },
148
+ });
149
+ describe('getFormattedTenantSalesOverviewReporting', () => {
150
+ it('formats brand-combined documents (summary, cancelled split, payments, ledger, channels)', () => {
151
+ const result = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, docB]);
152
+ expect(result).not.toBeNull();
153
+ const [pageData, analysis] = result;
154
+ expect(analysis).toBeNull();
155
+ expect(pageData).toHaveLength(1);
156
+ const data = pageData[0];
157
+ expect(data.tenant_ids).toEqual(['t1', 't2']);
158
+ // Summary — non-cancelled only, cents → decimals.
159
+ expect(data.summary.count).toBe(5);
160
+ expect(data.summary.gross_amount).toBe(500);
161
+ expect(data.summary.discount_amount).toBe(10);
162
+ expect(data.summary.discount_by_type).toEqual({
163
+ special_discount: 4,
164
+ loyalty_discount: 3,
165
+ voucher_discount: 3,
166
+ });
167
+ expect(data.summary.gst_amount).toBe(6);
168
+ expect(data.summary.tip_amount).toBe(1);
169
+ expect(data.summary.delivery_charges).toBe(2);
170
+ // Cancelled facet from the CANCELLED:* keys.
171
+ expect(data.cancelled.count).toBe(1);
172
+ expect(data.cancelled.gross_amount).toBe(50);
173
+ // Amount collected slot.
174
+ expect(data.amount_collected.count).toBe(4);
175
+ expect(data.amount_collected.gross_amount).toBe(390);
176
+ // Payments: UNPAID first, then the rest (count desc / name asc), settlement appended.
177
+ expect(data.payments.map((payment) => payment.payment_type)).toEqual([
178
+ 'UNPAID',
179
+ 'CARD',
180
+ 'CASH',
181
+ 'CREDIT_SETTLEMENT',
182
+ ]);
183
+ expect(data.payments[0].gross_amount).toBe(110);
184
+ const settlement = data.payments[3];
185
+ expect(settlement.derived).toBe(true);
186
+ expect(settlement.count).toBe(1); // de-duplicated across documents
187
+ expect(settlement.gross_amount).toBe(110);
188
+ // Credit-bill ledger (counters recomputed from the de-duplicated bills).
189
+ expect(data.credit_bills.issued).toEqual({
190
+ count: 1,
191
+ amount: 110,
192
+ settled_count: 0,
193
+ settled_amount: 0,
194
+ });
195
+ expect(data.credit_bills.received).toEqual({ count: 1, amount: 110 });
196
+ expect(data.credit_bills.outstanding_amount).toBe(110);
197
+ // Channels — count desc.
198
+ expect(data.channels.map((channel) => channel.platform)).toEqual(['POS_TAKE-AWAY', 'POS_WALK-IN']);
199
+ expect(data.channels[0]).toMatchObject({
200
+ order_from: 'Pos',
201
+ order_type: 'Take-away',
202
+ count: 3,
203
+ gross_amount: 300,
204
+ });
205
+ // Weekday groups (date scope), ordered SUN…SAT.
206
+ expect(data.weekday?.map((day) => day.day_index)).toEqual([constants_1.DAY_INDEX_ENUM.THU, constants_1.DAY_INDEX_ENUM.FRI]);
207
+ expect(data.weekday?.[0].metric.count).toBe(2);
208
+ expect(data.weekday?.[1].metric.count).toBe(3);
209
+ expect(data.hourly).toBeNull();
210
+ });
211
+ it('applies platform / order-status / weekday filters to the key map', () => {
212
+ const [platformFiltered] = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, docB], {
213
+ platforms: ['POS_WALK-IN'],
214
+ });
215
+ const data = platformFiltered[0];
216
+ expect(data.summary.count).toBe(2);
217
+ expect(data.summary.gross_amount).toBe(200);
218
+ expect(data.cancelled.count).toBe(1);
219
+ expect(data.channels.map((channel) => channel.platform)).toEqual(['POS_WALK-IN']);
220
+ expect(data.payments.map((payment) => payment.payment_type)).toEqual(['UNPAID', 'CASH', 'CREDIT_SETTLEMENT']);
221
+ const [statusFiltered] = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, docB], {
222
+ order_statuses: ['CANCELLED'],
223
+ });
224
+ expect(statusFiltered[0].summary.count).toBe(0);
225
+ expect(statusFiltered[0].cancelled.count).toBe(1);
226
+ const [weekdayFiltered] = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, docB], {
227
+ day_indexes: [constants_1.DAY_INDEX_ENUM.FRI],
228
+ });
229
+ expect(weekdayFiltered[0].tenant_ids).toEqual(['t2']);
230
+ expect(weekdayFiltered[0].summary.count).toBe(3);
231
+ expect(weekdayFiltered[0].weekday?.map((day) => day.day_index)).toEqual([constants_1.DAY_INDEX_ENUM.FRI]);
232
+ });
233
+ it('orders hour points by business-hour index across the 06:00 boundary', () => {
234
+ const result = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([
235
+ makeHourDoc('2026-10-01 22', 1),
236
+ makeHourDoc('2026-10-01 23', 1),
237
+ makeHourDoc('2026-10-01 00', 1),
238
+ makeHourDoc('2026-10-01 01', 1),
239
+ ]);
240
+ const [pageData] = result;
241
+ const data = pageData[0];
242
+ expect(data.hourly?.map((point) => point.hour)).toEqual([22, 23, 0, 1]);
243
+ expect(data.hourly?.map((point) => point.business_hour_index)).toEqual([16, 17, 18, 19]);
244
+ expect(data.hourly?.map((point) => point.local_date)).toEqual([
245
+ '2026-10-01',
246
+ '2026-10-01',
247
+ '2026-10-01',
248
+ '2026-10-01',
249
+ ]);
250
+ expect(data.hourly?.[0].metric.count).toBe(1);
251
+ // Weekday grouping also works for hour scopes.
252
+ expect(data.weekday).toEqual([expect.objectContaining({ day_index: constants_1.DAY_INDEX_ENUM.THU })]);
253
+ expect(data.weekday?.[0].metric.count).toBe(4);
254
+ });
255
+ it('merges hour buckets across tenants in combined reads', () => {
256
+ const result = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([
257
+ makeHourDoc('2026-10-01 22', 1),
258
+ makeDoc({
259
+ _id: 'hour-t2',
260
+ tenant_id: 't2',
261
+ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
262
+ scope_field: '2026-10-01 22',
263
+ day_index: constants_1.DAY_INDEX_ENUM.THU,
264
+ sale_type_metrics: {
265
+ 'COMPLETED:POS_WALK-IN': makeKeyMetrics(makeOrderMetric({ count: 2 })),
266
+ },
267
+ }),
268
+ ]);
269
+ const [pageData] = result;
270
+ expect(pageData[0].hourly).toHaveLength(1);
271
+ expect(pageData[0].hourly?.[0].metric.count).toBe(3);
272
+ expect(pageData[0].tenant_ids).toEqual(['t1', 't2']);
273
+ });
274
+ it('returns separate per-tenant views when requested', () => {
275
+ const [pageData] = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, docB], null, true);
276
+ expect(pageData).toHaveLength(2);
277
+ expect(pageData[0].tenant_ids).toEqual(['t1']);
278
+ expect(pageData[0].summary.count).toBe(2);
279
+ expect(pageData[1].tenant_ids).toEqual(['t2']);
280
+ expect(pageData[1].summary.count).toBe(3);
281
+ });
282
+ it('returns a zero-filled page for an empty document list', () => {
283
+ const [pageData] = (0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([]);
284
+ expect(pageData).toHaveLength(1);
285
+ expect(pageData[0]).toMatchObject({
286
+ tenant_ids: [],
287
+ summary: { count: 0, gross_amount: 0 },
288
+ payments: [],
289
+ channels: [],
290
+ weekday: null,
291
+ hourly: null,
292
+ });
293
+ });
294
+ it('returns null for unformattable input', () => {
295
+ expect((0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)(null)).toBeNull();
296
+ expect((0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, null])).toBeNull();
297
+ // Mixed scope contexts.
298
+ expect((0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, makeHourDoc('2026-10-01 18', 1)])).toBeNull();
299
+ // Mixed key filters.
300
+ const reversedKeys = makeDoc({
301
+ sale_type_key_filters: [PLATFORM_DIM, ORDER_STATUS_DIM],
302
+ });
303
+ expect((0, tenant_sales_overview_formatter_1.getFormattedTenantSalesOverviewReporting)([docA, reversedKeys])).toBeNull();
304
+ });
305
+ });
306
+ describe('materialized reports read helpers', () => {
307
+ it('computes the business-hour index (06…23, 00…05)', () => {
308
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(6)).toBe(0);
309
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(23)).toBe(17);
310
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(0)).toBe(18);
311
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(5)).toBe(23);
312
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(24)).toBeNull();
313
+ expect((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(1.5)).toBeNull();
314
+ });
315
+ it('expands recurring hour windows (incl. the wrap across midnight)', () => {
316
+ const evening = (0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01', '2026-10-02'], 16, 20);
317
+ expect(evening).toEqual([
318
+ '2026-10-01 16',
319
+ '2026-10-01 17',
320
+ '2026-10-01 18',
321
+ '2026-10-01 19',
322
+ '2026-10-02 16',
323
+ '2026-10-02 17',
324
+ '2026-10-02 18',
325
+ '2026-10-02 19',
326
+ ]);
327
+ const wrapped = (0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01'], 22, 2);
328
+ expect(wrapped).toEqual(['2026-10-01 22', '2026-10-01 23', '2026-10-01 00', '2026-10-01 01']);
329
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01'], 0, 24)).toHaveLength(24);
330
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01'], 16, 16)).toBeNull();
331
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-02-31'], 16, 20)).toBeNull();
332
+ // Windows crossing the 06:00 business-morning boundary span two label days
333
+ // — rejected instead of silently mislabelled.
334
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01'], 4, 8)).toBeNull();
335
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(['2026-10-01'], 5, 7)).toBeNull();
336
+ });
337
+ it('derives fetch spans and filters documents by scope fields', () => {
338
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourScopeSpan)(['2026-10-02', '2026-10-01'])).toEqual({
339
+ from: '2026-10-01 00',
340
+ to: '2026-10-02 23',
341
+ });
342
+ expect((0, materialized_reports_read_helpers_1.getMaterializedHourScopeSpan)([])).toBeNull();
343
+ expect((0, materialized_reports_read_helpers_1.getMaterializedScopeSpan)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH, ['2026-10', '2026-01'])).toEqual({
344
+ from: '2026-01',
345
+ to: '2026-10',
346
+ });
347
+ expect((0, materialized_reports_read_helpers_1.getMaterializedScopeSpan)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, ['2026-10-01 00'])).toBeNull();
348
+ const kept = (0, materialized_reports_read_helpers_1.filterMaterializedTenantSalesOverviewReportsByScopeFields)([docA, docB], ['2026-10-02']);
349
+ expect(kept?.map((doc) => doc._id)).toEqual(['docB']);
350
+ expect((0, materialized_reports_read_helpers_1.filterMaterializedTenantSalesOverviewReportsByScopeFields)(null, [])).toBeNull();
351
+ });
352
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",