@managesome/eposmatic-toolkit 0.4.26 → 0.4.28
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-scenarios.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-scenarios.test.js +676 -0
- package/lib/tests/materialized-reports/materialized-discount-sources.test.js +148 -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/real-discount-orders.test.d.ts +1 -0
- package/lib/tests/materialized-reports/real-discount-orders.test.js +110 -0
- package/lib/tests/materialized-reports/sales-overview-baseline.test.js +51 -51
- package/lib/tests/materialized-reports/tenant-discount-source-formatter.test.js +89 -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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const globals_1 = require("@jest/globals");
|
|
10
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
11
|
+
const materialized_discount_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-compile-helpers");
|
|
12
|
+
const materialized_discount_source_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-source-helpers");
|
|
13
|
+
const materialized_integer_contract_1 = require("../../helpers/materialized-reports/materialized-integer-contract");
|
|
14
|
+
const ORDERS = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '..', 'real-discount-orders-2026-10-23.json'), 'utf8'));
|
|
15
|
+
const TENANT = 'thailemon.uae';
|
|
16
|
+
const BRAND = 'thailemon.co.nz';
|
|
17
|
+
const DAY = '2026-10-23';
|
|
18
|
+
const MONTH = '2026-10';
|
|
19
|
+
const compile = () => (0, materialized_discount_compile_helpers_1.compileTenantDiscountReports)({
|
|
20
|
+
tenantId: TENANT,
|
|
21
|
+
brandId: BRAND,
|
|
22
|
+
localDate: DAY,
|
|
23
|
+
orders: ORDERS,
|
|
24
|
+
gmtOffset: 5,
|
|
25
|
+
computedAt: new Date('2026-10-23T23:59:00.000Z'),
|
|
26
|
+
});
|
|
27
|
+
const sourcesForMonth = () => {
|
|
28
|
+
const compiled = compile();
|
|
29
|
+
const entry = compiled.entries.find((e) => e.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH);
|
|
30
|
+
return {
|
|
31
|
+
compiled,
|
|
32
|
+
sources: (0, materialized_discount_source_helpers_1.buildDiscountSourcesForScope)({
|
|
33
|
+
tenantId: TENANT,
|
|
34
|
+
brandId: BRAND,
|
|
35
|
+
scopeContext: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
36
|
+
scopeField: MONTH,
|
|
37
|
+
dayIndex: null,
|
|
38
|
+
sections: entry.discount_entries,
|
|
39
|
+
computedAt: new Date('2026-10-23T23:59:00.000Z'),
|
|
40
|
+
sourceWatermark: null,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
(0, globals_1.describe)('real 2026-10-23 discount orders', () => {
|
|
45
|
+
(0, globals_1.it)('contains all 19 reference orders, including the no-discount control', () => {
|
|
46
|
+
strict_1.default.equal(ORDERS.length, 19);
|
|
47
|
+
strict_1.default.deepEqual(ORDERS.map((order) => order.order_number).sort((a, b) => a - b), Array.from({ length: 19 }, (_, index) => 55 + index));
|
|
48
|
+
});
|
|
49
|
+
(0, globals_1.it)('compiles 18 contributing orders and reconciles source money to report money', () => {
|
|
50
|
+
const { compiled, sources } = sourcesForMonth();
|
|
51
|
+
strict_1.default.equal(compiled.contributingOrders, 18);
|
|
52
|
+
const monthReport = compiled.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH);
|
|
53
|
+
const reportTotal = Object.values(monthReport.discount_counters ?? {}).reduce((sum, counters) => sum + (counters.amount ?? 0), 0);
|
|
54
|
+
const sourceTotal = sources.reduce((sum, source) => sum + source.discount_amount, 0);
|
|
55
|
+
strict_1.default.equal(reportTotal, 311490);
|
|
56
|
+
strict_1.default.equal(sourceTotal, 311490);
|
|
57
|
+
strict_1.default.equal(sources.filter((source) => source.source_class === 'COMPLIMENTARY').length, 2);
|
|
58
|
+
strict_1.default.equal(sources.filter((source) => source.kind === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.FREE_ITEM).length, 2);
|
|
59
|
+
strict_1.default.equal(sources.reduce((sum, source) => sum + source.free_item_count, 0), 4);
|
|
60
|
+
});
|
|
61
|
+
(0, globals_1.it)('keeps the expected source rows and distinct order counts', () => {
|
|
62
|
+
const { sources } = sourcesForMonth();
|
|
63
|
+
const byKey = new Map(sources.map((source) => [`${source.source_key}|${source.level}`, source]));
|
|
64
|
+
const expected = [
|
|
65
|
+
['manual:order', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER, 3, 90000],
|
|
66
|
+
['manual:item', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 4, 43490],
|
|
67
|
+
['price_override:item', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 1, 25000],
|
|
68
|
+
['catalog:auto', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 3, 70000],
|
|
69
|
+
['loyalty:wallet_cashback', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER, 1, 50000],
|
|
70
|
+
['discount:68cbaf10f365eb45bdbee96d', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 1, 15000],
|
|
71
|
+
['discount:6adb1adfa5fa4b8c498e65ec', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER, 1, 10000],
|
|
72
|
+
['voucher:6abf432e5e03cc49e2462a62', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER, 1, 5000],
|
|
73
|
+
['loyalty:offer:6ad9fa14ae19ab3c25c18a8a', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 1, 2000],
|
|
74
|
+
['loyalty:offer:6ad9f91eae19ab3c25c18a89', MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM, 1, 1000],
|
|
75
|
+
];
|
|
76
|
+
for (const [key, level, orderCount, amount] of expected) {
|
|
77
|
+
const source = byKey.get(`${key}|${level}`);
|
|
78
|
+
strict_1.default.ok(source, `missing ${key}`);
|
|
79
|
+
strict_1.default.equal(source.order_count, orderCount, String(key));
|
|
80
|
+
strict_1.default.equal(source.discount_amount, amount, String(key));
|
|
81
|
+
}
|
|
82
|
+
strict_1.default.equal(byKey.get('complimentary:full|PAYMENT')?.covered_amount, 50000);
|
|
83
|
+
strict_1.default.equal(byKey.get('complimentary:partial|PAYMENT')?.covered_amount, 25000);
|
|
84
|
+
strict_1.default.equal(byKey.get('complimentary:full|PAYMENT')?.complimentary_full, true);
|
|
85
|
+
strict_1.default.equal(byKey.get('complimentary:partial|PAYMENT')?.complimentary_full, false);
|
|
86
|
+
});
|
|
87
|
+
(0, globals_1.it)('derives rates from integer sum/count only and never stores an average', () => {
|
|
88
|
+
const { sources } = sourcesForMonth();
|
|
89
|
+
for (const source of sources) {
|
|
90
|
+
strict_1.default.equal('rate' in source, false, `${source.source_key} stored rate`);
|
|
91
|
+
strict_1.default.ok(Number.isInteger(source.percentage_rate_sum));
|
|
92
|
+
strict_1.default.ok(Number.isInteger(source.percentage_row_count));
|
|
93
|
+
strict_1.default.ok(Number.isInteger(source.discount_amount));
|
|
94
|
+
}
|
|
95
|
+
const manualItem = sources.find((source) => source.source_key === 'manual:item');
|
|
96
|
+
strict_1.default.equal(manualItem.percentage_rate_sum, 18000);
|
|
97
|
+
strict_1.default.equal(manualItem.percentage_row_count, 4);
|
|
98
|
+
strict_1.default.equal(manualItem.rate_kind, 'PERCENTAGE');
|
|
99
|
+
const manualOrder = sources.find((source) => source.source_key === 'manual:order');
|
|
100
|
+
strict_1.default.equal(manualOrder.rate_kind, 'MIXED');
|
|
101
|
+
strict_1.default.equal(manualOrder.percentage_rate_sum, 10000);
|
|
102
|
+
strict_1.default.equal(manualOrder.percentage_row_count, 2);
|
|
103
|
+
});
|
|
104
|
+
(0, globals_1.it)('passes the recursive integer-only contract for reports, entries and sources', () => {
|
|
105
|
+
const { compiled, sources } = sourcesForMonth();
|
|
106
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.reports, { collection: 'reports' });
|
|
107
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(compiled.entries, { collection: 'entries' });
|
|
108
|
+
(0, materialized_integer_contract_1.assertIntegerOnlyDocuments)(sources, { collection: 'sources' });
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -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 });
|