@managesome/eposmatic-toolkit 0.4.52 → 0.4.54
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 +6 -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/report-platform/definition.js +508 -0
- package/esm/helpers/materialized-reports/report-platform/index.js +4 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/budget.js +27 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +12 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +121 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +14 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/index.js +8 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +10 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +42 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +28 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/top-n.js +24 -0
- package/esm/helpers/materialized-reports/report-platform/registry.js +23 -0
- package/esm/helpers/materialized-reports/report-platform/validate-report-registry.js +214 -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 +6 -0
- package/lib/helpers/materialized-reports/index.js +6 -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/report-platform/definition.d.ts +133 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +511 -0
- package/lib/helpers/materialized-reports/report-platform/index.d.ts +4 -0
- package/lib/helpers/materialized-reports/report-platform/index.js +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.d.ts +40 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +130 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.d.ts +22 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +17 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.js +24 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +47 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.d.ts +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.js +29 -0
- package/lib/helpers/materialized-reports/report-platform/registry.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/registry.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.js +218 -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/characterization/delivery.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.js +229 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.js +99 -0
- package/lib/tests/materialized-reports/characterization/fixtures.d.ts +30 -0
- package/lib/tests/materialized-reports/characterization/fixtures.js +402 -0
- package/lib/tests/materialized-reports/characterization/golden.d.ts +18 -0
- package/lib/tests/materialized-reports/characterization/golden.js +127 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.js +69 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.js +102 -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/materialized-reports/report-platform/lifecycle-primitives.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.js +177 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +214 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.js +103 -0
- 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 +6 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHASE 1 CHARACTERIZATION FIXTURES (test-only).
|
|
3
|
+
*
|
|
4
|
+
* One compact tenant-day corpus used by the toolkit compile/formatter goldens and
|
|
5
|
+
* mirrored by the workers close-day goldens. It deliberately contains the known
|
|
6
|
+
* oddities so later platform work cannot "fix" them silently:
|
|
7
|
+
*
|
|
8
|
+
* - a deferred PAY_LATER credit bill issued on the day;
|
|
9
|
+
* - a prior-day credit bill collected on the day;
|
|
10
|
+
* - MEASURED / zero-minute / UNMEASURED prep rows and all four target sources;
|
|
11
|
+
* - order-level and item-level discounts, a cancellation and a free item;
|
|
12
|
+
* - delivery adoption (off-app order), reassignment, an orphan delivery,
|
|
13
|
+
* a cancelled delivery and invalid (0,0) coordinates.
|
|
14
|
+
*
|
|
15
|
+
* Dates are fixed. `_id`s are fixed strings; the golden helper still replaces them
|
|
16
|
+
* with stable placeholders because several production builders mint ObjectIds.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CHARACTERIZATION_TENANT_ID = "tenant-characterization";
|
|
19
|
+
export declare const CHARACTERIZATION_BRAND_ID = "brand-characterization";
|
|
20
|
+
export declare const CHARACTERIZATION_TENANT_NAME = "Characterization Store";
|
|
21
|
+
export declare const CHARACTERIZATION_DAY = "2026-09-14";
|
|
22
|
+
export declare const CHARACTERIZATION_PREV_DAY = "2026-09-13";
|
|
23
|
+
export declare const CHARACTERIZATION_NEXT_DAY = "2026-09-15";
|
|
24
|
+
export declare const CHARACTERIZATION_COMPUTED_AT: Date;
|
|
25
|
+
export interface ICharacterizationFixtures {
|
|
26
|
+
orders: any[];
|
|
27
|
+
deliveries: any[];
|
|
28
|
+
dayOrders: any[];
|
|
29
|
+
}
|
|
30
|
+
export declare function buildCharacterizationFixtures(): ICharacterizationFixtures;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CHARACTERIZATION_COMPUTED_AT = exports.CHARACTERIZATION_NEXT_DAY = exports.CHARACTERIZATION_PREV_DAY = exports.CHARACTERIZATION_DAY = exports.CHARACTERIZATION_TENANT_NAME = exports.CHARACTERIZATION_BRAND_ID = exports.CHARACTERIZATION_TENANT_ID = void 0;
|
|
4
|
+
exports.buildCharacterizationFixtures = buildCharacterizationFixtures;
|
|
5
|
+
const constants_1 = require("../../../constants");
|
|
6
|
+
/**
|
|
7
|
+
* PHASE 1 CHARACTERIZATION FIXTURES (test-only).
|
|
8
|
+
*
|
|
9
|
+
* One compact tenant-day corpus used by the toolkit compile/formatter goldens and
|
|
10
|
+
* mirrored by the workers close-day goldens. It deliberately contains the known
|
|
11
|
+
* oddities so later platform work cannot "fix" them silently:
|
|
12
|
+
*
|
|
13
|
+
* - a deferred PAY_LATER credit bill issued on the day;
|
|
14
|
+
* - a prior-day credit bill collected on the day;
|
|
15
|
+
* - MEASURED / zero-minute / UNMEASURED prep rows and all four target sources;
|
|
16
|
+
* - order-level and item-level discounts, a cancellation and a free item;
|
|
17
|
+
* - delivery adoption (off-app order), reassignment, an orphan delivery,
|
|
18
|
+
* a cancelled delivery and invalid (0,0) coordinates.
|
|
19
|
+
*
|
|
20
|
+
* Dates are fixed. `_id`s are fixed strings; the golden helper still replaces them
|
|
21
|
+
* with stable placeholders because several production builders mint ObjectIds.
|
|
22
|
+
*/
|
|
23
|
+
exports.CHARACTERIZATION_TENANT_ID = 'tenant-characterization';
|
|
24
|
+
exports.CHARACTERIZATION_BRAND_ID = 'brand-characterization';
|
|
25
|
+
exports.CHARACTERIZATION_TENANT_NAME = 'Characterization Store';
|
|
26
|
+
exports.CHARACTERIZATION_DAY = '2026-09-14';
|
|
27
|
+
exports.CHARACTERIZATION_PREV_DAY = '2026-09-13';
|
|
28
|
+
exports.CHARACTERIZATION_NEXT_DAY = '2026-09-15';
|
|
29
|
+
exports.CHARACTERIZATION_COMPUTED_AT = new Date('2026-09-15T10:00:00.000Z');
|
|
30
|
+
const at = (day, time) => new Date(`${day}T${time}.000Z`);
|
|
31
|
+
const cashPayment = (amount, refunded = 0) => ({
|
|
32
|
+
_id: `pay-cash-${amount}-${refunded}`,
|
|
33
|
+
payment_id: `pay-cash-${amount}-${refunded}`,
|
|
34
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.CASH,
|
|
35
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.SETTLED,
|
|
36
|
+
amount_due: amount,
|
|
37
|
+
amount_paid: amount,
|
|
38
|
+
amount_refunded: refunded,
|
|
39
|
+
card_details: null,
|
|
40
|
+
});
|
|
41
|
+
const cardPayment = (amount, charges = 25) => ({
|
|
42
|
+
_id: `pay-card-${amount}`,
|
|
43
|
+
payment_id: `pay-card-${amount}`,
|
|
44
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.CARD,
|
|
45
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.SETTLED,
|
|
46
|
+
amount_due: amount,
|
|
47
|
+
amount_paid: amount,
|
|
48
|
+
amount_refunded: 0,
|
|
49
|
+
card_details: { card_charges: charges },
|
|
50
|
+
});
|
|
51
|
+
const payLaterPayment = (amountDue, amountPaid, status) => ({
|
|
52
|
+
_id: `pay-later-${amountDue}-${amountPaid}`,
|
|
53
|
+
payment_id: `pay-later-${amountDue}-${amountPaid}`,
|
|
54
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.PAY_LATER,
|
|
55
|
+
payment_status: status,
|
|
56
|
+
amount_due: amountDue,
|
|
57
|
+
amount_paid: amountPaid,
|
|
58
|
+
amount_refunded: 0,
|
|
59
|
+
card_details: null,
|
|
60
|
+
});
|
|
61
|
+
const order = (over = {}) => {
|
|
62
|
+
const localDate = over.localDate ?? exports.CHARACTERIZATION_DAY;
|
|
63
|
+
const localHour = over.localHour ?? 12;
|
|
64
|
+
return {
|
|
65
|
+
_id: over._id ?? 'order-base',
|
|
66
|
+
tenant_id: exports.CHARACTERIZATION_TENANT_ID,
|
|
67
|
+
platform: over.platform ?? 'POS_DINE-IN',
|
|
68
|
+
order_status: over.order_status ?? constants_1.ORDER_STATUS_ENUM.COMPLETED,
|
|
69
|
+
order_number: over.order_number ?? 1,
|
|
70
|
+
price: over.price ?? 10000,
|
|
71
|
+
amount_earned: over.amount_earned ?? 10000,
|
|
72
|
+
amount_collected: over.amount_collected ?? 10000,
|
|
73
|
+
total_discount_applied: over.total_discount_applied ?? 0,
|
|
74
|
+
gst_amount: over.gst_amount ?? 0,
|
|
75
|
+
tax_amount: over.tax_amount ?? 0,
|
|
76
|
+
tip_amount: over.tip_amount ?? 0,
|
|
77
|
+
deferred_settlement: over.deferred_settlement ?? false,
|
|
78
|
+
is_deleted: false,
|
|
79
|
+
localDate,
|
|
80
|
+
localHour,
|
|
81
|
+
order_settled_at: over.order_settled_at === undefined
|
|
82
|
+
? at(localDate, `${String(localHour).padStart(2, '0')}:00:00`)
|
|
83
|
+
: over.order_settled_at,
|
|
84
|
+
createdAt: over.createdAt ?? at(localDate, '11:00:00'),
|
|
85
|
+
updatedAt: over.updatedAt ?? at(localDate, '12:00:00'),
|
|
86
|
+
categories: over.categories ?? [],
|
|
87
|
+
payments: over.payments ?? [],
|
|
88
|
+
delivery_details: over.delivery_details ?? null,
|
|
89
|
+
dinein_details: over.dinein_details ?? null,
|
|
90
|
+
wallet_redemptions: over.wallet_redemptions ?? null,
|
|
91
|
+
order_discount_details: over.order_discount_details ?? null,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const item = (id, over = {}) => ({
|
|
95
|
+
_id: `line-${id}`,
|
|
96
|
+
item_id: `catalog-${id}`,
|
|
97
|
+
name: `Item ${id}`,
|
|
98
|
+
item_type: 'REGULAR',
|
|
99
|
+
quantity: 1,
|
|
100
|
+
price: 5000,
|
|
101
|
+
subtotal: 5000,
|
|
102
|
+
_gross_amount: 5000,
|
|
103
|
+
_net_amount: 5000,
|
|
104
|
+
_discount_amount: 0,
|
|
105
|
+
is_ready: true,
|
|
106
|
+
ready_minutes: 5,
|
|
107
|
+
prep_started_at: at(exports.CHARACTERIZATION_DAY, '10:00:00'),
|
|
108
|
+
item_discount_details: null,
|
|
109
|
+
...over,
|
|
110
|
+
});
|
|
111
|
+
const deliveryDetails = (over = {}) => ({
|
|
112
|
+
city: over.city ?? 'Istanbul',
|
|
113
|
+
state: over.state ?? over.city ?? 'Istanbul',
|
|
114
|
+
street: 'Characterization Street 1',
|
|
115
|
+
zip_code: '34000',
|
|
116
|
+
country_code: 'TR',
|
|
117
|
+
address_instructions: '',
|
|
118
|
+
delivery_code: `D-${over.city ?? 'Istanbul'}`,
|
|
119
|
+
delivery_cost: over.delivery_cost ?? 300,
|
|
120
|
+
estimated_delivery_time: null,
|
|
121
|
+
distance_in_meters_from_store: over.distance ?? 3000,
|
|
122
|
+
lat: over.lat === undefined ? 41.0082 : over.lat,
|
|
123
|
+
lng: over.lng === undefined ? 28.9784 : over.lng,
|
|
124
|
+
});
|
|
125
|
+
const delivery = (over) => {
|
|
126
|
+
const status = over.status ?? 'COMPLETED';
|
|
127
|
+
return {
|
|
128
|
+
_id: over._id,
|
|
129
|
+
tenant_id: exports.CHARACTERIZATION_TENANT_ID,
|
|
130
|
+
order_id: over.order_id,
|
|
131
|
+
order_number: over.order_number ?? 1,
|
|
132
|
+
rider_id: over.rider_id ?? 'rider-1',
|
|
133
|
+
rider_name: over.rider_name ?? 'Rider One',
|
|
134
|
+
status,
|
|
135
|
+
cancel_reason: over.cancel_reason ?? null,
|
|
136
|
+
localDate: over.localDate ?? exports.CHARACTERIZATION_DAY,
|
|
137
|
+
distance_in_meters_from_store: over.distance ?? 3000,
|
|
138
|
+
tracking_enabled: over.tracking_enabled ?? false,
|
|
139
|
+
pickup_food_image_url: null,
|
|
140
|
+
dropoff_food_image_url: null,
|
|
141
|
+
assigned_at: over.assigned_at ?? at(exports.CHARACTERIZATION_DAY, '10:02:00'),
|
|
142
|
+
picked_up_at: over.picked_up_at ?? at(exports.CHARACTERIZATION_DAY, '10:12:00'),
|
|
143
|
+
expected_delivery_at: over.expected_delivery_at ?? at(exports.CHARACTERIZATION_DAY, '10:45:00'),
|
|
144
|
+
delivered_at: over.delivered_at === undefined
|
|
145
|
+
? status === 'CANCELLED'
|
|
146
|
+
? null
|
|
147
|
+
: at(exports.CHARACTERIZATION_DAY, '10:28:00')
|
|
148
|
+
: over.delivered_at,
|
|
149
|
+
cancelled_at: over.cancelled_at === undefined
|
|
150
|
+
? status === 'CANCELLED'
|
|
151
|
+
? at(exports.CHARACTERIZATION_DAY, '10:20:00')
|
|
152
|
+
: null
|
|
153
|
+
: over.cancelled_at,
|
|
154
|
+
status_updated_count: over.status_updated_count ?? 2,
|
|
155
|
+
delivery_minutes: status === 'COMPLETED' ? 23 : null,
|
|
156
|
+
rider_earnings: over.rider_earnings ?? {
|
|
157
|
+
amount: status === 'COMPLETED' ? 500 : 0,
|
|
158
|
+
status: status === 'COMPLETED'
|
|
159
|
+
? constants_1.RIDER_EARNINGS_STATUS_ENUM.FINAL
|
|
160
|
+
: status === 'CANCELLED'
|
|
161
|
+
? constants_1.RIDER_EARNINGS_STATUS_ENUM.VOID
|
|
162
|
+
: constants_1.RIDER_EARNINGS_STATUS_ENUM.PENDING,
|
|
163
|
+
rule_type: constants_1.RIDER_FEE_TYPE_ENUM.DISTANCE_ONE_WAY,
|
|
164
|
+
per_meter: 5000,
|
|
165
|
+
distance_step: 1000,
|
|
166
|
+
distance_meters: over.distance ?? 3000,
|
|
167
|
+
delivery_charge: 300,
|
|
168
|
+
calculated_at: status === 'COMPLETED' ? at(exports.CHARACTERIZATION_DAY, '10:28:00') : null,
|
|
169
|
+
version: 1,
|
|
170
|
+
},
|
|
171
|
+
polyline: [],
|
|
172
|
+
createdAt: over.createdAt ?? at(exports.CHARACTERIZATION_DAY, '10:00:00'),
|
|
173
|
+
updatedAt: over.updatedAt ?? at(exports.CHARACTERIZATION_DAY, '10:30:00'),
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
function buildCharacterizationFixtures() {
|
|
177
|
+
const dayOrders = [];
|
|
178
|
+
// ---- 1. Dine-in: order-level fixed discount, MEASURED / instant / unmeasured prep.
|
|
179
|
+
dayOrders.push(order({
|
|
180
|
+
_id: 'order-dine-in',
|
|
181
|
+
order_number: 101,
|
|
182
|
+
platform: 'POS_DINE-IN',
|
|
183
|
+
total_discount_applied: 1000,
|
|
184
|
+
amount_earned: 9000,
|
|
185
|
+
amount_collected: 9000,
|
|
186
|
+
tip_amount: 200,
|
|
187
|
+
dinein_details: { prep_minutes: 10 },
|
|
188
|
+
order_discount_details: {
|
|
189
|
+
total_discount: 1000,
|
|
190
|
+
special_discount: 1000,
|
|
191
|
+
special_discount_id: 'collection-discount-1',
|
|
192
|
+
is_special_discount_percentage: false,
|
|
193
|
+
},
|
|
194
|
+
categories: [
|
|
195
|
+
{
|
|
196
|
+
category_id: 'cat-mains',
|
|
197
|
+
name: 'Mains',
|
|
198
|
+
items: [
|
|
199
|
+
item('measured-9', { ready_minutes: 9 }),
|
|
200
|
+
item('instant-0', { ready_minutes: 0 }),
|
|
201
|
+
item('unmeasured-20', { ready_minutes: 20, prep_started_at: null }),
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
payments: [cashPayment(8800)],
|
|
206
|
+
}));
|
|
207
|
+
// ---- 2. Takeaway: item-level 100% free item + voucher reference + card charges.
|
|
208
|
+
dayOrders.push(order({
|
|
209
|
+
_id: 'order-takeaway',
|
|
210
|
+
order_number: 102,
|
|
211
|
+
platform: 'POS_TAKE-AWAY',
|
|
212
|
+
total_discount_applied: 500,
|
|
213
|
+
amount_earned: 4500,
|
|
214
|
+
amount_collected: 4500,
|
|
215
|
+
order_discount_details: {
|
|
216
|
+
total_discount: 500,
|
|
217
|
+
voucher_discount: 500,
|
|
218
|
+
voucher_reference_number: 'VOUCHER-CHAR-1',
|
|
219
|
+
is_voucher_discount_percentage: false,
|
|
220
|
+
},
|
|
221
|
+
categories: [
|
|
222
|
+
{
|
|
223
|
+
category_id: 'cat-free',
|
|
224
|
+
name: 'Free items',
|
|
225
|
+
items: [
|
|
226
|
+
item('free', {
|
|
227
|
+
price: 5000,
|
|
228
|
+
_gross_amount: 5000,
|
|
229
|
+
// 100% item discount => FREE_ITEM row.
|
|
230
|
+
_net_amount: 0,
|
|
231
|
+
_discount_amount: 5000,
|
|
232
|
+
item_discount_details: {
|
|
233
|
+
total_discount: 5000,
|
|
234
|
+
special_discount: 5000,
|
|
235
|
+
special_discount_id: constants_1.MATERIALIZED_DISCOUNT_SPECIAL_DISCOUNT_ID,
|
|
236
|
+
is_special_discount_percentage: true,
|
|
237
|
+
},
|
|
238
|
+
prep_started_at: null,
|
|
239
|
+
ready_minutes: null,
|
|
240
|
+
is_ready: false,
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
payments: [cardPayment(4500)],
|
|
246
|
+
}));
|
|
247
|
+
// ---- 3. Cancelled aggregator order: refunded payment, loyalty discount.
|
|
248
|
+
dayOrders.push(order({
|
|
249
|
+
_id: 'order-cancelled',
|
|
250
|
+
order_number: 103,
|
|
251
|
+
platform: 'FOODPANDA',
|
|
252
|
+
order_status: constants_1.ORDER_STATUS_ENUM.CANCELLED,
|
|
253
|
+
total_discount_applied: 300,
|
|
254
|
+
amount_earned: 0,
|
|
255
|
+
amount_collected: 0,
|
|
256
|
+
order_discount_details: {
|
|
257
|
+
total_discount: 300,
|
|
258
|
+
loyalty_discount: 300,
|
|
259
|
+
loyalty_discount_id: 'offer-char-1',
|
|
260
|
+
is_loyalty_discount_percentage: false,
|
|
261
|
+
},
|
|
262
|
+
categories: [
|
|
263
|
+
{
|
|
264
|
+
category_id: 'cat-cancelled',
|
|
265
|
+
name: 'Mains',
|
|
266
|
+
items: [item('cancelled-item', { prep_started_at: null, ready_minutes: null })],
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
payments: [cashPayment(4700, 4700)],
|
|
270
|
+
}));
|
|
271
|
+
// ---- 4. Deferred PAY_LATER credit bill issued on the day.
|
|
272
|
+
dayOrders.push(order({
|
|
273
|
+
_id: 'order-credit-issued',
|
|
274
|
+
order_number: 104,
|
|
275
|
+
platform: 'POS_DINE-IN',
|
|
276
|
+
deferred_settlement: true,
|
|
277
|
+
order_settled_at: null,
|
|
278
|
+
amount_collected: 0,
|
|
279
|
+
categories: [
|
|
280
|
+
{
|
|
281
|
+
category_id: 'cat-credit',
|
|
282
|
+
name: 'Mains',
|
|
283
|
+
items: [item('credit-item', { prep_started_at: null, ready_minutes: null })],
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
payments: [payLaterPayment(6000, 0, constants_1.PAYMENT_STATUS_ENUM.PENDING)],
|
|
287
|
+
}));
|
|
288
|
+
// ---- 5. No prep signal at all (coverage denominator, UNMEASURED).
|
|
289
|
+
dayOrders.push(order({
|
|
290
|
+
_id: 'order-no-prep',
|
|
291
|
+
order_number: 105,
|
|
292
|
+
platform: 'POS_WALK-IN',
|
|
293
|
+
price: 1200,
|
|
294
|
+
amount_earned: 1200,
|
|
295
|
+
amount_collected: 1200,
|
|
296
|
+
categories: [
|
|
297
|
+
{
|
|
298
|
+
category_id: 'cat-drinks',
|
|
299
|
+
name: 'Drinks',
|
|
300
|
+
items: [item('no-signal', { prep_started_at: null, ready_minutes: null, is_ready: false })],
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
payments: [cashPayment(1200)],
|
|
304
|
+
}));
|
|
305
|
+
// ---- 6-9. Delivery demand: app order, reassigned app order, off-app order, unknown geo.
|
|
306
|
+
dayOrders.push(order({
|
|
307
|
+
_id: 'order-delivery-istanbul',
|
|
308
|
+
order_number: 106,
|
|
309
|
+
platform: 'POS_DELIVERY',
|
|
310
|
+
delivery_details: deliveryDetails({ city: 'Istanbul' }),
|
|
311
|
+
payments: [cashPayment(5300)],
|
|
312
|
+
}), order({
|
|
313
|
+
_id: 'order-delivery-ankara',
|
|
314
|
+
order_number: 107,
|
|
315
|
+
platform: 'APP_DELIVERY',
|
|
316
|
+
delivery_details: deliveryDetails({ city: 'Ankara', lat: 39.9334, lng: 32.8597 }),
|
|
317
|
+
payments: [cashPayment(5300)],
|
|
318
|
+
}), order({
|
|
319
|
+
_id: 'order-delivery-offapp',
|
|
320
|
+
order_number: 108,
|
|
321
|
+
platform: 'WEB_DELIVERY',
|
|
322
|
+
delivery_details: deliveryDetails({ city: 'Izmir', lat: 38.4237, lng: 27.1428 }),
|
|
323
|
+
payments: [cashPayment(5300)],
|
|
324
|
+
}), order({
|
|
325
|
+
_id: 'order-delivery-unknown',
|
|
326
|
+
order_number: 109,
|
|
327
|
+
platform: 'POS_DELIVERY',
|
|
328
|
+
delivery_details: deliveryDetails({ city: null, state: null, lat: 0, lng: 0 }),
|
|
329
|
+
payments: [cashPayment(5300)],
|
|
330
|
+
}));
|
|
331
|
+
const deliveries = [
|
|
332
|
+
delivery({
|
|
333
|
+
_id: 'delivery-istanbul',
|
|
334
|
+
order_id: 'order-delivery-istanbul',
|
|
335
|
+
rider_id: 'rider-1',
|
|
336
|
+
rider_name: 'Rider One',
|
|
337
|
+
}),
|
|
338
|
+
// Reassignment: one cancelled attempt + one completed attempt for the same order.
|
|
339
|
+
delivery({
|
|
340
|
+
_id: 'delivery-ankara-a',
|
|
341
|
+
order_id: 'order-delivery-ankara',
|
|
342
|
+
rider_id: 'rider-2',
|
|
343
|
+
rider_name: 'Rider Two',
|
|
344
|
+
status: 'CANCELLED',
|
|
345
|
+
cancel_reason: 'Rider unavailable',
|
|
346
|
+
rider_earnings: {
|
|
347
|
+
amount: 0,
|
|
348
|
+
status: constants_1.RIDER_EARNINGS_STATUS_ENUM.VOID,
|
|
349
|
+
rule_type: constants_1.RIDER_FEE_TYPE_ENUM.DISTANCE_ONE_WAY,
|
|
350
|
+
per_meter: 5000,
|
|
351
|
+
distance_step: 1000,
|
|
352
|
+
distance_meters: 3000,
|
|
353
|
+
delivery_charge: 300,
|
|
354
|
+
calculated_at: null,
|
|
355
|
+
version: 1,
|
|
356
|
+
},
|
|
357
|
+
}),
|
|
358
|
+
delivery({
|
|
359
|
+
_id: 'delivery-ankara-b',
|
|
360
|
+
order_id: 'order-delivery-ankara',
|
|
361
|
+
rider_id: 'rider-3',
|
|
362
|
+
rider_name: 'Rider Three',
|
|
363
|
+
status: 'COMPLETED',
|
|
364
|
+
createdAt: at(exports.CHARACTERIZATION_DAY, '10:22:00'),
|
|
365
|
+
delivered_at: at(exports.CHARACTERIZATION_DAY, '10:50:00'),
|
|
366
|
+
estimated_delivery_at: at(exports.CHARACTERIZATION_DAY, '11:00:00'),
|
|
367
|
+
}),
|
|
368
|
+
delivery({
|
|
369
|
+
_id: 'delivery-unknown',
|
|
370
|
+
order_id: 'order-delivery-unknown',
|
|
371
|
+
rider_id: 'rider-1',
|
|
372
|
+
rider_name: 'Rider One',
|
|
373
|
+
status: 'COMPLETED',
|
|
374
|
+
}),
|
|
375
|
+
// Orphan delivery: no staged order. Counts as an app RECORD in UNKNOWN.
|
|
376
|
+
delivery({
|
|
377
|
+
_id: 'delivery-orphan',
|
|
378
|
+
order_id: 'order-not-staged',
|
|
379
|
+
rider_id: 'rider-4',
|
|
380
|
+
rider_name: 'Rider Four',
|
|
381
|
+
status: 'COMPLETED',
|
|
382
|
+
delivered_at: at(exports.CHARACTERIZATION_DAY, '11:15:00'),
|
|
383
|
+
}),
|
|
384
|
+
];
|
|
385
|
+
// Prior-day credit bill collected on the characterization day. It is NOT a
|
|
386
|
+
// day sale; the Overview compile turns it into a receipt event.
|
|
387
|
+
const priorReceipt = order({
|
|
388
|
+
_id: 'order-prior-receipt',
|
|
389
|
+
order_number: 100,
|
|
390
|
+
localDate: exports.CHARACTERIZATION_PREV_DAY,
|
|
391
|
+
localHour: 18,
|
|
392
|
+
order_settled_at: at(exports.CHARACTERIZATION_DAY, '13:00:00'),
|
|
393
|
+
deferred_settlement: true,
|
|
394
|
+
amount_collected: 4000,
|
|
395
|
+
payments: [payLaterPayment(4000, 4000, constants_1.PAYMENT_STATUS_ENUM.SETTLED)],
|
|
396
|
+
});
|
|
397
|
+
return {
|
|
398
|
+
orders: [...dayOrders, priorReceipt],
|
|
399
|
+
deliveries,
|
|
400
|
+
dayOrders,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalises a value for a stable golden:
|
|
3
|
+
* - object keys are sorted recursively;
|
|
4
|
+
* - arrays keep their order (the reports define it; sorting would hide ordering
|
|
5
|
+
* regressions);
|
|
6
|
+
* - volatile envelope fields become stable placeholders;
|
|
7
|
+
* - every other number/string/boolean is preserved EXACTLY.
|
|
8
|
+
*
|
|
9
|
+
* `_id` values are replaced per unique value (`<id:1>`, `<id:2>`) so references
|
|
10
|
+
* between documents (for example an iteration row's `report_id`) stay
|
|
11
|
+
* comparable instead of collapsing to one placeholder.
|
|
12
|
+
*/
|
|
13
|
+
export declare function canonicalizeGolden(value: unknown): unknown;
|
|
14
|
+
export declare function goldenPath(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Compare (or update) one golden. Test-only; never imported by production code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function expectGolden(name: string, value: unknown): void;
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
exports.canonicalizeGolden = canonicalizeGolden;
|
|
7
|
+
exports.goldenPath = goldenPath;
|
|
8
|
+
exports.expectGolden = expectGolden;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/**
|
|
12
|
+
* PHASE 1 CHARACTERIZATION GOLDEN HELPER (test-only).
|
|
13
|
+
*
|
|
14
|
+
* The platform extraction must not change any number, document, page identity,
|
|
15
|
+
* cursor or error code. These goldens freeze what the code does TODAY, including
|
|
16
|
+
* known oddities. They are committed as JSON, never Jest snapshots, so an
|
|
17
|
+
* accidental update is a reviewable file diff.
|
|
18
|
+
*
|
|
19
|
+
* Regenerate explicitly:
|
|
20
|
+
* UPDATE_GOLDENS=1 npx jest --config jestconfig.json \
|
|
21
|
+
* src/tests/materialized-reports/characterization --runInBand
|
|
22
|
+
*
|
|
23
|
+
* Without UPDATE_GOLDENS the helper compares the canonical value with the
|
|
24
|
+
* committed JSON and fails on any difference.
|
|
25
|
+
*/
|
|
26
|
+
const GOLDENS_DIR = path_1.default.join(__dirname, 'goldens');
|
|
27
|
+
/** Envelope fields generated from the clock or from a fresh ObjectId. */
|
|
28
|
+
const VOLATILE_KEYS = new Set([
|
|
29
|
+
'_id',
|
|
30
|
+
'as_of',
|
|
31
|
+
'computed_at',
|
|
32
|
+
'createdAt',
|
|
33
|
+
'updatedAt',
|
|
34
|
+
'source_watermark',
|
|
35
|
+
'max_updated_at',
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Canonicalises a value for a stable golden:
|
|
39
|
+
* - object keys are sorted recursively;
|
|
40
|
+
* - arrays keep their order (the reports define it; sorting would hide ordering
|
|
41
|
+
* regressions);
|
|
42
|
+
* - volatile envelope fields become stable placeholders;
|
|
43
|
+
* - every other number/string/boolean is preserved EXACTLY.
|
|
44
|
+
*
|
|
45
|
+
* `_id` values are replaced per unique value (`<id:1>`, `<id:2>`) so references
|
|
46
|
+
* between documents (for example an iteration row's `report_id`) stay
|
|
47
|
+
* comparable instead of collapsing to one placeholder.
|
|
48
|
+
*/
|
|
49
|
+
function canonicalizeGolden(value) {
|
|
50
|
+
const idMap = new Map();
|
|
51
|
+
let nextId = 1;
|
|
52
|
+
const walk = (input, key) => {
|
|
53
|
+
if (input === undefined)
|
|
54
|
+
return '__undefined__';
|
|
55
|
+
if (input === null)
|
|
56
|
+
return null;
|
|
57
|
+
if (input instanceof Date) {
|
|
58
|
+
return key != null && VOLATILE_KEYS.has(key) ? '<date>' : input.toISOString();
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(input)) {
|
|
61
|
+
return input.map((entry) => walk(entry, null));
|
|
62
|
+
}
|
|
63
|
+
if (typeof input === 'object') {
|
|
64
|
+
const source = input;
|
|
65
|
+
// BSON ObjectId / Decimal128-like values serialise through toHexString or
|
|
66
|
+
// toString; normalise them before the generic object walk.
|
|
67
|
+
if (typeof source.toHexString === 'function') {
|
|
68
|
+
return walk(source.toHexString(), key);
|
|
69
|
+
}
|
|
70
|
+
if (typeof source.toString === 'function' &&
|
|
71
|
+
source._bsontype != null) {
|
|
72
|
+
return walk(String(source), key);
|
|
73
|
+
}
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const childKey of Object.keys(source).sort()) {
|
|
76
|
+
if (VOLATILE_KEYS.has(childKey)) {
|
|
77
|
+
const raw = source[childKey];
|
|
78
|
+
if (childKey === '_id' && raw != null) {
|
|
79
|
+
const identity = String(typeof raw.toHexString === 'function'
|
|
80
|
+
? raw.toHexString()
|
|
81
|
+
: raw);
|
|
82
|
+
if (!idMap.has(identity))
|
|
83
|
+
idMap.set(identity, `<id:${nextId}>`);
|
|
84
|
+
nextId += 1;
|
|
85
|
+
out[childKey] = idMap.get(identity);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
out[childKey] = '<volatile>';
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
out[childKey] = walk(source[childKey], childKey);
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
if (typeof input === 'number') {
|
|
97
|
+
if (Number.isNaN(input))
|
|
98
|
+
return '<NaN>';
|
|
99
|
+
if (!Number.isFinite(input))
|
|
100
|
+
return '<Infinity>';
|
|
101
|
+
return input;
|
|
102
|
+
}
|
|
103
|
+
return input;
|
|
104
|
+
};
|
|
105
|
+
return walk(value, null);
|
|
106
|
+
}
|
|
107
|
+
function goldenPath(name) {
|
|
108
|
+
return path_1.default.join(GOLDENS_DIR, `${name}.json`);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Compare (or update) one golden. Test-only; never imported by production code.
|
|
112
|
+
*/
|
|
113
|
+
function expectGolden(name, value) {
|
|
114
|
+
const canonical = canonicalizeGolden(value);
|
|
115
|
+
const file = goldenPath(name);
|
|
116
|
+
const serialized = JSON.stringify(canonical, null, 2) + '\n';
|
|
117
|
+
if (process.env.UPDATE_GOLDENS === '1') {
|
|
118
|
+
fs_1.default.mkdirSync(GOLDENS_DIR, { recursive: true });
|
|
119
|
+
fs_1.default.writeFileSync(file, serialized, 'utf8');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!fs_1.default.existsSync(file)) {
|
|
123
|
+
throw new Error(`Missing golden ${path_1.default.relative(process.cwd(), file)}. ` + 'Run with UPDATE_GOLDENS=1 and review the new file.');
|
|
124
|
+
}
|
|
125
|
+
const expected = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
|
|
126
|
+
expect(canonical).toEqual(expected);
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const materialized_reports_1 = require("../../../helpers/materialized-reports");
|
|
4
|
+
const MATERIALIZED_REPORTS_1 = require("../../../constants/MATERIALIZED_REPORTS");
|
|
5
|
+
const golden_1 = require("./golden");
|
|
6
|
+
const fixtures_1 = require("./fixtures");
|
|
7
|
+
/**
|
|
8
|
+
* OVERVIEW characterization — compile + formatter.
|
|
9
|
+
*
|
|
10
|
+
* Locks the current platform's document shape, credit receipt/issue candidates
|
|
11
|
+
* and the two formatter paths (raw day docs and the aggregated read record).
|
|
12
|
+
* It also captures the deliberate map-only counter shape (no `_counter_rows`).
|
|
13
|
+
*/
|
|
14
|
+
describe('characterization: Overview', () => {
|
|
15
|
+
const fixtures = (0, fixtures_1.buildCharacterizationFixtures)();
|
|
16
|
+
const compiled = (0, materialized_reports_1.convertOrdersToMaterializedTenantSalesOverviewReports)(fixtures_1.CHARACTERIZATION_DAY, fixtures.orders, {
|
|
17
|
+
tenantId: fixtures_1.CHARACTERIZATION_TENANT_ID,
|
|
18
|
+
brandId: fixtures_1.CHARACTERIZATION_BRAND_ID,
|
|
19
|
+
gmtOffset: 0,
|
|
20
|
+
computedAt: fixtures_1.CHARACTERIZATION_COMPUTED_AT,
|
|
21
|
+
});
|
|
22
|
+
it('compiles the day into the current document set', () => {
|
|
23
|
+
expect(compiled).not.toBeNull();
|
|
24
|
+
(0, golden_1.expectGolden)('overview.compile.day', compiled);
|
|
25
|
+
// Current shape, stated explicitly: Overview has NO counter rows.
|
|
26
|
+
const dayDoc = compiled.materializedReports.find((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && doc.scope_field === fixtures_1.CHARACTERIZATION_DAY);
|
|
27
|
+
expect(dayDoc).toBeDefined();
|
|
28
|
+
expect(dayDoc).not.toHaveProperty('sales_overview_counter_rows');
|
|
29
|
+
expect(dayDoc.sale_type_key_filters).toEqual(MATERIALIZED_REPORTS_1.SALES_OVERVIEW_KEY_FILTERS);
|
|
30
|
+
});
|
|
31
|
+
it('compiles an order-less closed day into zero-filled period documents', () => {
|
|
32
|
+
const empty = (0, materialized_reports_1.convertOrdersToMaterializedTenantSalesOverviewReports)(fixtures_1.CHARACTERIZATION_DAY, [], {
|
|
33
|
+
tenantId: fixtures_1.CHARACTERIZATION_TENANT_ID,
|
|
34
|
+
brandId: fixtures_1.CHARACTERIZATION_BRAND_ID,
|
|
35
|
+
gmtOffset: 0,
|
|
36
|
+
computedAt: fixtures_1.CHARACTERIZATION_COMPUTED_AT,
|
|
37
|
+
});
|
|
38
|
+
expect(empty).not.toBeNull();
|
|
39
|
+
(0, golden_1.expectGolden)('overview.compile.empty-day', empty);
|
|
40
|
+
expect(empty.materializedReports).toHaveLength(7);
|
|
41
|
+
expect(empty.materializedReports.every((doc) => doc.sale_type_metrics == null || Object.keys(doc.sale_type_metrics).length === 0)).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('formats the raw day documents', () => {
|
|
44
|
+
const dayDocs = compiled.materializedReports.filter((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && doc.scope_field === fixtures_1.CHARACTERIZATION_DAY);
|
|
45
|
+
(0, golden_1.expectGolden)('overview.formatted.raw-day', (0, materialized_reports_1.getFormattedTenantSalesOverviewReporting)(dayDocs));
|
|
46
|
+
(0, golden_1.expectGolden)('overview.formatted.raw-day-filtered', (0, materialized_reports_1.getFormattedTenantSalesOverviewReporting)(dayDocs, {
|
|
47
|
+
platforms: ['POS_DINE-IN', 'POS_DELIVERY'],
|
|
48
|
+
order_statuses: ['COMPLETED'],
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
it('formats the aggregated read record and refuses a weekday filter', () => {
|
|
52
|
+
const dayDoc = compiled.materializedReports.find((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && doc.scope_field === fixtures_1.CHARACTERIZATION_DAY);
|
|
53
|
+
const aggregated = {
|
|
54
|
+
tenant_id: dayDoc.tenant_id,
|
|
55
|
+
brand_id: dayDoc.brand_id,
|
|
56
|
+
max_iteration: dayDoc.iteration ?? 1,
|
|
57
|
+
max_updated_at: dayDoc.updatedAt ?? null,
|
|
58
|
+
matched_documents: 1,
|
|
59
|
+
first_scope_field: dayDoc.scope_field,
|
|
60
|
+
last_scope_field: dayDoc.scope_field,
|
|
61
|
+
sale_type_key_filters: dayDoc.sale_type_key_filters,
|
|
62
|
+
sale_type_metrics: dayDoc.sale_type_metrics,
|
|
63
|
+
};
|
|
64
|
+
(0, golden_1.expectGolden)('overview.formatted.aggregated', (0, materialized_reports_1.getFormattedTenantSalesOverviewAggregatedReporting)([aggregated]));
|
|
65
|
+
expect((0, materialized_reports_1.getFormattedTenantSalesOverviewAggregatedReporting)([aggregated], {
|
|
66
|
+
day_indexes: ['MONDAY'],
|
|
67
|
+
})).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|