@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.
- package/esm/constants/MATERIALIZED_REPORTS.js +106 -2
- package/esm/constants/enums/delivery.js +13 -0
- package/esm/helpers/materialized-reports/index.js +5 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
- package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
- package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
- package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
- package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
- package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
- package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
- package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/esm/schemas/models/applied_order_discounts.js +103 -0
- package/esm/schemas/models/index.js +12 -10
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
- package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
- package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/esm/schemas/types/applied_order_discounts.js +1 -0
- package/esm/schemas/types/index.js +14 -12
- package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
- package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
- package/lib/constants/enums/delivery.d.ts +9 -0
- package/lib/constants/enums/delivery.js +14 -1
- package/lib/helpers/materialized-reports/index.d.ts +5 -0
- package/lib/helpers/materialized-reports/index.js +5 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
- package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
- package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
- package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/lib/helpers/order/payment-collection.d.ts +25 -0
- package/lib/helpers/order/payment-collection.js +51 -0
- package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
- package/lib/schemas/models/applied_order_discounts.js +106 -0
- package/lib/schemas/models/index.d.ts +12 -10
- package/lib/schemas/models/index.js +12 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
- package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
- package/lib/schemas/types/applied_order_discounts.js +2 -0
- package/lib/schemas/types/index.d.ts +14 -12
- package/lib/schemas/types/index.js +14 -12
- package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
- package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
- package/lib/tests/offer-item-resolution.test.js +1 -4
- package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
- package/lib/tests/payment-collection-timestamps.test.js +71 -0
- package/package.json +4 -2
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const delivery_1 = require("../../constants/enums/delivery");
|
|
4
|
+
const index_1 = require("../../helpers/materialized-reports/index");
|
|
5
|
+
const materialized_delivery_entry_pages_1 = require("../../helpers/materialized-reports/materialized-delivery-entry-pages");
|
|
6
|
+
const materialized_document_size_1 = require("../../helpers/materialized-reports/materialized-document-size");
|
|
7
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
8
|
+
const TENANT = 'tenant-practical';
|
|
9
|
+
const BRAND = 'brand-practical';
|
|
10
|
+
const DAY = '2026-09-10';
|
|
11
|
+
const order = (id, over = {}) => ({
|
|
12
|
+
_id: id,
|
|
13
|
+
tenant_id: TENANT,
|
|
14
|
+
platform: 'POS_DELIVERY',
|
|
15
|
+
order_status: 'COMPLETED',
|
|
16
|
+
createdAt: new Date(DAY + 'T10:00:00.000Z'),
|
|
17
|
+
localDate: DAY,
|
|
18
|
+
localHour: 10,
|
|
19
|
+
net_sale_amount: 5000,
|
|
20
|
+
amount_collected: 5000,
|
|
21
|
+
delivery_details: { city: 'Istanbul', state: 'Istanbul', delivery_cost: 300 },
|
|
22
|
+
...over,
|
|
23
|
+
});
|
|
24
|
+
const delivery = (id, orderId, over = {}) => ({
|
|
25
|
+
_id: id,
|
|
26
|
+
tenant_id: TENANT,
|
|
27
|
+
order_id: orderId,
|
|
28
|
+
rider_id: 'rider-1',
|
|
29
|
+
rider_name: 'Sam',
|
|
30
|
+
status: 'COMPLETED',
|
|
31
|
+
createdAt: new Date(DAY + 'T10:05:00.000Z'),
|
|
32
|
+
updatedAt: new Date(DAY + 'T10:35:00.000Z'),
|
|
33
|
+
delivered_at: new Date(DAY + 'T10:32:00.000Z'),
|
|
34
|
+
expected_delivery_at: null,
|
|
35
|
+
distance_in_meters_from_store: 3000,
|
|
36
|
+
rider_earnings: {
|
|
37
|
+
status: delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL,
|
|
38
|
+
amount: 700,
|
|
39
|
+
},
|
|
40
|
+
tracking_enabled: true,
|
|
41
|
+
localDate: DAY,
|
|
42
|
+
...over,
|
|
43
|
+
});
|
|
44
|
+
describe('delivery practical-scale correctness', () => {
|
|
45
|
+
it('uses a per-metric denominator for completion and total time', () => {
|
|
46
|
+
const compiled = (0, index_1.compileTenantDeliveryReports)({
|
|
47
|
+
tenantId: TENANT,
|
|
48
|
+
brandId: BRAND,
|
|
49
|
+
localDate: DAY,
|
|
50
|
+
orders: [order('o1'), order('o2', { localHour: 11 })],
|
|
51
|
+
deliveries: [
|
|
52
|
+
delivery('d1', 'o1'),
|
|
53
|
+
delivery('d2', 'o2', {
|
|
54
|
+
status: 'IN_PROGRESS',
|
|
55
|
+
delivered_at: null,
|
|
56
|
+
updatedAt: new Date(DAY + 'T11:06:00.000Z'),
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
computedAt: new Date(DAY + 'T23:00:00.000Z'),
|
|
60
|
+
});
|
|
61
|
+
const page = (0, index_1.getFormattedTenantDeliveryReporting)(compiled.reports)[0][0];
|
|
62
|
+
expect(page.summary.average_complete_minutes).toBe(27);
|
|
63
|
+
expect(page.summary.average_total_minutes).toBe(32);
|
|
64
|
+
// The old denominator was graded_count (2), which produced 13.5 / 16.
|
|
65
|
+
expect(page.summary.average_complete_minutes).not.toBe(13.5);
|
|
66
|
+
expect(page.summary.average_total_minutes).not.toBe(16);
|
|
67
|
+
});
|
|
68
|
+
it('attributes a delivery to the ORDER local day, even after midnight', () => {
|
|
69
|
+
const orderDate = '2026-09-10';
|
|
70
|
+
const o = order('o-midnight', {
|
|
71
|
+
localDate: orderDate,
|
|
72
|
+
createdAt: new Date('2026-09-10T20:50:00.000Z'),
|
|
73
|
+
localHour: 23,
|
|
74
|
+
});
|
|
75
|
+
const d = delivery('d-midnight', 'o-midnight', {
|
|
76
|
+
localDate: '2026-09-11',
|
|
77
|
+
createdAt: new Date('2026-09-10T21:10:00.000Z'),
|
|
78
|
+
updatedAt: new Date('2026-09-10T21:40:00.000Z'),
|
|
79
|
+
delivered_at: new Date('2026-09-10T21:35:00.000Z'),
|
|
80
|
+
});
|
|
81
|
+
const compiled = (0, index_1.compileTenantDeliveryReports)({
|
|
82
|
+
tenantId: TENANT,
|
|
83
|
+
brandId: BRAND,
|
|
84
|
+
localDate: orderDate,
|
|
85
|
+
orders: [o],
|
|
86
|
+
deliveries: [d],
|
|
87
|
+
computedAt: new Date(),
|
|
88
|
+
});
|
|
89
|
+
const row = Object.values(compiled.entries[0].delivery_entries ?? {}).flatMap((section) => section.rows)[0];
|
|
90
|
+
expect(row.source_local_date).toBe(orderDate);
|
|
91
|
+
expect(row.source_day_unattributed).toBe(false);
|
|
92
|
+
expect(row.order_status).toBe('COMPLETED');
|
|
93
|
+
expect(row.street).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
it('excludes pickup orders from H3 cells and unknown aggregates', () => {
|
|
96
|
+
const cells = (0, index_1.compileDeliveryGeoCounters)({
|
|
97
|
+
tenantId: TENANT,
|
|
98
|
+
brandId: BRAND,
|
|
99
|
+
localDate: DAY,
|
|
100
|
+
orders: [
|
|
101
|
+
order('o-delivery', {
|
|
102
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat: 41, lng: 29 },
|
|
103
|
+
}),
|
|
104
|
+
order('o-pickup', { delivery_details: null }),
|
|
105
|
+
],
|
|
106
|
+
deliveries: [],
|
|
107
|
+
computedAt: new Date(),
|
|
108
|
+
});
|
|
109
|
+
expect(cells.reduce((sum, cell) => sum + cell.orders, 0)).toBe(1);
|
|
110
|
+
expect(cells.some((cell) => cell.h3_cell === '__UNKNOWN__')).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
it('returns cap counts in the geo response', () => {
|
|
113
|
+
const cells = Array.from({ length: 2002 }, (_, index) => ({
|
|
114
|
+
tenant_id: TENANT,
|
|
115
|
+
brand_id: BRAND,
|
|
116
|
+
scope_context: 'localDate',
|
|
117
|
+
scope_field: DAY,
|
|
118
|
+
city: 'Istanbul',
|
|
119
|
+
h3_cell: String(800000000000000 + index),
|
|
120
|
+
resolution: 8,
|
|
121
|
+
location: {
|
|
122
|
+
type: 'Point',
|
|
123
|
+
coordinates: [29, 41],
|
|
124
|
+
},
|
|
125
|
+
orders: 3,
|
|
126
|
+
app_orders: 3,
|
|
127
|
+
delivery_records: 3,
|
|
128
|
+
completed: 3,
|
|
129
|
+
cancelled: 0,
|
|
130
|
+
net_sale_amount: 0,
|
|
131
|
+
delivery_charge_amount: 0,
|
|
132
|
+
rider_revenue_amount: 0,
|
|
133
|
+
schema_version: 1,
|
|
134
|
+
computed_at: new Date(),
|
|
135
|
+
}));
|
|
136
|
+
const response = (0, index_1.buildDeliveryGeoResponse)({
|
|
137
|
+
cells: cells.slice(0, 2000),
|
|
138
|
+
totalOrders: 6006,
|
|
139
|
+
totalAppOrders: 6006,
|
|
140
|
+
cappedCellCount: 2,
|
|
141
|
+
cappedOrderCount: 6,
|
|
142
|
+
});
|
|
143
|
+
expect(response.capped_cell_count).toBe(2);
|
|
144
|
+
expect(response.capped_order_count).toBe(6);
|
|
145
|
+
});
|
|
146
|
+
it('keeps a 5,000-order cell far below the 2 MiB geo budget', () => {
|
|
147
|
+
const orders = Array.from({ length: 5000 }, (_, index) => order('big-' + index, {
|
|
148
|
+
platform: 'P' + (index % 7),
|
|
149
|
+
order_status: ['COMPLETED', 'CANCELLED', 'PENDING'][index % 3],
|
|
150
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat: 41, lng: 29 },
|
|
151
|
+
}));
|
|
152
|
+
const result = (0, index_1.compileTenantDeliveryGeoCellsWithStats)({
|
|
153
|
+
tenantId: TENANT,
|
|
154
|
+
brandId: BRAND,
|
|
155
|
+
localDate: DAY,
|
|
156
|
+
orders,
|
|
157
|
+
deliveries: [],
|
|
158
|
+
computedAt: new Date(),
|
|
159
|
+
});
|
|
160
|
+
expect(result.cells).toHaveLength(1);
|
|
161
|
+
const keys = Object.keys(result.cells[0].by_key ?? {});
|
|
162
|
+
expect(keys.length).toBeLessThanOrEqual(64);
|
|
163
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(result.cells[0])).toBeLessThan(2 * 1024 * 1024);
|
|
164
|
+
});
|
|
165
|
+
it('reports write-time cell cap counts', () => {
|
|
166
|
+
const orders = [41.0, 41.1, 41.2].map((lat, index) => order('cap-' + index, {
|
|
167
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat, lng: 29 + index * 0.1 },
|
|
168
|
+
}));
|
|
169
|
+
const result = (0, index_1.compileTenantDeliveryGeoCellsWithStats)({
|
|
170
|
+
tenantId: TENANT,
|
|
171
|
+
brandId: BRAND,
|
|
172
|
+
localDate: DAY,
|
|
173
|
+
orders,
|
|
174
|
+
deliveries: [],
|
|
175
|
+
computedAt: new Date(),
|
|
176
|
+
maxCells: 1,
|
|
177
|
+
});
|
|
178
|
+
expect(result.cells).toHaveLength(1);
|
|
179
|
+
expect(result.cappedCellCount).toBe(2);
|
|
180
|
+
expect(result.cappedOrderCount).toBe(2);
|
|
181
|
+
});
|
|
182
|
+
it('filters H3 cells by platform and order status through by_key', () => {
|
|
183
|
+
const cells = (0, index_1.compileDeliveryGeoCounters)({
|
|
184
|
+
tenantId: TENANT,
|
|
185
|
+
brandId: BRAND,
|
|
186
|
+
localDate: DAY,
|
|
187
|
+
orders: [
|
|
188
|
+
order('o-completed-pos', {
|
|
189
|
+
order_status: 'COMPLETED',
|
|
190
|
+
platform: 'POS_DELIVERY',
|
|
191
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat: 41, lng: 29 },
|
|
192
|
+
}),
|
|
193
|
+
order('o-cancelled-web', {
|
|
194
|
+
order_status: 'CANCELLED',
|
|
195
|
+
platform: 'WEB_DELIVERY',
|
|
196
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat: 41.0001, lng: 29.0001 },
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
deliveries: [],
|
|
200
|
+
computedAt: new Date(),
|
|
201
|
+
});
|
|
202
|
+
const all = (0, index_1.buildDeliveryGeoResponse)({ cells, totalOrders: 2, totalAppOrders: 0, minOrders: 1 });
|
|
203
|
+
const cancelled = (0, index_1.buildDeliveryGeoResponse)({
|
|
204
|
+
cells,
|
|
205
|
+
totalOrders: 1,
|
|
206
|
+
totalAppOrders: 0,
|
|
207
|
+
minOrders: 1,
|
|
208
|
+
filters: { order_statuses: ['CANCELLED'] },
|
|
209
|
+
});
|
|
210
|
+
const web = (0, index_1.buildDeliveryGeoResponse)({
|
|
211
|
+
cells,
|
|
212
|
+
totalOrders: 1,
|
|
213
|
+
totalAppOrders: 0,
|
|
214
|
+
minOrders: 1,
|
|
215
|
+
filters: { platforms: ['WEB_DELIVERY'] },
|
|
216
|
+
});
|
|
217
|
+
const both = (0, index_1.buildDeliveryGeoResponse)({
|
|
218
|
+
cells,
|
|
219
|
+
totalOrders: 1,
|
|
220
|
+
totalAppOrders: 0,
|
|
221
|
+
minOrders: 1,
|
|
222
|
+
filters: { platforms: ['WEB_DELIVERY'], order_statuses: ['CANCELLED'] },
|
|
223
|
+
});
|
|
224
|
+
expect(all.cells.reduce((sum, cell) => sum + cell.orders, 0)).toBe(2);
|
|
225
|
+
expect(cancelled.cells.reduce((sum, cell) => sum + cell.orders, 0)).toBe(1);
|
|
226
|
+
expect(web.cells.reduce((sum, cell) => sum + cell.orders, 0)).toBe(1);
|
|
227
|
+
expect(both.cells.reduce((sum, cell) => sum + cell.orders, 0)).toBe(1);
|
|
228
|
+
expect(cancelled.cells[0].orders).toBe(1);
|
|
229
|
+
expect(both.cells[0].orders).toBe(1);
|
|
230
|
+
for (const cell of cells) {
|
|
231
|
+
expect(Object.values(cell.by_key ?? {}).reduce((sum, value) => sum + value.orders, 0)).toBe(cell.orders);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
it('city filter narrows cells without touching the by_key sums', () => {
|
|
235
|
+
const cells = (0, index_1.compileDeliveryGeoCounters)({
|
|
236
|
+
tenantId: TENANT,
|
|
237
|
+
brandId: BRAND,
|
|
238
|
+
localDate: DAY,
|
|
239
|
+
orders: [
|
|
240
|
+
order('o-istanbul', {
|
|
241
|
+
delivery_details: { city: 'Istanbul', delivery_cost: 300, lat: 41, lng: 29 },
|
|
242
|
+
}),
|
|
243
|
+
order('o-ankara', {
|
|
244
|
+
delivery_details: { city: 'Ankara', delivery_cost: 300, lat: 39.9, lng: 32.9 },
|
|
245
|
+
}),
|
|
246
|
+
],
|
|
247
|
+
deliveries: [],
|
|
248
|
+
computedAt: new Date(),
|
|
249
|
+
});
|
|
250
|
+
const istanbul = (0, index_1.buildDeliveryGeoResponse)({
|
|
251
|
+
cells,
|
|
252
|
+
totalOrders: 1,
|
|
253
|
+
totalAppOrders: 0,
|
|
254
|
+
minOrders: 1,
|
|
255
|
+
filters: { cities: ['Istanbul'] },
|
|
256
|
+
});
|
|
257
|
+
expect(istanbul.cells).toHaveLength(1);
|
|
258
|
+
expect(istanbul.cells[0].city).toBe('Istanbul');
|
|
259
|
+
expect(istanbul.cells[0].orders).toBe(1);
|
|
260
|
+
for (const cell of cells) {
|
|
261
|
+
expect(Object.values(cell.by_key ?? {}).reduce((sum, value) => sum + value.orders, 0)).toBe(cell.orders);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
it('splits a synthetic over-budget entry page deterministically', () => {
|
|
265
|
+
const rows = Array.from({ length: 35000 }, (_, index) => ({
|
|
266
|
+
delivery_id: 'd-' + index,
|
|
267
|
+
entry_key: 'e-' + index,
|
|
268
|
+
order_id: 'o-' + index,
|
|
269
|
+
source_local_date: DAY,
|
|
270
|
+
delivered_at: new Date(DAY + 'T10:00:00.000Z'),
|
|
271
|
+
created_at: new Date(DAY + 'T09:00:00.000Z'),
|
|
272
|
+
rider_name: 'r'.repeat(420),
|
|
273
|
+
}));
|
|
274
|
+
const document = {
|
|
275
|
+
tenant_id: TENANT,
|
|
276
|
+
brand_id: BRAND,
|
|
277
|
+
scope_context: 'localMonth',
|
|
278
|
+
scope_field: '2026-09',
|
|
279
|
+
page: DAY,
|
|
280
|
+
day_index: null,
|
|
281
|
+
sale_type_key_filters: ['ORDER_STATUS', 'PLATFORM', 'CITY'],
|
|
282
|
+
delivery_entries: { 'COMPLETED:POS_DELIVERY': { rows } },
|
|
283
|
+
off_app_order_count: 3,
|
|
284
|
+
schema_version: 3,
|
|
285
|
+
source_watermark: new Date(DAY + 'T23:00:00.000Z'),
|
|
286
|
+
computed_at: new Date(DAY + 'T23:00:00.000Z'),
|
|
287
|
+
createdAt: new Date(DAY + 'T23:00:00.000Z'),
|
|
288
|
+
updatedAt: new Date(DAY + 'T23:00:00.000Z'),
|
|
289
|
+
};
|
|
290
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(document)).toBeGreaterThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES);
|
|
291
|
+
const pages = (0, index_1.splitMaterializedDeliveryEntryPage)(document);
|
|
292
|
+
expect(pages.length).toBeGreaterThan(1);
|
|
293
|
+
const ids = new Set();
|
|
294
|
+
let count = 0;
|
|
295
|
+
for (const page of pages) {
|
|
296
|
+
expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(page)).toBeLessThanOrEqual(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES);
|
|
297
|
+
expect((0, materialized_delivery_entry_pages_1.isDeliveryEntryPageForSourceDay)(page.scope_context, page.page, DAY)).toBe(true);
|
|
298
|
+
for (const section of Object.values(page.delivery_entries ?? {})) {
|
|
299
|
+
for (const row of section.rows) {
|
|
300
|
+
ids.add(String(row.delivery_id));
|
|
301
|
+
count += 1;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
expect(count).toBe(rows.length);
|
|
306
|
+
expect(ids.size).toBe(rows.length);
|
|
307
|
+
const merged = (0, index_1.mergeMaterializedDeliveryEntryPages)(pages);
|
|
308
|
+
const mergedRows = Object.values(merged.delivery_entries ?? {}).flatMap((section) => section.rows);
|
|
309
|
+
expect(mergedRows.length).toBe(rows.length);
|
|
310
|
+
expect(new Set(mergedRows.map((row) => row.delivery_id)).size).toBe(rows.length);
|
|
311
|
+
expect(merged.off_app_order_count).toBe(3);
|
|
312
|
+
});
|
|
313
|
+
it('filters totals by order status, platform and city', () => {
|
|
314
|
+
const compiled = (0, index_1.compileTenantDeliveryReports)({
|
|
315
|
+
tenantId: TENANT,
|
|
316
|
+
brandId: BRAND,
|
|
317
|
+
localDate: DAY,
|
|
318
|
+
orders: [
|
|
319
|
+
order('o1', { order_status: 'COMPLETED', platform: 'POS_DELIVERY' }),
|
|
320
|
+
order('o2', {
|
|
321
|
+
order_status: 'CANCELLED',
|
|
322
|
+
platform: 'WEB_DELIVERY',
|
|
323
|
+
delivery_details: { city: 'Ankara', delivery_cost: 300 },
|
|
324
|
+
}),
|
|
325
|
+
],
|
|
326
|
+
deliveries: [],
|
|
327
|
+
computedAt: new Date(),
|
|
328
|
+
});
|
|
329
|
+
const all = (0, index_1.getFormattedTenantDeliveryReporting)(compiled.reports)[0][0];
|
|
330
|
+
const cancelled = (0, index_1.getFormattedTenantDeliveryReporting)(compiled.reports, {
|
|
331
|
+
order_statuses: ['CANCELLED'],
|
|
332
|
+
})[0][0];
|
|
333
|
+
const pos = (0, index_1.getFormattedTenantDeliveryReporting)(compiled.reports, {
|
|
334
|
+
platforms: ['POS_DELIVERY'],
|
|
335
|
+
})[0][0];
|
|
336
|
+
const ankara = (0, index_1.getFormattedTenantDeliveryReporting)(compiled.reports, {
|
|
337
|
+
cities: ['Ankara'],
|
|
338
|
+
})[0][0];
|
|
339
|
+
expect(all.summary.orders).toBe(2);
|
|
340
|
+
expect(cancelled.summary.orders).toBe(1);
|
|
341
|
+
expect(pos.summary.orders).toBe(1);
|
|
342
|
+
expect(ankara.summary.orders).toBe(1);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
@@ -232,3 +232,17 @@ describe('a FULL discount document set is integer-only', () => {
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
|
+
describe('geometry is the one exception', () => {
|
|
236
|
+
it('accepts a GeoJSON centroid while still rejecting money decimals', () => {
|
|
237
|
+
expect((0, materialized_integer_contract_1.findNonIntegerNumericLeaves)({
|
|
238
|
+
h3_cell: '88194ad33dfffff',
|
|
239
|
+
orders: 3,
|
|
240
|
+
location: { type: 'Point', coordinates: [28.9784123, 41.0082456] },
|
|
241
|
+
})).toEqual([]);
|
|
242
|
+
expect((0, materialized_integer_contract_1.findNonIntegerNumericLeaves)({
|
|
243
|
+
orders: 3,
|
|
244
|
+
net_sale_amount: 12.5,
|
|
245
|
+
location: { type: 'Point', coordinates: [28.9784123, 41.0082456] },
|
|
246
|
+
}).map((violation) => violation.path)).toEqual(['net_sale_amount']);
|
|
247
|
+
});
|
|
248
|
+
});
|
package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js
CHANGED
|
@@ -209,7 +209,7 @@ describe('materialized_tenant_sales_overview_reports schema', () => {
|
|
|
209
209
|
});
|
|
210
210
|
it('rejects unsupported key-filter dimensions', () => {
|
|
211
211
|
// NOTE: this test previously used 'CITY' as its unsupported example. The delivery
|
|
212
|
-
// report (M4) legitimately ADDED CITY as a real dimension - a key is <PLATFORM>:<CITY>
|
|
212
|
+
// report (M4) legitimately ADDED CITY as a real dimension - a key is <ORDER_STATUS>:<PLATFORM>:<CITY>
|
|
213
213
|
// - so the fixture silently stopped testing rejection. The sentinel is now a value
|
|
214
214
|
// that is deliberately not a dimension, and the guard below makes the test fail
|
|
215
215
|
// LOUDLY if that ever changes, instead of quietly passing on a valid value.
|
|
@@ -141,10 +141,7 @@ describe('getClaimedRewardQuantity / getRemainingRewardQuantity', () => {
|
|
|
141
141
|
expect(result).toBe(6);
|
|
142
142
|
});
|
|
143
143
|
it('subtracts claimed units from the order allowance and never goes negative', () => {
|
|
144
|
-
const cart = categories([
|
|
145
|
-
stamped(2, { loyalty: 'a' }),
|
|
146
|
-
stamped(1, { voucher: 'a' }),
|
|
147
|
-
]);
|
|
144
|
+
const cart = categories([stamped(2, { loyalty: 'a' }), stamped(1, { voucher: 'a' })]);
|
|
148
145
|
expect((0, offer_item_resolution_1.getRemainingRewardQuantity)({ categories: cart, offerId: 'a', allowance: 6 })).toBe(3);
|
|
149
146
|
expect((0, offer_item_resolution_1.getRemainingRewardQuantity)({ categories: cart, offerId: 'a', allowance: 3 })).toBe(0);
|
|
150
147
|
expect((0, offer_item_resolution_1.getRemainingRewardQuantity)({ categories: cart, offerId: 'a', allowance: 1 })).toBe(0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const payment_collection_1 = require("../helpers/order/payment-collection");
|
|
5
|
+
const NOW = new Date('2026-10-20T14:00:00.000Z');
|
|
6
|
+
const EARLIER = new Date('2026-10-19T10:00:00.000Z');
|
|
7
|
+
const payment = (over = {}) => ({
|
|
8
|
+
_id: '5f0000000000000000000001',
|
|
9
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.CASH,
|
|
10
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.SETTLED,
|
|
11
|
+
card_details: null,
|
|
12
|
+
amount_paid: 1000,
|
|
13
|
+
amount_due: 1000,
|
|
14
|
+
amount_refunded: 0,
|
|
15
|
+
payment_id: 'pay-1',
|
|
16
|
+
...over,
|
|
17
|
+
});
|
|
18
|
+
describe('stampPaymentCollectionTimestamps', () => {
|
|
19
|
+
it('stamps new collected money and leaves unpaid PAY_LATER empty', () => {
|
|
20
|
+
const [paid, credit] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([
|
|
21
|
+
payment(),
|
|
22
|
+
payment({
|
|
23
|
+
_id: '5f0000000000000000000002',
|
|
24
|
+
payment_id: 'pay-2',
|
|
25
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.PAY_LATER,
|
|
26
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.PENDING,
|
|
27
|
+
amount_paid: 0,
|
|
28
|
+
amount_due: 5000,
|
|
29
|
+
}),
|
|
30
|
+
], null, { now: NOW });
|
|
31
|
+
expect(paid.collected_at).toBe(NOW);
|
|
32
|
+
expect(credit.collected_at).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
it('ignores a client-supplied collected_at on create', () => {
|
|
35
|
+
const [paid] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: EARLIER })], null, { now: NOW });
|
|
36
|
+
expect(paid.collected_at).toBe(NOW);
|
|
37
|
+
});
|
|
38
|
+
it('preserves the stored timestamp when amount_paid did not increase', () => {
|
|
39
|
+
const previous = payment({ collected_at: EARLIER });
|
|
40
|
+
const [unchanged] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: null })], [previous], { now: NOW });
|
|
41
|
+
expect(unchanged.collected_at).toBe(EARLIER);
|
|
42
|
+
});
|
|
43
|
+
it('stamps the latest collection when a partial amount is collected', () => {
|
|
44
|
+
const previous = payment({ amount_paid: 400, collected_at: EARLIER });
|
|
45
|
+
const [partial] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 700 })], [previous], { now: NOW });
|
|
46
|
+
expect(partial.collected_at).toBe(NOW);
|
|
47
|
+
});
|
|
48
|
+
it('does not rewrite the timestamp on a refund / amount decrease', () => {
|
|
49
|
+
const previous = payment({ amount_paid: 1000, collected_at: EARLIER });
|
|
50
|
+
const [refunded] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 0, amount_refunded: 1000, payment_status: constants_1.PAYMENT_STATUS_ENUM.REFUNDED })], [previous], { now: NOW });
|
|
51
|
+
expect(refunded.collected_at).toBe(EARLIER);
|
|
52
|
+
});
|
|
53
|
+
it('matches legacy rows by _id when payment_id is null', () => {
|
|
54
|
+
const previous = payment({ payment_id: null, collected_at: EARLIER });
|
|
55
|
+
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: null, amount_paid: 1200 })], [previous], { now: NOW });
|
|
56
|
+
expect(updated.collected_at).toBe(NOW);
|
|
57
|
+
});
|
|
58
|
+
it('preserves the stamp when the server reassigns payment_id but _id is stable', () => {
|
|
59
|
+
const previous = payment({ payment_id: 'pay-old', collected_at: EARLIER });
|
|
60
|
+
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: 'pay-new' })], [previous], { now: NOW });
|
|
61
|
+
expect(updated.collected_at).toBe(EARLIER);
|
|
62
|
+
});
|
|
63
|
+
it('does not stamp a failed payment', () => {
|
|
64
|
+
const [failed] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_status: constants_1.PAYMENT_STATUS_ENUM.FAILED })], null, { now: NOW });
|
|
65
|
+
expect(failed.collected_at).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
it('returns an empty array for empty / invalid input', () => {
|
|
68
|
+
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(null)).toEqual([]);
|
|
69
|
+
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(undefined)).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@managesome/eposmatic-toolkit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.53",
|
|
4
4
|
"description": "A Toolkit Library for Eposmatic",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -26,13 +26,15 @@
|
|
|
26
26
|
"fixtures:prep-time": "tsx scripts/analyze-prep-time.ts",
|
|
27
27
|
"fixtures:prep-time-parity": "tsx scripts/analyze-prep-time-parity.ts",
|
|
28
28
|
"fixtures:delivery": "tsx scripts/analyze-delivery.ts",
|
|
29
|
-
"sim:close-day": "tsx simulations/simulate-day-close.ts"
|
|
29
|
+
"sim:close-day": "tsx simulations/simulate-day-close.ts",
|
|
30
|
+
"wipe:delivery": "tsx scripts/wipe-delivery-materialization.ts"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"bson-objectid": "^2.0.4",
|
|
33
34
|
"crypto-js": "^4.2.0",
|
|
34
35
|
"emoji-strip": "^1.0.1",
|
|
35
36
|
"google-libphonenumber": "^3.2.40",
|
|
37
|
+
"h3-js": "^4.5.0",
|
|
36
38
|
"lodash": "^4.17.21",
|
|
37
39
|
"moment": "^2.30.1",
|
|
38
40
|
"mongoose": "^8.13.2"
|