71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { previousClose } from '../../application/instrument-market';
|
|
import { metrics } from './get-stock-company.use-case';
|
|
import { stockDividends } from './stock-income.service';
|
|
import { stockQuote } from './stock-market.service';
|
|
jest.mock('../../../../../prisma/prisma.service', () => ({
|
|
PrismaService: class {},
|
|
}));
|
|
const time = (value: string) => ({ seconds: String(Date.parse(value) / 1000) });
|
|
describe('stock financial projections', () => {
|
|
it('keeps raw public payouts when holdings are unavailable and omits cancelled events', () => {
|
|
const result = stockDividends(
|
|
[
|
|
{
|
|
dividendNet: { currency: 'rub', units: '32', nano: 880000000 },
|
|
recordDate: time('2026-10-13'),
|
|
paymentDate: time('2026-10-27'),
|
|
},
|
|
{ dividendType: 'Cancelled', recordDate: time('2026-10-14') },
|
|
],
|
|
null,
|
|
{ from: '2021-09-10', to: '2027-09-10', today: '2026-09-10' },
|
|
'source-time',
|
|
true,
|
|
);
|
|
expect(result.dividends).toEqual([
|
|
{
|
|
perShare: { currency: 'RUB', value: '32.88' },
|
|
recordDate: '2026-10-13',
|
|
paymentDate: '2026-10-27',
|
|
lastBuyDate: null,
|
|
timing: 'upcoming',
|
|
estimatedAmount: null,
|
|
},
|
|
]);
|
|
expect(result.estimateUnavailable).toBe(true);
|
|
expect(result.observedAt).toBe('source-time');
|
|
});
|
|
it('uses the last complete previous trading day', () => {
|
|
const candles = [
|
|
{ time: time('2026-09-09'), close: { units: '10' }, isComplete: true },
|
|
{ time: time('2026-09-10'), close: { units: '11' }, isComplete: false },
|
|
];
|
|
expect(previousClose(candles, '2026-09-10T18:00:00Z')).toEqual(candles[0]);
|
|
});
|
|
it('retains stock price precision and percent change without inventing unavailable fundamentals', () => {
|
|
expect(
|
|
stockQuote(
|
|
{
|
|
instrument: { currency: 'rub' },
|
|
price: { price: { units: '11', nano: 1 } },
|
|
candle: { close: { units: '10' } },
|
|
},
|
|
[],
|
|
'time',
|
|
),
|
|
).toMatchObject({
|
|
price: { currency: 'RUB', value: '11.000000001' },
|
|
change: { currency: 'RUB', value: '1.000000001' },
|
|
changePercent: '10',
|
|
});
|
|
expect(metrics(null, 'financial')).toEqual([]);
|
|
expect(
|
|
metrics(
|
|
{ peRatioTtm: 6, netIncomeTtm: 10, revenueTtm: 100, currency: 'rub' },
|
|
'financial',
|
|
).map((item) => item.key),
|
|
).toEqual(['peRatioTtm', 'netIncomeTtm']);
|
|
expect(metrics({ netIncomeTtm: 10 })).toEqual([]);
|
|
});
|
|
});
|