test: await portfolio publication done instead of polling ticks (WealthLedger/backend#63) #103
@@ -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' },
|
||||||
|
|||||||
Reference in New Issue
Block a user