test: await portfolio publication done instead of polling ticks (WealthLedger/backend#63)
Backend verify / commits (pull_request) Successful in 35s
Backend verify / security (pull_request) Successful in 13s
Backend verify / verify (pull_request) Successful in 5m41s

This commit is contained in:
2026-10-15 15:09:21 +03:00
parent ec6d9a2639
commit b7cf097abd
@@ -1,4 +1,4 @@
import { setImmediate as immediate } from 'node:timers/promises'; import assert from 'node:assert/strict';
jest.mock('../../../../prisma/prisma.service', () => ({ jest.mock('../../../../prisma/prisma.service', () => ({
PrismaService: class {}, PrismaService: class {},
})); }));
@@ -97,14 +97,9 @@ describe('persistent portfolio projection', () => {
], ],
work: [], work: [],
}); });
await service.request('user', 'private', 'a'); const handle = await service.request('user', 'private', 'a');
for ( assert(handle);
let index = 0; await handle.done;
index < 10 && !repository.publish.mock.calls.length;
index += 1
) {
await immediate();
}
const snapshot = ( const snapshot = (
repository.publish.mock.calls as [unknown, string, PortfolioDto][] repository.publish.mock.calls as [unknown, string, PortfolioDto][]
)[0][2]; )[0][2];
@@ -147,10 +142,9 @@ describe('persistent portfolio projection', () => {
{ units: '99' }, { units: '99' },
{ currency: 'EUR', units: '1' }, { currency: 'EUR', units: '1' },
] }); ] });
await service.request('user', 'private', 'a'); const handle = await service.request('user', 'private', 'a');
for (let index = 0; index < 10 && !repository.publish.mock.calls.length; index++) { assert(handle);
await immediate(); await handle.done;
}
const snapshot = (repository.publish.mock.calls as [unknown, string, PortfolioDto][])[0][2]; const snapshot = (repository.publish.mock.calls as [unknown, string, PortfolioDto][])[0][2];
expect(snapshot.cashBalances).toEqual([ expect(snapshot.cashBalances).toEqual([
{ currency: 'RUB', value: '0' }, { currency: 'RUB', value: '0' },