fix(investments): align roles and date contracts
Backend security / security (push) Successful in 9s
Backend verify / verify (push) Successful in 10m23s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Successful in 10m39s
Conventional commits / commits (pull_request) Successful in 29s

Identify income dependencies by role and document screen-specific dates.
Convert inclusive calendar days into half-open source ranges while
preserving operation timestamps and existing stored coverage.
This commit is contained in:
2026-09-27 11:38:13 +03:00
parent e4232138d0
commit 516e43203e
18 changed files with 500 additions and 74 deletions
+16 -1
View File
@@ -46,11 +46,26 @@ describe('TbankClient operations', () => {
seconds: String(Math.floor(Date.parse('2026-08-19T00:00:00Z') / 1000)),
},
to: {
seconds: String(Math.floor(Date.parse('2026-09-18T00:00:00Z') / 1000)),
seconds: String(Math.floor(Date.parse('2026-09-19T00:00:00Z') / 1000)),
},
});
});
it.each(['getDividends', 'getBondCoupons'] as const)(
'%s converts a leap-day calendar window to a full half-open UTC day',
async (method) => {
const client = Object.create(TbankClient.prototype) as TbankClient;
const call = jest.fn().mockResolvedValue({});
(client as unknown as { call: jest.Mock }).call = call;
await client[method]('token', 'uid', '2024-02-29', '2024-02-29');
expect(call).toHaveBeenCalledWith('token', undefined, method, {
instrumentId: 'uid',
from: { seconds: String(Date.parse('2024-02-29T00:00:00Z') / 1000) },
to: { seconds: String(Date.parse('2024-03-01T00:00:00Z') / 1000) },
});
},
);
it('propagates the normalized upstream error', async () => {
const client = Object.create(TbankClient.prototype) as TbankClient;
const error = new ServiceUnavailableException({
+7 -4
View File
@@ -292,7 +292,7 @@ export class TbankClient {
{
instrumentId,
from: { seconds: String(utcSeconds(from)) },
to: { seconds: String(utcSeconds(to)) },
to: { seconds: String(utcSeconds(to, true)) },
},
).then((response) => response.dividends ?? []);
}
@@ -344,7 +344,7 @@ export class TbankClient {
{
instrumentId: uid,
from: { seconds: String(utcSeconds(from)) },
to: { seconds: String(utcSeconds(to)) },
to: { seconds: String(utcSeconds(to, true)) },
},
).then((response) => response.events ?? []);
}
@@ -552,6 +552,9 @@ export class TbankClient {
}
}
function utcSeconds(date: string): number {
return Math.floor(Date.parse(`${date}T00:00:00Z`) / MILLISECONDS_PER_SECOND);
// Calendar owners supply inclusive UTC days; RPC timestamps use [from, next(to)).
function utcSeconds(date: string, nextDay = false): number {
const instant = new Date(`${date}T00:00:00Z`);
if (nextDay) instant.setUTCDate(instant.getUTCDate() + 1);
return Math.floor(instant.valueOf() / MILLISECONDS_PER_SECOND);
}