@managesome/eposmatic-toolkit 0.4.26 → 0.4.27
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/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +13 -1
- package/esm/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
- package/esm/helpers/materialized-reports/materialized-integer-contract.js +142 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
- package/esm/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -29
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
- package/esm/helpers/utils/duration-conversion.js +31 -0
- package/esm/helpers/utils/index.js +2 -0
- package/esm/helpers/utils/percentage-conversion.js +69 -0
- package/esm/schemas/models/materialized_tenant_discount_sources.js +5 -1
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +18 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +14 -2
- package/lib/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
- package/lib/helpers/materialized-reports/materialized-integer-contract.d.ts +68 -0
- package/lib/helpers/materialized-reports/materialized-integer-contract.js +147 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
- package/lib/helpers/materialized-reports/tenant-discount-source-formatter.d.ts +12 -30
- package/lib/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -30
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
- package/lib/helpers/types/materialized-reports-apis.d.ts +11 -3
- package/lib/helpers/utils/duration-conversion.d.ts +19 -0
- package/lib/helpers/utils/duration-conversion.js +37 -0
- package/lib/helpers/utils/index.d.ts +2 -0
- package/lib/helpers/utils/index.js +2 -0
- package/lib/helpers/utils/percentage-conversion.d.ts +49 -0
- package/lib/helpers/utils/percentage-conversion.js +76 -0
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +0 -3
- package/lib/schemas/models/materialized_tenant_discount_sources.js +5 -1
- package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +11 -4
- package/lib/schemas/types/materialized_tenant_discount_sources.d.ts +23 -4
- package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
- package/lib/tests/materialized-reports/fixtures.js +118 -8
- package/lib/tests/materialized-reports/materialized-discount-classification.test.js +34 -24
- package/lib/tests/materialized-reports/materialized-discount-sources.test.js +14 -10
- package/lib/tests/materialized-reports/materialized-integer-contract.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +223 -0
- package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.js +58 -0
- package/lib/tests/materialized-reports/materialized-writers-integer-only.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-writers-integer-only.test.js +150 -0
- package/lib/tests/materialized-reports/sales-overview-baseline.test.js +51 -51
- package/lib/tests/materialized-reports/tenant-discount-source-formatter.test.js +80 -41
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
+
const materialized_integer_contract_1 = require("../../helpers/materialized-reports/materialized-integer-contract");
|
|
5
|
+
const materialized_credit_bills_helpers_1 = require("../../helpers/materialized-reports/materialized-credit-bills-helpers");
|
|
6
|
+
const materialized_sales_comparison_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-sales-comparison-compile-helpers");
|
|
7
|
+
const materialized_payments_comparison_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-payments-comparison-compile-helpers");
|
|
8
|
+
const materialized_hourly_comparison_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-hourly-comparison-compile-helpers");
|
|
9
|
+
const materialized_delivery_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-delivery-compile-helpers");
|
|
10
|
+
const fixtures_1 = require("./fixtures");
|
|
11
|
+
/**
|
|
12
|
+
* EVERY materialized writer must emit integer-only documents.
|
|
13
|
+
*
|
|
14
|
+
* The contract: money in CENTS, percentage rates in BASIS POINTS, durations in
|
|
15
|
+
* whole MINUTES, counts as counts — and no stored share, average or ratio.
|
|
16
|
+
*
|
|
17
|
+
* This suite is the per-writer audit: each writer is driven with the live
|
|
18
|
+
* fixtures and its OUTPUT is checked recursively, so a decimal hiding in a
|
|
19
|
+
* nested counter, a key-metric map or a flat row cannot slip through.
|
|
20
|
+
*/
|
|
21
|
+
const TENANT = 'basha-istanbul-f7';
|
|
22
|
+
const BRAND = 'basha-istanbul-f7';
|
|
23
|
+
const OFFSET = 5;
|
|
24
|
+
const AT = new Date('2026-09-13T23:00:00.000Z');
|
|
25
|
+
const ordersOf = (localDate) => (0, fixtures_1.loadOrdersDataset)('basha').filter((order) => order.localDate === localDate);
|
|
26
|
+
describe('every materialized writer emits integer-only documents', () => {
|
|
27
|
+
it('the sales comparison writer', () => {
|
|
28
|
+
const compiled = (0, materialized_sales_comparison_compile_helpers_1.compileTenantSalesComparisonReports)({
|
|
29
|
+
tenantId: TENANT,
|
|
30
|
+
brandId: BRAND,
|
|
31
|
+
localDate: '2026-09-13',
|
|
32
|
+
orders: ordersOf('2026-09-13'),
|
|
33
|
+
gmtOffset: OFFSET,
|
|
34
|
+
computedAt: AT,
|
|
35
|
+
});
|
|
36
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.reports, {
|
|
37
|
+
collection: 'materialized_tenant_sales_comparison_reports',
|
|
38
|
+
});
|
|
39
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.entries, {
|
|
40
|
+
collection: 'materialized_tenant_sales_comparison_entries',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('the payments comparison writer', () => {
|
|
44
|
+
const compiled = (0, materialized_payments_comparison_compile_helpers_1.compileTenantPaymentsComparisonReports)({
|
|
45
|
+
tenantId: TENANT,
|
|
46
|
+
brandId: BRAND,
|
|
47
|
+
localDate: '2026-09-13',
|
|
48
|
+
orders: ordersOf('2026-09-13'),
|
|
49
|
+
gmtOffset: OFFSET,
|
|
50
|
+
computedAt: AT,
|
|
51
|
+
});
|
|
52
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.reports, {
|
|
53
|
+
collection: 'materialized_tenant_payments_comparison_reports',
|
|
54
|
+
});
|
|
55
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.entries, {
|
|
56
|
+
collection: 'materialized_tenant_payments_comparison_entries',
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('the hourly comparison writer', () => {
|
|
60
|
+
const compiled = (0, materialized_hourly_comparison_compile_helpers_1.compileTenantHourlyComparisonReports)({
|
|
61
|
+
tenantId: TENANT,
|
|
62
|
+
brandId: BRAND,
|
|
63
|
+
localDate: '2026-09-13',
|
|
64
|
+
orders: ordersOf('2026-09-13'),
|
|
65
|
+
gmtOffset: OFFSET,
|
|
66
|
+
computedAt: AT,
|
|
67
|
+
});
|
|
68
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.reports, {
|
|
69
|
+
collection: 'materialized_tenant_hourly_comparison_reports',
|
|
70
|
+
});
|
|
71
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.entries, {
|
|
72
|
+
collection: 'materialized_tenant_hourly_comparison_entries',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('the delivery writer', () => {
|
|
76
|
+
const compiled = (0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)({
|
|
77
|
+
tenantId: TENANT,
|
|
78
|
+
brandId: BRAND,
|
|
79
|
+
localDate: '2026-09-13',
|
|
80
|
+
orders: [],
|
|
81
|
+
deliveries: [
|
|
82
|
+
{
|
|
83
|
+
_id: 'd-1',
|
|
84
|
+
tenant_id: TENANT,
|
|
85
|
+
order_id: 'order-1',
|
|
86
|
+
rider_id: 'rider-1',
|
|
87
|
+
rider_name: 'Sam',
|
|
88
|
+
status: 'COMPLETED',
|
|
89
|
+
createdAt: new Date('2026-09-13T10:05:00.000Z'),
|
|
90
|
+
updatedAt: new Date('2026-09-13T10:35:00.000Z'),
|
|
91
|
+
delivered_at: new Date('2026-09-13T10:32:00.000Z'),
|
|
92
|
+
// A distance in METRES — the source float becomes whole metres.
|
|
93
|
+
distance_in_meters_from_store: 3000.4,
|
|
94
|
+
rider_earnings: { amount: 700.4, status: 'FINAL' },
|
|
95
|
+
polyline: [[1, 2]],
|
|
96
|
+
localHour: 10,
|
|
97
|
+
localDate: '2026-09-13',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
gmtOffset: OFFSET,
|
|
101
|
+
computedAt: AT,
|
|
102
|
+
});
|
|
103
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.reports, {
|
|
104
|
+
collection: 'materialized_tenant_delivery_reports',
|
|
105
|
+
});
|
|
106
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.entries, {
|
|
107
|
+
collection: 'materialized_tenant_delivery_entries',
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
it('the credit-bill ledger writer', () => {
|
|
111
|
+
const orders = ordersOf('2026-09-13');
|
|
112
|
+
const issued = orders.flatMap((order) => (0, materialized_credit_bills_helpers_1.buildCreditBillIssuedCandidatesFromOrder)(order, '2026-09-13', {
|
|
113
|
+
now: AT,
|
|
114
|
+
gmtOffset: OFFSET,
|
|
115
|
+
}) ?? []);
|
|
116
|
+
const resolution = (0, materialized_credit_bills_helpers_1.resolveCreditBillDay)({
|
|
117
|
+
tenantId: TENANT,
|
|
118
|
+
brandId: BRAND,
|
|
119
|
+
localDate: '2026-09-13',
|
|
120
|
+
issued,
|
|
121
|
+
received_events: [],
|
|
122
|
+
settled_bills: [],
|
|
123
|
+
stored: [],
|
|
124
|
+
computedAt: AT,
|
|
125
|
+
});
|
|
126
|
+
const documents = (0, materialized_credit_bills_helpers_1.buildMaterializedCreditBillDayReports)({
|
|
127
|
+
tenantId: TENANT,
|
|
128
|
+
brandId: BRAND,
|
|
129
|
+
localDate: '2026-09-13',
|
|
130
|
+
resolution,
|
|
131
|
+
computedAt: AT,
|
|
132
|
+
});
|
|
133
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(documents, {
|
|
134
|
+
collection: 'materialized_tenant_credit_bills',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('the scope metadata of a materialized document stays integer', () => {
|
|
138
|
+
// `scope_field` is a STRING ("2026", "2026-09-15") — an identifier, not a
|
|
139
|
+
// number — and the contract must not flag it.
|
|
140
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)([
|
|
141
|
+
{
|
|
142
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
143
|
+
scope_field: '2026-09',
|
|
144
|
+
day_index: '2026-09-15',
|
|
145
|
+
row_count: 3,
|
|
146
|
+
schema_version: 1,
|
|
147
|
+
},
|
|
148
|
+
], { collection: 'materialized_report_drilldown_scopes' });
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -43,34 +43,34 @@ describe('sales-overview baseline — basha (2026-09)', () => {
|
|
|
43
43
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
44
44
|
const totalSales = overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0];
|
|
45
45
|
expect(totalSales).toMatchObject({ _id: BASHA, count: 2916 });
|
|
46
|
-
expect(round2(totalSales.grossAmount)).toBe(
|
|
46
|
+
expect(round2(totalSales.grossAmount)).toBe(30556729);
|
|
47
47
|
const cancelled = overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS][0];
|
|
48
48
|
expect(cancelled).toMatchObject({ _id: BASHA, count: 15 });
|
|
49
|
-
expect(round2(cancelled.grossAmount)).toBe(
|
|
49
|
+
expect(round2(cancelled.grossAmount)).toBe(33962);
|
|
50
50
|
// Every order in the fixture is either a sale or a cancelled order.
|
|
51
51
|
expect(totalSales.count + cancelled.count).toBe(fixtures_1.ORDERS_DATASETS.basha.orderCount);
|
|
52
52
|
});
|
|
53
53
|
it('matches the pinned payments breakdown, including legacy CARD_PAYMENT', () => {
|
|
54
54
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
55
55
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
56
|
-
CARD_PAYMENT: { count: 2433, grossAmount:
|
|
57
|
-
CASH: { count: 459, grossAmount:
|
|
58
|
-
UNPAID: { count: 20, grossAmount:
|
|
56
|
+
CARD_PAYMENT: { count: 2433, grossAmount: 25798740 },
|
|
57
|
+
CASH: { count: 459, grossAmount: 4534577 },
|
|
58
|
+
UNPAID: { count: 20, grossAmount: 220432 },
|
|
59
59
|
COMPLIMENTARY: { count: 4, grossAmount: 2980 },
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
it('matches the pinned platform breakdown', () => {
|
|
63
63
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
64
64
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.SALES_BY_PLATFORM])).toEqual({
|
|
65
|
-
'APP_DINE-IN': { count: 2800, grossAmount:
|
|
66
|
-
'POS_TAKE-AWAY': { count: 50, grossAmount:
|
|
67
|
-
WEB_DELIVERY: { count: 28, grossAmount:
|
|
68
|
-
POS_DELIVERY: { count: 22, grossAmount:
|
|
69
|
-
'WEB_TAKE-AWAY': { count: 5, grossAmount:
|
|
70
|
-
'POS_DINE-IN': { count: 4, grossAmount:
|
|
71
|
-
'POS_DRIVE-THRU': { count: 2, grossAmount:
|
|
72
|
-
POS_KIOSK: { count: 2, grossAmount:
|
|
73
|
-
'WEB_DINE-IN': { count: 2, grossAmount:
|
|
65
|
+
'APP_DINE-IN': { count: 2800, grossAmount: 29567054 },
|
|
66
|
+
'POS_TAKE-AWAY': { count: 50, grossAmount: 409113 },
|
|
67
|
+
WEB_DELIVERY: { count: 28, grossAmount: 140939 },
|
|
68
|
+
POS_DELIVERY: { count: 22, grossAmount: 332341 },
|
|
69
|
+
'WEB_TAKE-AWAY': { count: 5, grossAmount: 24072 },
|
|
70
|
+
'POS_DINE-IN': { count: 4, grossAmount: 14505 },
|
|
71
|
+
'POS_DRIVE-THRU': { count: 2, grossAmount: 10392 },
|
|
72
|
+
POS_KIOSK: { count: 2, grossAmount: 23743 },
|
|
73
|
+
'WEB_DINE-IN': { count: 2, grossAmount: 25570 },
|
|
74
74
|
'POS_WALK-IN': { count: 1, grossAmount: 9000 },
|
|
75
75
|
});
|
|
76
76
|
});
|
|
@@ -117,14 +117,14 @@ describe('sales-overview baseline — basha (2026-09)', () => {
|
|
|
117
117
|
});
|
|
118
118
|
const totalSales = overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0];
|
|
119
119
|
expect(totalSales.count).toBe(2906);
|
|
120
|
-
expect(round2(totalSales.grossAmount)).toBe(
|
|
120
|
+
expect(round2(totalSales.grossAmount)).toBe(30497563);
|
|
121
121
|
// No cancelled orders qualify; the UNPAID bucket carries the credit bills
|
|
122
122
|
// + settled-later bills whose orders still collected > 0.
|
|
123
123
|
expect(overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS]).toEqual([]);
|
|
124
124
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
125
|
-
CARD_PAYMENT: { count: 2433, grossAmount:
|
|
126
|
-
CASH: { count: 459, grossAmount:
|
|
127
|
-
UNPAID: { count: 14, grossAmount:
|
|
125
|
+
CARD_PAYMENT: { count: 2433, grossAmount: 25798740 },
|
|
126
|
+
CASH: { count: 459, grossAmount: 4534577 },
|
|
127
|
+
UNPAID: { count: 14, grossAmount: 164246 },
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
it('returns credit bills (deferred settlement) for the sale type', () => {
|
|
@@ -133,10 +133,10 @@ describe('sales-overview baseline — basha (2026-09)', () => {
|
|
|
133
133
|
saleType: constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS,
|
|
134
134
|
});
|
|
135
135
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES])).toEqual({
|
|
136
|
-
[BASHA]: { count: 8, grossAmount:
|
|
136
|
+
[BASHA]: { count: 8, grossAmount: 97301 },
|
|
137
137
|
});
|
|
138
138
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
139
|
-
UNPAID: { count: 8, grossAmount:
|
|
139
|
+
UNPAID: { count: 8, grossAmount: 97301 },
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
it('applies platform + order status filters together', () => {
|
|
@@ -146,15 +146,15 @@ describe('sales-overview baseline — basha (2026-09)', () => {
|
|
|
146
146
|
orderStatuses: [constants_1.ORDER_STATUS_ENUM.COMPLETED, constants_1.ORDER_STATUS_ENUM.READY],
|
|
147
147
|
});
|
|
148
148
|
expect(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0]).toMatchObject({ count: 2789 });
|
|
149
|
-
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(
|
|
149
|
+
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(29423101);
|
|
150
150
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
151
|
-
CARD_PAYMENT: { count: 2355, grossAmount:
|
|
152
|
-
CASH: { count: 416, grossAmount:
|
|
153
|
-
UNPAID: { count: 14, grossAmount:
|
|
151
|
+
CARD_PAYMENT: { count: 2355, grossAmount: 25152628 },
|
|
152
|
+
CASH: { count: 416, grossAmount: 4110051 },
|
|
153
|
+
UNPAID: { count: 14, grossAmount: 157442 },
|
|
154
154
|
COMPLIMENTARY: { count: 4, grossAmount: 2980 },
|
|
155
155
|
});
|
|
156
156
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.SALES_BY_PLATFORM])).toEqual({
|
|
157
|
-
'APP_DINE-IN': { count: 2789, grossAmount:
|
|
157
|
+
'APP_DINE-IN': { count: 2789, grossAmount: 29423101 },
|
|
158
158
|
});
|
|
159
159
|
expect(overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS]).toEqual([]);
|
|
160
160
|
});
|
|
@@ -177,22 +177,22 @@ describe('sales-overview baseline — bruzo (2026-09)', () => {
|
|
|
177
177
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
178
178
|
const totalSales = overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0];
|
|
179
179
|
expect(totalSales).toMatchObject({ _id: BRUZO, count: 2070 });
|
|
180
|
-
expect(round2(totalSales.grossAmount)).toBe(
|
|
180
|
+
expect(round2(totalSales.grossAmount)).toBe(2662177);
|
|
181
181
|
const cancelled = overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS][0];
|
|
182
182
|
expect(cancelled).toMatchObject({ _id: BRUZO, count: 96 });
|
|
183
|
-
expect(round2(cancelled.grossAmount)).toBe(
|
|
183
|
+
expect(round2(cancelled.grossAmount)).toBe(112571);
|
|
184
184
|
expect(totalSales.count + cancelled.count).toBe(fixtures_1.ORDERS_DATASETS.bruzo.orderCount);
|
|
185
185
|
});
|
|
186
186
|
it('matches the pinned payments breakdown (aggregator + legacy payment types pass through)', () => {
|
|
187
187
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
188
188
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
189
|
-
CASH: { count: 770, grossAmount:
|
|
190
|
-
ONLINE: { count: 511, grossAmount:
|
|
191
|
-
CARD_PAYMENT: { count: 353, grossAmount:
|
|
192
|
-
FOODPANDA: { count: 309, grossAmount:
|
|
193
|
-
PLAZA: { count: 61, grossAmount: 83809
|
|
189
|
+
CASH: { count: 770, grossAmount: 936932 },
|
|
190
|
+
ONLINE: { count: 511, grossAmount: 577493 },
|
|
191
|
+
CARD_PAYMENT: { count: 353, grossAmount: 600671 },
|
|
192
|
+
FOODPANDA: { count: 309, grossAmount: 372894 },
|
|
193
|
+
PLAZA: { count: 61, grossAmount: 83809 },
|
|
194
194
|
COMPLIMENTARY: { count: 41, grossAmount: 43165 },
|
|
195
|
-
UNPAID: { count: 19, grossAmount: 29067
|
|
195
|
+
UNPAID: { count: 19, grossAmount: 29067 },
|
|
196
196
|
MARKETING: { count: 4, grossAmount: 15078 },
|
|
197
197
|
GOLOOTLO: { count: 2, grossAmount: 3068 },
|
|
198
198
|
});
|
|
@@ -200,15 +200,15 @@ describe('sales-overview baseline — bruzo (2026-09)', () => {
|
|
|
200
200
|
it('matches the pinned platform breakdown', () => {
|
|
201
201
|
const overview = (0, sales_overview_reference_1.computeSalesOverviewReference)(orders, monthFilters);
|
|
202
202
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.SALES_BY_PLATFORM])).toEqual({
|
|
203
|
-
'POS_TAKE-AWAY': { count: 414, grossAmount:
|
|
203
|
+
'POS_TAKE-AWAY': { count: 414, grossAmount: 465826 },
|
|
204
204
|
APP_DELIVERY: { count: 395, grossAmount: 496541 },
|
|
205
|
-
'POS_DINE-IN': { count: 388, grossAmount: 640803
|
|
206
|
-
WEB_DELIVERY: { count: 342, grossAmount:
|
|
207
|
-
'FOODPANDA_TAKE-AWAY': { count: 311, grossAmount:
|
|
205
|
+
'POS_DINE-IN': { count: 388, grossAmount: 640803 },
|
|
206
|
+
WEB_DELIVERY: { count: 342, grossAmount: 391439 },
|
|
207
|
+
'FOODPANDA_TAKE-AWAY': { count: 311, grossAmount: 375640 },
|
|
208
208
|
'APP_DINE-IN': { count: 80, grossAmount: 132715 },
|
|
209
209
|
'APP_TAKE-AWAY': { count: 63, grossAmount: 73220 },
|
|
210
|
-
POS_DELIVERY: { count: 41, grossAmount: 50899
|
|
211
|
-
'WEB_TAKE-AWAY': { count: 28, grossAmount: 26567
|
|
210
|
+
POS_DELIVERY: { count: 41, grossAmount: 50899 },
|
|
211
|
+
'WEB_TAKE-AWAY': { count: 28, grossAmount: 26567 },
|
|
212
212
|
FOODPANDA_DELIVERY: { count: 2, grossAmount: 2286 },
|
|
213
213
|
'POS_WALK-IN': { count: 2, grossAmount: 1186 },
|
|
214
214
|
TALABAT_DELIVERY: { count: 2, grossAmount: 2146 },
|
|
@@ -265,17 +265,17 @@ describe('sales-overview baseline — bruzo (2026-09)', () => {
|
|
|
265
265
|
saleType: constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED,
|
|
266
266
|
});
|
|
267
267
|
expect(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].count).toBe(2023);
|
|
268
|
-
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(
|
|
268
|
+
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(2613395);
|
|
269
269
|
expect(overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS]).toEqual([]);
|
|
270
270
|
// COMPLIMENTARY orders drop out of the collected view; the UNPAID bucket
|
|
271
271
|
// carries the credit bills + settled-later bills whose orders collected > 0.
|
|
272
272
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
273
|
-
CASH: { count: 770, grossAmount:
|
|
274
|
-
ONLINE: { count: 511, grossAmount:
|
|
275
|
-
CARD_PAYMENT: { count: 353, grossAmount:
|
|
276
|
-
FOODPANDA: { count: 309, grossAmount:
|
|
277
|
-
PLAZA: { count: 61, grossAmount: 83809
|
|
278
|
-
UNPAID: { count: 13, grossAmount: 23450
|
|
273
|
+
CASH: { count: 770, grossAmount: 936932 },
|
|
274
|
+
ONLINE: { count: 511, grossAmount: 577493 },
|
|
275
|
+
CARD_PAYMENT: { count: 353, grossAmount: 600671 },
|
|
276
|
+
FOODPANDA: { count: 309, grossAmount: 372894 },
|
|
277
|
+
PLAZA: { count: 61, grossAmount: 83809 },
|
|
278
|
+
UNPAID: { count: 13, grossAmount: 23450 },
|
|
279
279
|
MARKETING: { count: 4, grossAmount: 15078 },
|
|
280
280
|
GOLOOTLO: { count: 2, grossAmount: 3068 },
|
|
281
281
|
});
|
|
@@ -286,10 +286,10 @@ describe('sales-overview baseline — bruzo (2026-09)', () => {
|
|
|
286
286
|
saleType: constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS,
|
|
287
287
|
});
|
|
288
288
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES])).toEqual({
|
|
289
|
-
[BRUZO]: { count: 8, grossAmount: 13948
|
|
289
|
+
[BRUZO]: { count: 8, grossAmount: 13948 },
|
|
290
290
|
});
|
|
291
291
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
292
|
-
UNPAID: { count: 8, grossAmount: 13948
|
|
292
|
+
UNPAID: { count: 8, grossAmount: 13948 },
|
|
293
293
|
});
|
|
294
294
|
});
|
|
295
295
|
it('applies platform + order status filters together (aggregator store)', () => {
|
|
@@ -299,14 +299,14 @@ describe('sales-overview baseline — bruzo (2026-09)', () => {
|
|
|
299
299
|
orderStatuses: [constants_1.ORDER_STATUS_ENUM.COMPLETED, constants_1.ORDER_STATUS_ENUM.CANCELLED],
|
|
300
300
|
});
|
|
301
301
|
expect(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0]).toMatchObject({ count: 310 });
|
|
302
|
-
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(
|
|
302
|
+
expect(round2(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_SALES][0].grossAmount)).toBe(374991);
|
|
303
303
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.TOTAL_PAYMENT_SALES])).toEqual({
|
|
304
|
-
FOODPANDA: { count: 308, grossAmount:
|
|
304
|
+
FOODPANDA: { count: 308, grossAmount: 372245 },
|
|
305
305
|
PLAZA: { count: 1, grossAmount: 1648 },
|
|
306
306
|
UNPAID: { count: 1, grossAmount: 1098 },
|
|
307
307
|
});
|
|
308
308
|
expect(toSummaryMap(overview[constants_1.REPORT_TYPE_ENUM.SALES_BY_PLATFORM])).toEqual({
|
|
309
|
-
'FOODPANDA_TAKE-AWAY': { count: 310, grossAmount:
|
|
309
|
+
'FOODPANDA_TAKE-AWAY': { count: 310, grossAmount: 374991 },
|
|
310
310
|
});
|
|
311
311
|
const cancelled = overview[constants_1.REPORT_TYPE_ENUM.CANCELLED_ORDERS][0];
|
|
312
312
|
expect(cancelled).toMatchObject({ count: 2 });
|
|
@@ -15,7 +15,10 @@ const row = (over = {}) => ({
|
|
|
15
15
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
16
16
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL,
|
|
17
17
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION,
|
|
18
|
-
rate:
|
|
18
|
+
// NO stored rate: the source keeps the integer SUM of its percentage rates
|
|
19
|
+
// (in BASIS POINTS, 1% = 100 bps) and the COUNT of its percentage rows.
|
|
20
|
+
percentage_rate_sum: 15000,
|
|
21
|
+
percentage_row_count: 10,
|
|
19
22
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
20
23
|
order_count: 10,
|
|
21
24
|
row_count: 10,
|
|
@@ -44,7 +47,8 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
44
47
|
source_name: 'Manual / quick discount',
|
|
45
48
|
source_class: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM.MANUAL,
|
|
46
49
|
discount_amount: 50000,
|
|
47
|
-
|
|
50
|
+
percentage_rate_sum: null,
|
|
51
|
+
percentage_row_count: null,
|
|
48
52
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED,
|
|
49
53
|
}),
|
|
50
54
|
row({
|
|
@@ -81,15 +85,17 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
81
85
|
it('renders rate labels: percentage, mixed and fixed', () => {
|
|
82
86
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
83
87
|
report([
|
|
84
|
-
row({
|
|
88
|
+
row({ percentage_rate_sum: 15000, percentage_row_count: 10, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
|
|
85
89
|
row({
|
|
86
90
|
source_key: 'manual:item',
|
|
87
|
-
|
|
91
|
+
percentage_rate_sum: null,
|
|
92
|
+
percentage_row_count: null,
|
|
88
93
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED,
|
|
89
94
|
}),
|
|
90
95
|
row({
|
|
91
96
|
source_key: 'price_override:item',
|
|
92
|
-
|
|
97
|
+
percentage_rate_sum: null,
|
|
98
|
+
percentage_row_count: null,
|
|
93
99
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED,
|
|
94
100
|
}),
|
|
95
101
|
]),
|
|
@@ -102,22 +108,68 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
102
108
|
expect(formatted.sources.find((source) => source.source_key === 'manual:item')?.rate_kind_label).toBe('Mixed');
|
|
103
109
|
expect(formatted.sources.find((source) => source.source_key === 'price_override:item')?.rate_kind_label).toBe('Fixed');
|
|
104
110
|
});
|
|
105
|
-
it('
|
|
111
|
+
it('derives the rate from the integer sum/count (5000 / 1 -> 50%)', () => {
|
|
106
112
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
107
|
-
report([
|
|
113
|
+
report([
|
|
114
|
+
row({
|
|
115
|
+
percentage_rate_sum: 5000,
|
|
116
|
+
percentage_row_count: 1,
|
|
117
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
118
|
+
}),
|
|
119
|
+
]),
|
|
108
120
|
]);
|
|
109
121
|
const source = formatted.sources[0];
|
|
110
122
|
expect(source.rate_label).toBe('50%');
|
|
111
123
|
expect(source.rate_percent).toBe(50);
|
|
112
|
-
// The
|
|
124
|
+
// The formatted rate is the DERIVED average (basis points), not a stored field.
|
|
113
125
|
expect(source.rate).toBe(5000);
|
|
114
126
|
});
|
|
127
|
+
it('derives 2000 / 2 -> 10% from the integer sum/count', () => {
|
|
128
|
+
// 2000 basis points is the SUM of two 10% rows -> 1000 bps -> 10%.
|
|
129
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
130
|
+
report([
|
|
131
|
+
row({
|
|
132
|
+
percentage_rate_sum: 2000,
|
|
133
|
+
percentage_row_count: 2,
|
|
134
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
135
|
+
}),
|
|
136
|
+
]),
|
|
137
|
+
]);
|
|
138
|
+
const source = formatted.sources[0];
|
|
139
|
+
expect(source.rate_percent).toBe(10);
|
|
140
|
+
expect(source.rate_label).toBe('10%');
|
|
141
|
+
});
|
|
142
|
+
it('derives the EXACT average from the integer sum/count', () => {
|
|
143
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
144
|
+
report([
|
|
145
|
+
row({
|
|
146
|
+
percentage_rate_sum: 5000,
|
|
147
|
+
percentage_row_count: 3,
|
|
148
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
149
|
+
}),
|
|
150
|
+
]),
|
|
151
|
+
]);
|
|
152
|
+
const source = formatted.sources[0];
|
|
153
|
+
// 5000 / 3 bps = 16.6667% — the formatter derives it from the integers.
|
|
154
|
+
expect(source.rate_percent).toBeCloseTo(16.6667, 4);
|
|
155
|
+
expect(source.rate_label).toBe('16.67%');
|
|
156
|
+
});
|
|
115
157
|
it('keeps "mixed" and "—" when normalising (the rate kind wins)', () => {
|
|
116
158
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
117
159
|
report([
|
|
118
|
-
row({ source_key: 'discount:a',
|
|
119
|
-
row({
|
|
120
|
-
|
|
160
|
+
row({ source_key: 'discount:a', percentage_rate_sum: null, percentage_row_count: null, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED }),
|
|
161
|
+
row({
|
|
162
|
+
source_key: 'discount:b',
|
|
163
|
+
percentage_rate_sum: null,
|
|
164
|
+
percentage_row_count: null,
|
|
165
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
166
|
+
}),
|
|
167
|
+
row({
|
|
168
|
+
source_key: 'discount:c',
|
|
169
|
+
percentage_rate_sum: null,
|
|
170
|
+
percentage_row_count: null,
|
|
171
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED,
|
|
172
|
+
}),
|
|
121
173
|
]),
|
|
122
174
|
]);
|
|
123
175
|
expect(formatted.sources.find((source) => source.source_key === 'discount:a')?.rate_label).toBe('mixed');
|
|
@@ -203,43 +255,30 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
203
255
|
expect((0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([null])).toBeNull();
|
|
204
256
|
});
|
|
205
257
|
});
|
|
206
|
-
describe('
|
|
207
|
-
|
|
208
|
-
* THE RULE: a stored rate ABOVE 100 is cents-scaled (50% is stored as 5000)
|
|
209
|
-
* and is divided by 100; a rate of 100 or below is already a percentage.
|
|
210
|
-
*/
|
|
211
|
-
it('divides a cents-scaled rate by 100', () => {
|
|
212
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(5000)).toBe(50);
|
|
213
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(2000)).toBe(20);
|
|
214
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(1500)).toBe(15);
|
|
215
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(10000)).toBe(100);
|
|
216
|
-
});
|
|
217
|
-
it('keeps a plain percentage as-is', () => {
|
|
218
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(100)).toBe(100);
|
|
219
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(15)).toBe(15);
|
|
220
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(1)).toBe(1);
|
|
221
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(0)).toBe(0);
|
|
222
|
-
});
|
|
223
|
-
it('returns null for a missing or non-finite rate', () => {
|
|
224
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(null)).toBeNull();
|
|
225
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(undefined)).toBeNull();
|
|
226
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(Number.NaN)).toBeNull();
|
|
227
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(Number.POSITIVE_INFINITY)).toBeNull();
|
|
228
|
-
});
|
|
229
|
-
it('renders the label of every production rate shape', () => {
|
|
258
|
+
describe('the stored rate is BASIS POINTS (no magnitude heuristic)', () => {
|
|
259
|
+
it('converts every production rate shape', () => {
|
|
230
260
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
231
261
|
report([
|
|
232
|
-
row({ source_key: 'a',
|
|
233
|
-
row({ source_key: 'b',
|
|
234
|
-
row({ source_key: 'c',
|
|
235
|
-
row({ source_key: 'd',
|
|
236
|
-
row({ source_key: 'e',
|
|
237
|
-
row({ source_key: 'f',
|
|
262
|
+
row({ source_key: 'a', percentage_rate_sum: 5000, percentage_row_count: 1 }),
|
|
263
|
+
row({ source_key: 'b', percentage_rate_sum: 2000, percentage_row_count: 1 }),
|
|
264
|
+
row({ source_key: 'c', percentage_rate_sum: 1500, percentage_row_count: 1 }),
|
|
265
|
+
row({ source_key: 'd', percentage_rate_sum: 10000, percentage_row_count: 1 }),
|
|
266
|
+
row({ source_key: 'e', percentage_rate_sum: 15000, percentage_row_count: 10 }),
|
|
267
|
+
row({ source_key: 'f', percentage_rate_sum: null, percentage_row_count: null }),
|
|
238
268
|
]),
|
|
239
269
|
]);
|
|
240
270
|
const labels = Object.fromEntries(formatted.sources.map((source) => [source.source_key, source.rate_label]));
|
|
241
271
|
expect(labels).toEqual({ a: '50%', b: '20%', c: '15%', d: '100%', e: '15%', f: '—' });
|
|
242
272
|
});
|
|
273
|
+
it('never guesses the unit from the magnitude of a value', () => {
|
|
274
|
+
// 100 bps is 1% — NOT "100%" and not "1". The unit is fixed by the
|
|
275
|
+
// contract, so the same division applies to every value.
|
|
276
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
277
|
+
report([row({ percentage_rate_sum: 100, percentage_row_count: 1 })]),
|
|
278
|
+
]);
|
|
279
|
+
expect(formatted.sources[0].rate_label).toBe('1%');
|
|
280
|
+
expect(formatted.sources[0].rate_percent).toBe(1);
|
|
281
|
+
});
|
|
243
282
|
});
|
|
244
283
|
describe('getDiscountSourceShareReconciliation', () => {
|
|
245
284
|
it('reports an unattributed GAP when summary > source', () => {
|