@managesome/eposmatic-toolkit 0.4.52 → 0.4.53

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.
Files changed (107) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +106 -2
  2. package/esm/constants/enums/delivery.js +13 -0
  3. package/esm/helpers/materialized-reports/index.js +5 -0
  4. package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  5. package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
  6. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
  7. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
  8. package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
  9. package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
  10. package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
  11. package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
  12. package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
  13. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
  14. package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  15. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
  16. package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
  17. package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
  18. package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  19. package/esm/schemas/models/applied_order_discounts.js +103 -0
  20. package/esm/schemas/models/index.js +12 -10
  21. package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
  22. package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
  23. package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
  24. package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  25. package/esm/schemas/types/applied_order_discounts.js +1 -0
  26. package/esm/schemas/types/index.js +14 -12
  27. package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
  28. package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
  29. package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
  30. package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
  31. package/lib/constants/enums/delivery.d.ts +9 -0
  32. package/lib/constants/enums/delivery.js +14 -1
  33. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  34. package/lib/helpers/materialized-reports/index.js +5 -0
  35. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  36. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
  37. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
  38. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
  39. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
  40. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
  41. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
  42. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
  43. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
  44. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
  45. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
  46. package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
  47. package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
  48. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
  49. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
  50. package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
  51. package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
  52. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
  53. package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  54. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
  55. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
  56. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
  57. package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
  58. package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
  59. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
  60. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  61. package/lib/helpers/order/payment-collection.d.ts +25 -0
  62. package/lib/helpers/order/payment-collection.js +51 -0
  63. package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
  64. package/lib/schemas/models/applied_order_discounts.js +106 -0
  65. package/lib/schemas/models/index.d.ts +12 -10
  66. package/lib/schemas/models/index.js +12 -10
  67. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
  68. package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
  69. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
  70. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
  71. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
  72. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
  73. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
  74. package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  75. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
  76. package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
  77. package/lib/schemas/types/applied_order_discounts.js +2 -0
  78. package/lib/schemas/types/index.d.ts +14 -12
  79. package/lib/schemas/types/index.js +14 -12
  80. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
  81. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
  82. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
  83. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
  84. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
  85. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
  86. package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
  87. package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
  88. package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
  89. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
  90. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
  91. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
  92. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
  93. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
  94. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
  95. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
  96. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
  97. package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
  98. package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
  99. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
  100. package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
  101. package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
  102. package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
  103. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
  104. package/lib/tests/offer-item-resolution.test.js +1 -4
  105. package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
  106. package/lib/tests/payment-collection-timestamps.test.js +71 -0
  107. package/package.json +4 -2
@@ -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({ platform: 'POS', city: 'Istanbul' });
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({ platform: 'PO-S', city: 'Is-tanbul' });
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 hour heat map', () => {
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
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'a', localHour: 10 }), null, KEY);
113
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'b', localHour: 10 }), null, KEY);
114
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'c', localHour: 14 }), null, 'POS:Ankara');
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.riders['rider-1'].count).toBe(3);
117
- expect(counters.riders['rider-1'].rider_revenue_amount).toBe(2100);
118
- // areas are keyed by CITY from the JOINED key.
119
- expect(counters.areas['Istanbul'].by_hour['10']).toBe(2);
120
- expect(counters.areas['Ankara'].by_hour['14']).toBe(1);
121
- expect(counters.areas['Istanbul'].count).toBe(2);
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,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
+ });
@@ -17,6 +17,7 @@ const order = (id, over = {}) => ({
17
17
  _id: id,
18
18
  tenant_id: TENANT,
19
19
  platform: 'POS_WALK-IN',
20
+ order_status: 'COMPLETED',
20
21
  order_number: 100,
21
22
  createdAt: new Date('2026-09-14T10:00:00.000Z'),
22
23
  net_sale_amount: 5000,
@@ -54,7 +55,50 @@ const compile = (over = {}) => (0, materialized_delivery_compile_helpers_1.compi
54
55
  computedAt: new Date('2026-09-14T23:00:00.000Z'),
55
56
  ...over,
56
57
  });
58
+ /** The DAY entry page (`page='all'`) - the row set every other entry page retargets. */
59
+ const dayEntry = (compiled) => compiled.entries.find((entry) => String(entry.scope_context) === 'localDate');
57
60
  describe('M4 day compile', () => {
61
+ it('uses the same delivery-charge and city/state fallbacks as the counter', () => {
62
+ const compiled = (0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)({
63
+ tenantId: 't',
64
+ brandId: 'b',
65
+ localDate: '2026-09-14',
66
+ orders: [
67
+ {
68
+ _id: 'o-fallback',
69
+ tenant_id: 't',
70
+ platform: 'POS_DELIVERY',
71
+ order_status: 'COMPLETED',
72
+ createdAt: new Date('2026-09-14T10:00:00.000Z'),
73
+ localDate: '2026-09-14',
74
+ localHour: 10,
75
+ localMinute: 30,
76
+ net_sale_amount: 1000,
77
+ amount_collected: 1000,
78
+ delivery_details: { state: 'Ankara', delivery_charge: 250 },
79
+ },
80
+ ],
81
+ deliveries: [
82
+ {
83
+ _id: 'd-fallback',
84
+ tenant_id: 't',
85
+ order_id: 'o-fallback',
86
+ rider_id: 'r1',
87
+ status: 'COMPLETED',
88
+ createdAt: new Date('2026-09-14T10:05:00.000Z'),
89
+ updatedAt: new Date('2026-09-14T10:30:00.000Z'),
90
+ delivered_at: new Date('2026-09-14T10:28:00.000Z'),
91
+ localDate: '2026-09-14',
92
+ },
93
+ ],
94
+ computedAt: new Date('2026-09-14T23:00:00.000Z'),
95
+ });
96
+ const row = Object.values(compiled.entries[0].delivery_entries ?? {}).flatMap((section) => section.rows)[0];
97
+ expect(row.city).toBe('Ankara');
98
+ expect(row.delivery_charge).toBe(250);
99
+ expect(row.local_hour).toBe('2026-09-14 10:30');
100
+ expect(Object.values(compiled.reports[0].delivery_counters)[0].money.delivery_charge_amount).toBe(250);
101
+ });
58
102
  it('returns null only when there is NEITHER an order NOR a delivery', () => {
59
103
  expect(compile()).toBeNull();
60
104
  expect(compile({ orders: [order('o')] })).not.toBeNull();
@@ -62,51 +106,100 @@ describe('M4 day compile', () => {
62
106
  expect((0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)(null)).toBeNull();
63
107
  expect(compile({ tenantId: '' })).toBeNull();
64
108
  });
109
+ it('emits ONE page per entry scope, with the page rules of the discounts split', () => {
110
+ const compiled = compile({
111
+ orders: [order('o1')],
112
+ deliveries: [delivery({ order_id: 'o1' })],
113
+ });
114
+ const byScope = new Map(compiled.entries.map((entry) => [String(entry.scope_context), entry]));
115
+ expect([...byScope.keys()].sort()).toEqual(['localDate', 'localMonth', 'localWeek', 'localWeekOfYear']);
116
+ expect(byScope.get('localDate').page).toBe('all');
117
+ expect(byScope.get('localDate').scope_field).toBe(DAY);
118
+ expect(byScope.get('localWeek').page).toBe(DAY);
119
+ expect(byScope.get('localWeekOfYear').page).toBe(DAY);
120
+ expect(byScope.get('localMonth').page).toBe(DAY);
121
+ expect(byScope.get('localMonth').scope_field).toBe('2026-09');
122
+ // No quarter / semester / year entry document exists at ANY time.
123
+ for (const forbidden of ['localQuarter', 'localSemester', 'localYear']) {
124
+ expect(byScope.has(forbidden)).toBe(false);
125
+ }
126
+ });
127
+ it('a MONTH of closes produces one month page per source day', () => {
128
+ const monthPages = [];
129
+ for (let day = 1; day <= 30; day += 1) {
130
+ const localDate = `2026-09-${String(day).padStart(2, '0')}`;
131
+ const compiled = (0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)({
132
+ tenantId: TENANT,
133
+ brandId: BRAND,
134
+ localDate,
135
+ orders: [order(`o-${day}`, { localDate })],
136
+ deliveries: [],
137
+ computedAt: new Date(`${localDate}T23:00:00.000Z`),
138
+ });
139
+ monthPages.push(compiled.entries.find((entry) => String(entry.scope_context) === 'localMonth'));
140
+ }
141
+ expect(monthPages).toHaveLength(30);
142
+ expect(new Set(monthPages.map((page) => page.page)).size).toBe(30);
143
+ expect(new Set(monthPages.map((page) => page.scope_field))).toEqual(new Set(['2026-09']));
144
+ // never one document holding the month's rows
145
+ expect(monthPages.every((page) => page.page !== '2026-09')).toBe(true);
146
+ });
147
+ it('puts the SAME day rows on every page - a page is never a folded period', () => {
148
+ const compiled = compile({
149
+ orders: [order('o1')],
150
+ deliveries: [delivery({ _id: 'd1', order_id: 'o1' })],
151
+ });
152
+ for (const entry of compiled.entries) {
153
+ const rows = Object.values(entry.delivery_entries ?? {}).flatMap((section) => section.rows);
154
+ expect(rows.map((row) => row.delivery_id)).toEqual(['d1']);
155
+ expect(entry.off_app_order_count).toBe(0);
156
+ }
157
+ });
65
158
  it('reports an adoption-POOR day: orders, no deliveries', () => {
66
159
  const compiled = compile({ orders: [order('o1'), order('o2')] });
67
- const counters = compiled.reports[0].delivery_counters['POS_WALK-IN:Istanbul'];
160
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
68
161
  expect(counters.adoption.delivery_order_count).toBe(2);
69
162
  expect(counters.adoption.delivered_via_app_count).toBe(0);
70
163
  // the app has won NOTHING yet - the pool is the whole day.
71
164
  expect(counters.adoption.off_app_count).toBe(2);
72
165
  expect(counters.deliveries.count).toBe(0);
73
166
  // and the entries document carries the count, because off-app orders are not rows.
74
- expect(compiled.entries[0].off_app_order_count).toBe(2);
75
- expect(compiled.entries[0].delivery_entries).toBeNull();
167
+ expect(dayEntry(compiled).off_app_order_count).toBe(2);
168
+ expect(dayEntry(compiled).delivery_entries).toBeNull();
76
169
  });
77
170
  it('reports an adoption-RICH day', () => {
78
171
  const compiled = compile({
79
172
  orders: [order('o1'), order('o2')],
80
173
  deliveries: [delivery({ _id: 'd1', order_id: 'o1' }), delivery({ _id: 'd2', order_id: 'o2' })],
81
174
  });
82
- const counters = compiled.reports[0].delivery_counters['POS_WALK-IN:Istanbul'];
175
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
83
176
  expect(counters.adoption.delivery_order_count).toBe(2);
84
177
  expect(counters.adoption.delivered_via_app_count).toBe(2);
85
178
  expect(counters.adoption.off_app_count).toBe(0);
86
- expect(compiled.entries[0].off_app_order_count).toBe(0);
179
+ expect(dayEntry(compiled).off_app_order_count).toBe(0);
87
180
  });
88
181
  it('keys a delivery on its ORDER, not on the delivery', () => {
89
182
  const compiled = compile({
90
183
  orders: [order('o1', { platform: 'DELIVEROO', delivery_details: { city: 'Ankara', delivery_cost: 500 } })],
91
184
  deliveries: [delivery({ order_id: 'o1' })],
92
185
  });
93
- expect(Object.keys(compiled.reports[0].delivery_counters)).toEqual(['DELIVEROO:Ankara']);
186
+ expect(Object.keys(compiled.reports[0].delivery_counters)).toEqual(['COMPLETED:DELIVEROO:Ankara']);
94
187
  });
95
188
  it('puts a delivery with an unstaged order in UNKNOWN rather than dropping it', () => {
96
189
  const compiled = compile({ deliveries: [delivery({ order_id: 'not-staged' })] });
97
190
  const keys = Object.keys(compiled.reports[0].delivery_counters);
98
- expect(keys).toEqual(['UNKNOWN:UNKNOWN']);
191
+ expect(keys).toEqual(['UNKNOWN:UNKNOWN:UNKNOWN']);
99
192
  // it is a real row a rider performed, so it counts as a delivery...
100
- expect(compiled.reports[0].delivery_counters['UNKNOWN:UNKNOWN'].deliveries.count).toBe(1);
193
+ expect(compiled.reports[0].delivery_counters['UNKNOWN:UNKNOWN:UNKNOWN'].deliveries.count).toBe(1);
101
194
  // ...but it cannot claim adoption for an order we never staged.
102
- expect(compiled.reports[0].delivery_counters['UNKNOWN:UNKNOWN'].adoption.delivery_order_count).toBe(0);
195
+ expect(compiled.reports[0].delivery_counters['UNKNOWN:UNKNOWN:UNKNOWN'].adoption.delivery_order_count).toBe(0);
103
196
  });
104
197
  it('builds statement rows with the joined order fields', () => {
105
198
  const compiled = compile({
106
199
  orders: [order('o1')],
107
200
  deliveries: [delivery({ order_id: 'o1' })],
108
201
  });
109
- const rows = Object.values(compiled.entries[0].delivery_entries).flatMap((section) => section.rows);
202
+ const rows = Object.values(dayEntry(compiled).delivery_entries).flatMap((section) => section.rows);
110
203
  expect(rows).toHaveLength(1);
111
204
  const row = rows[0];
112
205
  expect(row.order_id).toBe('o1');
@@ -125,7 +218,7 @@ describe('M4 day compile', () => {
125
218
  order('o1', {
126
219
  tip_amount: 500,
127
220
  total_discount_applied: 200,
128
- amount_refunded: 100,
221
+ payments: [{ amount_refunded: 60 }, { amount_refunded: 40 }],
129
222
  gst_amount: 300,
130
223
  tax_amount: 100,
131
224
  delivery_details: {
@@ -146,7 +239,7 @@ describe('M4 day compile', () => {
146
239
  }),
147
240
  ],
148
241
  });
149
- const counters = compiled.reports[0].delivery_counters['POS_WALK-IN:Istanbul'];
242
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
150
243
  expect(counters.money.tip_amount).toBe(500);
151
244
  expect(counters.money.discount_amount).toBe(200);
152
245
  expect(counters.money.refund_amount).toBe(100);
@@ -186,7 +279,7 @@ describe('M4 day compile', () => {
186
279
  }),
187
280
  ],
188
281
  });
189
- const timing = compiled.reports[0].delivery_counters['POS_WALK-IN:Istanbul'].timing;
282
+ const timing = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'].timing;
190
283
  expect(timing.promise_known_count).toBe(1);
191
284
  expect(timing.on_time_count).toBe(1);
192
285
  expect(timing.late_count).toBe(0);
@@ -207,7 +300,7 @@ describe('M4 day compile', () => {
207
300
  const compiled = compile({
208
301
  deliveries: [delivery({ rider_earnings: snapshot(status) })],
209
302
  });
210
- return Object.values(compiled.entries[0].delivery_entries).flatMap((section) => section.rows)[0];
303
+ return Object.values(dayEntry(compiled).delivery_entries).flatMap((section) => section.rows)[0];
211
304
  };
212
305
  expect(rowFor(delivery_1.RIDER_EARNINGS_STATUS_ENUM.PENDING).rider_revenue).toBeNull();
213
306
  expect(rowFor(delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL).rider_revenue).toBe(900);
@@ -233,10 +326,173 @@ describe('M4 day compile', () => {
233
326
  });
234
327
  expect(Object.values(final.reports[0].delivery_counters)[0].money.rider_revenue_amount).toBe(900);
235
328
  });
329
+ it('counts ONLY orders that carry delivery_details (DINE / walk-in are excluded)', () => {
330
+ const dineIn = order('dine-1', {
331
+ platform: 'POS_DINE-IN',
332
+ delivery_details: null,
333
+ dinein_details: { floor_id: 'f1', table_id: 't1', table_name: 'T1', num_of_guests: 2 },
334
+ });
335
+ const walkIn = order('walk-1', { platform: 'POS_WALK-IN', delivery_details: null });
336
+ const deliveryOrder = order('delivery-1');
337
+ const compiled = compile({ orders: [dineIn, walkIn, deliveryOrder], deliveries: [] });
338
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
339
+ expect(counters.adoption.delivery_order_count).toBe(1);
340
+ expect(counters.adoption.off_app_count).toBe(1);
341
+ expect(counters.money.net_sale_amount).toBe(5000);
342
+ expect(dayEntry(compiled).off_app_order_count).toBe(1);
343
+ });
344
+ it('keeps the three populations distinct under REASSIGNMENT', () => {
345
+ // o1 was reassigned (two attempts), o2 was delivered once, o3 never reached the app.
346
+ const compiled = compile({
347
+ orders: [order('o1'), order('o2'), order('o3')],
348
+ deliveries: [
349
+ delivery({ _id: 'd1', order_id: 'o1', rider_id: 'rider-1' }),
350
+ delivery({ _id: 'd2', order_id: 'o1', rider_id: 'rider-2', status: 'CANCELLED' }),
351
+ delivery({ _id: 'd3', order_id: 'o2', rider_id: 'rider-1' }),
352
+ ],
353
+ });
354
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
355
+ expect(counters.adoption.delivery_order_count).toBe(3); // unique ORDERS
356
+ expect(counters.adoption.delivered_via_app_count).toBe(2); // unique app orders
357
+ expect(counters.adoption.off_app_count).toBe(1); // o3, never off-app by reassignment
358
+ expect(counters.deliveries.count).toBe(3); // ATTEMPTS, one order contributed two
359
+ expect(counters.deliveries.cancelled_count).toBe(1);
360
+ // and the area row carries the same split.
361
+ expect(counters.areas['Istanbul'].delivery_orders).toBe(3);
362
+ expect(counters.areas['Istanbul'].app_orders).toBe(2);
363
+ expect(counters.areas['Istanbul'].off_app_orders).toBe(1);
364
+ expect(counters.areas['Istanbul'].delivery_records).toBe(3);
365
+ // adoption can never exceed 100 %.
366
+ expect(counters.adoption.delivered_via_app_count).toBeLessThanOrEqual(counters.adoption.delivery_order_count);
367
+ });
368
+ it('caps the RIDER leaderboard at the document level, deterministically', () => {
369
+ const orders = [];
370
+ const deliveries = [];
371
+ for (let index = 1; index <= 51; index += 1) {
372
+ const id = `cap-order-${index}`;
373
+ orders.push(order(id));
374
+ deliveries.push(delivery({
375
+ _id: `cap-delivery-${index}`,
376
+ order_id: id,
377
+ rider_id: `rider-${String(index).padStart(2, '0')}`,
378
+ }));
379
+ }
380
+ const compiled = compile({ orders, deliveries });
381
+ const counters = Object.values(compiled.reports[0].delivery_counters)[0];
382
+ const riderIds = Object.keys(counters.riders);
383
+ expect(riderIds).toHaveLength(51); // top 50 + __OTHER__
384
+ expect(riderIds).toContain('__OTHER__');
385
+ // ties break on rider id ASC, so the LAST rider is the one folded away.
386
+ expect(riderIds).toContain('rider-50');
387
+ expect(riderIds).not.toContain('rider-51');
388
+ expect(counters.riders['__OTHER__'].count).toBe(1);
389
+ expect(counters.deliveries.count).toBe(51);
390
+ });
391
+ it('folds cities beyond the top 50 into __OTHER__, keeping the totals exact', () => {
392
+ const orders = [];
393
+ for (let index = 1; index <= 51; index += 1) {
394
+ orders.push(order(`city-order-${index}`, {
395
+ delivery_details: {
396
+ city: `City-${String(index).padStart(2, '0')}`,
397
+ state: 'State',
398
+ delivery_cost: 300,
399
+ },
400
+ }));
401
+ }
402
+ const compiled = compile({ orders });
403
+ const counters = compiled.reports[0].delivery_counters;
404
+ const keys = Object.keys(counters);
405
+ expect(keys).toHaveLength(51); // top 50 cities + one __OTHER__ key
406
+ expect(keys).toContain('COMPLETED:POS_WALK-IN:__OTHER__');
407
+ expect(counters['COMPLETED:POS_WALK-IN:__OTHER__'].areas['__OTHER__'].delivery_orders).toBe(1);
408
+ const totalOrders = Object.values(counters).reduce((sum, block) => sum + block.adoption.delivery_order_count, 0);
409
+ expect(totalOrders).toBe(51);
410
+ expect(dayEntry(compiled).off_app_order_count).toBe(51);
411
+ });
412
+ it('includes OFF-APP order money in delivery sales, but no app-side payout', () => {
413
+ const compiled = compile({
414
+ orders: [order('o1'), order('o2')],
415
+ // only o1 reached the app; o2 is off-app and must still be a delivery sale.
416
+ deliveries: [delivery({ _id: 'd1', order_id: 'o1' })],
417
+ });
418
+ const counters = compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'];
419
+ // 2 x 5000 cents - the sale exists whether or not the rider app saw it.
420
+ expect(counters.money.net_sale_amount).toBe(10000);
421
+ expect(counters.money.delivery_charge_amount).toBe(600);
422
+ // rider payout comes ONLY from the one app record.
423
+ expect(counters.money.rider_revenue_amount).toBe(700);
424
+ // the off-app order is not a row.
425
+ expect(dayEntry(compiled).off_app_order_count).toBe(1);
426
+ expect(Object.values(dayEntry(compiled).delivery_entries).flatMap((section) => section.rows)).toHaveLength(1);
427
+ });
428
+ it('grades on-time / late ONLY against an explicit ETA', () => {
429
+ const explicit = compile({
430
+ orders: [
431
+ order('o1', {
432
+ delivery_details: {
433
+ city: 'Istanbul',
434
+ state: 'Istanbul',
435
+ delivery_cost: 300,
436
+ estimated_delivery_time: new Date('2026-09-14T10:30:00.000Z'),
437
+ },
438
+ }),
439
+ ],
440
+ deliveries: [delivery({ _id: 'd1', order_id: 'o1', delivered_at: new Date('2026-09-14T10:32:00.000Z') })],
441
+ });
442
+ const timing = Object.values(explicit.reports[0].delivery_counters)[0].timing;
443
+ expect(timing.promise_known_count).toBe(1);
444
+ expect(timing.late_count).toBe(1);
445
+ expect(timing.on_time_count).toBe(0);
446
+ expect(timing.late_minutes_sum).toBe(2);
447
+ // NO ETA anywhere: the delivery is completed but UNGRADED - not counted as on time.
448
+ const asap = compile({
449
+ orders: [order('o1')],
450
+ deliveries: [delivery({ _id: 'd1', order_id: 'o1' })],
451
+ });
452
+ const asapTiming = Object.values(asap.reports[0].delivery_counters)[0].timing;
453
+ expect(asapTiming.promise_known_count).toBe(0);
454
+ expect(asapTiming.on_time_count).toBe(0);
455
+ expect(asapTiming.late_count).toBe(0);
456
+ });
457
+ it('takes the LOCAL HOUR from the joined order, never from the delivery clock', () => {
458
+ const compiled = compile({
459
+ // 02:00 tenant-local, while the delivery document was written at 18:05 UTC.
460
+ orders: [order('o1', { localHour: 2 })],
461
+ deliveries: [
462
+ delivery({
463
+ _id: 'd1',
464
+ order_id: 'o1',
465
+ createdAt: new Date('2026-09-14T18:05:00.000Z'),
466
+ }),
467
+ ],
468
+ });
469
+ const row = Object.values(dayEntry(compiled).delivery_entries)
470
+ .flatMap((section) => section.rows)
471
+ .find((entry) => entry.delivery_id === 'd1');
472
+ // No localMinute on the order: keep the HOUR-ONLY stamp (never a false :00),
473
+ // so the UI's hour-only offset branch stays correct.
474
+ expect(row.local_hour).toBe(DAY + ' 02');
475
+ expect(Object.values(compiled.reports[0].delivery_counters)[0].areas['Istanbul'].by_hour['02']).toBe(1);
476
+ expect(Object.values(compiled.reports[0].delivery_counters)[0].areas['Istanbul'].by_hour['18']).toBeUndefined();
477
+ // A delivery whose order was not staged has NO local hour - not a server-time guess.
478
+ const orphan = compile({ deliveries: [delivery({ _id: 'd2', order_id: 'missing' })] });
479
+ const orphanRow = Object.values(dayEntry(orphan).delivery_entries).flatMap((section) => section.rows)[0];
480
+ expect(orphanRow.local_hour).toBeNull();
481
+ });
482
+ it('counts an orphan delivery as an app RECORD in the UNKNOWN area', () => {
483
+ const compiled = compile({ deliveries: [delivery({ _id: 'd1', order_id: 'missing' })] });
484
+ const counters = compiled.reports[0].delivery_counters['UNKNOWN:UNKNOWN:UNKNOWN'];
485
+ expect(counters.deliveries.count).toBe(1);
486
+ // it cannot be an APP ORDER: adoption is order-based and its order is not staged.
487
+ expect(counters.adoption.delivery_order_count).toBe(0);
488
+ expect(counters.adoption.delivered_via_app_count).toBe(0);
489
+ expect(counters.areas['UNKNOWN'].delivery_records).toBe(1);
490
+ expect(counters.money.net_sale_amount).toBe(0);
491
+ });
236
492
  it('never lets a FOREIGN tenant into the documents', () => {
237
493
  const compiled = compile({
238
494
  orders: [order('o1'), order('o2', { tenant_id: 'someone-else' })],
239
495
  });
240
- expect(compiled.reports[0].delivery_counters['POS_WALK-IN:Istanbul'].adoption.delivery_order_count).toBe(1);
496
+ expect(compiled.reports[0].delivery_counters['COMPLETED:POS_WALK-IN:Istanbul'].adoption.delivery_order_count).toBe(1);
241
497
  });
242
498
  });