Files
Neon-Desk/lib/server/taxonomy/metrics.test.ts

59 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'bun:test';
import type { TaxonomyFact } from '@/lib/server/taxonomy/types';
import { deriveTaxonomyMetrics } from '@/lib/server/taxonomy/metrics';
function fact(localName: string, value: number, overrides?: Partial<TaxonomyFact>): TaxonomyFact {
return {
conceptKey: `http://fasb.org/us-gaap/2024#${localName}`,
qname: `us-gaap:${localName}`,
namespaceUri: 'http://fasb.org/us-gaap/2024',
localName,
dataType: null,
contextId: 'c1',
unit: 'iso4217:USD',
decimals: '-6',
precision: null,
nil: false,
value,
periodStart: '2025-01-01',
periodEnd: '2025-12-31',
periodInstant: null,
dimensions: [],
isDimensionless: true,
sourceFile: 'abc_htm.xml',
...overrides
};
}
describe('taxonomy metric derivation', () => {
it('applies concept priority for canonical metrics and debt component fallback', () => {
const metrics = deriveTaxonomyMetrics([
fact('SalesRevenueNet', 500),
fact('Revenues', 450),
fact('NetIncomeLoss', 40),
fact('Assets', 1000),
fact('CashAndCashEquivalentsAtCarryingValue', 80),
fact('DebtCurrent', 15),
fact('LongTermDebtNoncurrent', 35)
]);
expect(metrics).toEqual({
revenue: 450,
netIncome: 40,
totalAssets: 1000,
cash: 80,
debt: 50
});
});
it('uses direct debt concept before computed debt fallback when available', () => {
const metrics = deriveTaxonomyMetrics([
fact('DebtCurrent', 15),
fact('LongTermDebtNoncurrent', 35),
fact('LongTermDebtAndCapitalLeaseObligations', 90)
]);
expect(metrics.debt).toBe(90);
});
});