fix(sync): start hourly operations after portfolio works finish (#201)
Backend verify / commits (pull_request) Successful in 1m42s
Backend verify / security (pull_request) Successful in 1m17s
Backend verify / verify (pull_request) Successful in 6m36s

This commit is contained in:
2026-11-11 09:14:34 +03:00
parent fee61537b6
commit 586e9fdd39
2 changed files with 31 additions and 1 deletions
+23
View File
@@ -167,6 +167,29 @@ describe('hourly attempt lifecycle (SQLite)', () => {
expect(read?.state).toBe('succeeded');
});
it('starts operations only after every portfolio work finished', async () => {
const portfolios: string[] = [];
portfolio.request.mockImplementation(
async (_userId: string, _revision: string, accountId: string) => {
const row = await child('running', null, `portfolio:${accountId}`);
portfolios.push(row.id);
return { id: row.id, done: Promise.resolve() };
},
);
const scheduler = createScheduler();
await scheduler.tick();
await pump();
expect(portfolios).toHaveLength(2);
expect(operations.request).not.toHaveBeenCalled();
await prisma.tbankSyncWork.updateMany({
where: { id: { in: portfolios } },
data: { state: 'complete' },
});
const row = await runWalk(scheduler);
expect(operations.request).toHaveBeenCalledTimes(2);
expect(row.state).toBe('complete');
});
it('settles partial and keeps successful steps when one account fails', async () => {
portfolio.request.mockImplementation(
async (_userId: string, _revision: string, accountId: string) => {