Expand financials surfaces with ratios, KPIs, and cadence support
- Add bundled financial modeling pipeline (ratios, KPI dimensions/notes, trend series, standardization) - Introduce company financial bundles storage (Drizzle migration + repo wiring) - Refactor financials page/API/query flow to use surfaceKind + cadence and new response shapes
This commit is contained in:
65
lib/server/financials/kpi-dimensions.test.ts
Normal file
65
lib/server/financials/kpi-dimensions.test.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import type {
|
||||
FinancialStatementPeriod,
|
||||
TaxonomyFactRow
|
||||
} from '@/lib/types';
|
||||
import { extractStructuredKpisFromDimensions } from './kpi-dimensions';
|
||||
|
||||
const PERIOD: FinancialStatementPeriod = {
|
||||
id: '2025-q4',
|
||||
filingId: 1,
|
||||
accessionNumber: '0000-1',
|
||||
filingDate: '2026-01-31',
|
||||
periodStart: '2025-10-01',
|
||||
periodEnd: '2025-12-31',
|
||||
filingType: '10-Q',
|
||||
periodLabel: 'Q4 2025'
|
||||
};
|
||||
|
||||
const FACT: TaxonomyFactRow = {
|
||||
id: 10,
|
||||
snapshotId: 5,
|
||||
filingId: 1,
|
||||
filingDate: '2026-01-31',
|
||||
statement: 'income',
|
||||
roleUri: 'income',
|
||||
conceptKey: 'us-gaap:Revenues',
|
||||
qname: 'us-gaap:Revenues',
|
||||
namespaceUri: 'http://fasb.org/us-gaap/2024',
|
||||
localName: 'Revenues',
|
||||
value: 50000,
|
||||
contextId: 'ctx-1',
|
||||
unit: 'iso4217:USD',
|
||||
decimals: null,
|
||||
periodStart: '2025-10-01',
|
||||
periodEnd: '2025-12-31',
|
||||
periodInstant: null,
|
||||
dimensions: [{
|
||||
axis: 'srt:ProductOrServiceAxis',
|
||||
member: 'msft:CloudMember'
|
||||
}],
|
||||
isDimensionless: false,
|
||||
sourceFile: null
|
||||
};
|
||||
|
||||
describe('dimension KPI extraction', () => {
|
||||
it('builds stable taxonomy KPI keys and provenance', () => {
|
||||
const rows = extractStructuredKpisFromDimensions({
|
||||
facts: [FACT],
|
||||
periods: [PERIOD],
|
||||
definitions: [{
|
||||
key: 'segment_revenue',
|
||||
label: 'Segment Revenue',
|
||||
category: 'segment_revenue',
|
||||
unit: 'currency',
|
||||
preferredConceptNames: ['Revenues']
|
||||
}]
|
||||
});
|
||||
|
||||
expect(rows).toHaveLength(1);
|
||||
expect(rows[0]?.key).toBe('segment_revenue__srt_productorserviceaxis__msft_cloudmember');
|
||||
expect(rows[0]?.provenanceType).toBe('taxonomy');
|
||||
expect(rows[0]?.values['2025-q4']).toBe(50000);
|
||||
expect(rows[0]?.sourceFactIds).toEqual([10]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user