55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { decimalFromString } from '../../../common/decimal';
|
|
import { bondEvent, dividendEvent } from './upcoming-event.mapper';
|
|
jest.mock('../../../prisma/prisma.service', () => ({
|
|
PrismaService: class {},
|
|
}));
|
|
const metadata = {
|
|
figi: 'figi',
|
|
instrumentUid: 'uid',
|
|
ticker: 'TEST',
|
|
displayName: 'Synthetic',
|
|
isin: null,
|
|
logoName: null,
|
|
};
|
|
describe('forecast financial projections', () => {
|
|
it('preserves registry dates, source currency and exact signed fractional quantities', () => {
|
|
expect(
|
|
dividendEvent(metadata, decimalFromString('-2.5'), {
|
|
recordDate: { seconds: String(Date.parse('2026-10-13Z') / 1000) },
|
|
dividendNet: { currency: 'usd', units: '10', nano: 1 },
|
|
}),
|
|
).toMatchObject({
|
|
date: '2026-10-13',
|
|
dateKind: 'registry',
|
|
projectedAmount: { currency: 'USD', value: '-25.0000000025' },
|
|
});
|
|
});
|
|
it('does not invent an amount for offers or missing currency', () => {
|
|
expect(
|
|
bondEvent(metadata, decimalFromString('3'), {
|
|
type: 'offer',
|
|
date: '2026-10-01',
|
|
}).projectedAmount,
|
|
).toBeNull();
|
|
expect(
|
|
dividendEvent(metadata, decimalFromString('3'), {
|
|
recordDate: { seconds: '1790812800' },
|
|
dividendNet: { units: '10' },
|
|
}).projectedAmount,
|
|
).toBeNull();
|
|
});
|
|
it('preserves redemption as a non-income event with its exact amount', () => {
|
|
expect(
|
|
bondEvent(metadata, decimalFromString('2.5'), {
|
|
type: 'maturity',
|
|
date: '2026-10-01',
|
|
currency: 'rub',
|
|
value: '500.000000001',
|
|
}),
|
|
).toMatchObject({
|
|
type: 'maturity',
|
|
projectedAmount: { currency: 'RUB', value: '1250.0000000025' },
|
|
});
|
|
});
|
|
});
|