76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { normalizeScreen } from './tbank-screen';
|
|
|
|
describe('manual sync screen boundary', () => {
|
|
it('normalizes equivalent descriptors to the same scope', () => {
|
|
expect(normalizeScreen({ screen: 'stocks', query: ' sber ' })).toEqual({
|
|
screen: 'stocks',
|
|
query: 'SBER',
|
|
});
|
|
expect(
|
|
JSON.stringify(
|
|
normalizeScreen({
|
|
screen: 'operations',
|
|
accountId: 'a',
|
|
categories: ['tax', 'income', 'tax'],
|
|
limit: 20,
|
|
}),
|
|
),
|
|
).toBe(
|
|
JSON.stringify(
|
|
normalizeScreen({
|
|
limit: 20,
|
|
categories: ['income', 'tax'],
|
|
accountId: 'a',
|
|
screen: 'operations',
|
|
}),
|
|
),
|
|
);
|
|
});
|
|
it('rejects missing identities and fields that would expand another screen', () => {
|
|
for (const scope of [
|
|
{ screen: 'accounts', accountId: 'a' },
|
|
{ screen: 'account' },
|
|
{ screen: 'stock' },
|
|
{ screen: 'stocks', query: ' ' },
|
|
{ screen: 'events', accountId: 'a', instrumentUid: 'uid' },
|
|
{ screen: 'income', accountId: 'a', from: '2026-01-01' },
|
|
{
|
|
screen: 'events',
|
|
accountId: 'a',
|
|
from: '2026-02-01',
|
|
to: '2026-01-01',
|
|
},
|
|
] as Parameters<typeof normalizeScreen>[0][]) {
|
|
expect(() => normalizeScreen(scope)).toThrow();
|
|
}
|
|
});
|
|
it('retains inclusive calendar days, rejecting instant values for date-only owners', () => {
|
|
const scope = {
|
|
screen: 'events' as const,
|
|
accountId: 'all',
|
|
from: '2026-01-01',
|
|
to: '2026-01-01',
|
|
};
|
|
expect(normalizeScreen(scope)).toEqual(scope);
|
|
expect(() =>
|
|
normalizeScreen({ ...scope, from: '2026-01-01T00:00:00Z' }),
|
|
).toThrow();
|
|
expect(() =>
|
|
normalizeScreen({
|
|
screen: 'stock',
|
|
instrumentUid: 'uid',
|
|
candleRange: { from: '2026-01-02', to: '2026-01-01' },
|
|
}),
|
|
).toThrow();
|
|
});
|
|
it('keeps independently supplied event dates and rejects an end before the default UTC start', () => {
|
|
for (const range of [{ from: '2096-02-29' }, { to: '2096-02-29' }]) {
|
|
const scope = { screen: 'events' as const, accountId: 'all', ...range };
|
|
expect(normalizeScreen(scope)).toEqual(scope);
|
|
}
|
|
expect(() =>
|
|
normalizeScreen({ screen: 'events', accountId: 'all', to: '2000-01-01' }),
|
|
).toThrow();
|
|
});
|
|
});
|