import { describe, expect, it } from 'bun:test'; import { __secCompanyProfileInternals, deriveValuationSnapshot } from './sec-company-profile'; describe('sec company profile helpers', () => { it('formats fiscal year end values', () => { expect(__secCompanyProfileInternals.formatFiscalYearEnd('0630')).toBe('06/30'); expect(__secCompanyProfileInternals.formatFiscalYearEnd('1231')).toBe('12/31'); expect(__secCompanyProfileInternals.formatFiscalYearEnd('')).toBeNull(); }); it('picks the latest numeric fact across supported namespaces', () => { const payload = { facts: { dei: { EntityCommonStockSharesOutstanding: { units: { shares: [ { val: 7_400_000_000, filed: '2025-10-31' }, { val: 7_500_000_000, filed: '2026-01-31' } ] } } } } }; expect( __secCompanyProfileInternals.pickLatestNumericFact( payload, ['dei'], ['EntityCommonStockSharesOutstanding'] ) ).toBe(7_500_000_000); }); it('derives valuation metrics from free inputs only', () => { const snapshot = deriveValuationSnapshot({ quote: 200, sharesOutstanding: 1_000_000, revenue: 50_000_000, cash: 5_000_000, debt: 15_000_000, netIncome: 10_000_000 }); expect(snapshot.marketCap).toBe(200_000_000); expect(snapshot.enterpriseValue).toBe(210_000_000); expect(snapshot.evToRevenue).toBe(4.2); expect(snapshot.trailingPe).toBe(20); expect(snapshot.source).toBe('derived'); }); it('marks valuation as unavailable when core inputs are missing', () => { const snapshot = deriveValuationSnapshot({ quote: null, sharesOutstanding: null, revenue: null, cash: null, debt: null, netIncome: null }); expect(snapshot.marketCap).toBeNull(); expect(snapshot.enterpriseValue).toBeNull(); expect(snapshot.source).toBe('unavailable'); }); });