87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import type { Filing } from '@/lib/types';
|
|
import { __recentDevelopmentsInternals, getRecentDevelopments, secFilingsDevelopmentSource } from './recent-developments';
|
|
|
|
function filing(input: Partial<Filing> & Pick<Filing, 'accession_number' | 'filing_type' | 'filing_date' | 'ticker' | 'cik' | 'company_name'>): Filing {
|
|
return {
|
|
id: 1,
|
|
filing_url: 'https://www.sec.gov/Archives/example.htm',
|
|
submission_url: null,
|
|
primary_document: 'example.htm',
|
|
metrics: null,
|
|
analysis: null,
|
|
created_at: '2026-03-01T00:00:00.000Z',
|
|
updated_at: '2026-03-01T00:00:00.000Z',
|
|
...input
|
|
};
|
|
}
|
|
|
|
describe('recent developments', () => {
|
|
it('prioritizes 8-K items ahead of periodic filings', async () => {
|
|
const items = await secFilingsDevelopmentSource.fetch('MSFT', {
|
|
now: new Date('2026-03-12T12:00:00.000Z'),
|
|
filings: [
|
|
filing({
|
|
accession_number: '0001',
|
|
filing_type: '10-Q',
|
|
filing_date: '2026-03-09',
|
|
ticker: 'MSFT',
|
|
cik: '0000789019',
|
|
company_name: 'Microsoft Corp'
|
|
}),
|
|
filing({
|
|
accession_number: '0002',
|
|
filing_type: '8-K',
|
|
filing_date: '2026-03-10',
|
|
ticker: 'MSFT',
|
|
cik: '0000789019',
|
|
company_name: 'Microsoft Corp'
|
|
})
|
|
]
|
|
});
|
|
|
|
expect(items[0]?.kind).toBe('8-K');
|
|
expect(items[0]?.title).toContain('8-K');
|
|
});
|
|
|
|
it('builds a ready recent developments payload from filing records', async () => {
|
|
const developments = await getRecentDevelopments('MSFT', {
|
|
now: new Date('2026-03-12T12:00:00.000Z'),
|
|
filings: [
|
|
filing({
|
|
accession_number: '0002',
|
|
filing_type: '8-K',
|
|
filing_date: '2026-03-10',
|
|
ticker: 'MSFT',
|
|
cik: '0000789019',
|
|
company_name: 'Microsoft Corp',
|
|
analysis: {
|
|
text: 'The company announced a new enterprise AI contract.',
|
|
provider: 'zhipu',
|
|
model: 'glm-5'
|
|
}
|
|
})
|
|
]
|
|
});
|
|
|
|
expect(developments.status).toBe('ready');
|
|
expect(developments.items).toHaveLength(1);
|
|
expect(developments.items[0]?.summary).toContain('enterprise AI contract');
|
|
});
|
|
|
|
it('creates heuristic summaries when filing analysis is unavailable', () => {
|
|
const summary = __recentDevelopmentsInternals.buildSummary(
|
|
filing({
|
|
accession_number: '0003',
|
|
filing_type: '10-K',
|
|
filing_date: '2026-03-02',
|
|
ticker: 'MSFT',
|
|
cik: '0000789019',
|
|
company_name: 'Microsoft Corp'
|
|
})
|
|
);
|
|
|
|
expect(summary).toContain('10-K');
|
|
});
|
|
});
|