test: await portfolio publication done instead of polling ticks (WealthLedger/backend#63)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { setImmediate as immediate } from 'node:timers/promises';
|
||||
import assert from 'node:assert/strict';
|
||||
jest.mock('../../../../prisma/prisma.service', () => ({
|
||||
PrismaService: class {},
|
||||
}));
|
||||
@@ -97,14 +97,9 @@ describe('persistent portfolio projection', () => {
|
||||
],
|
||||
work: [],
|
||||
});
|
||||
await service.request('user', 'private', 'a');
|
||||
for (
|
||||
let index = 0;
|
||||
index < 10 && !repository.publish.mock.calls.length;
|
||||
index += 1
|
||||
) {
|
||||
await immediate();
|
||||
}
|
||||
const handle = await service.request('user', 'private', 'a');
|
||||
assert(handle);
|
||||
await handle.done;
|
||||
const snapshot = (
|
||||
repository.publish.mock.calls as [unknown, string, PortfolioDto][]
|
||||
)[0][2];
|
||||
@@ -147,10 +142,9 @@ describe('persistent portfolio projection', () => {
|
||||
{ units: '99' },
|
||||
{ currency: 'EUR', units: '1' },
|
||||
] });
|
||||
await service.request('user', 'private', 'a');
|
||||
for (let index = 0; index < 10 && !repository.publish.mock.calls.length; index++) {
|
||||
await immediate();
|
||||
}
|
||||
const handle = await service.request('user', 'private', 'a');
|
||||
assert(handle);
|
||||
await handle.done;
|
||||
const snapshot = (repository.publish.mock.calls as [unknown, string, PortfolioDto][])[0][2];
|
||||
expect(snapshot.cashBalances).toEqual([
|
||||
{ currency: 'RUB', value: '0' },
|
||||
|
||||
Reference in New Issue
Block a user