From b7cf097abdec3db7276181a6293cfa5b6c58bc23 Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Thu, 15 Oct 2026 15:09:21 +0300 Subject: [PATCH] test: await portfolio publication done instead of polling ticks (WealthLedger/backend#63) --- .../application/portfolio.service.spec.ts | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/modules/investments/portfolio/application/portfolio.service.spec.ts b/src/modules/investments/portfolio/application/portfolio.service.spec.ts index 2b12f43..008c160 100644 --- a/src/modules/investments/portfolio/application/portfolio.service.spec.ts +++ b/src/modules/investments/portfolio/application/portfolio.service.spec.ts @@ -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' }, -- 2.54.0