diff --git a/server/tests/unit/nest/ski-routing/ski-router-runner.test.ts b/server/tests/unit/nest/ski-routing/ski-router-runner.test.ts index a2d8f1333..197556c80 100644 --- a/server/tests/unit/nest/ski-routing/ski-router-runner.test.ts +++ b/server/tests/unit/nest/ski-routing/ski-router-runner.test.ts @@ -21,6 +21,7 @@ import { WorkerSkiRouterRunner, } from '../../../../src/nest/ski-routing/worker-router-runner'; import { decodePolyline } from '../../../../src/utils/polyline'; +import { oneByOne } from '../../../helpers/one-by-one'; import { SkiWorld } from '../../../helpers/ski-world'; import { skiRouteRequestSchema } from '@trek/shared'; @@ -222,7 +223,9 @@ describe('WorkerSkiRouterRunner', () => { ); await expect(runner.run(job(['hang']))).rejects.toThrow('busy'); // One job at a time is with the thread, each on its own clock. - for (let i = 0; i < MAX_WAITING_JOBS; i++) await vi.advanceTimersByTimeAsync(answerTimeoutMs(job(['hang']))); + await oneByOne(Array.from({ length: MAX_WAITING_JOBS }), () => + vi.advanceTimersByTimeAsync(answerTimeoutMs(job(['hang']))), + ); expect(await Promise.all(waiting)).toEqual(Array.from({ length: MAX_WAITING_JOBS }, () => 'timeout')); await runner.close(); } finally { diff --git a/server/tests/unit/nest/tours.mcp.test.ts b/server/tests/unit/nest/tours.mcp.test.ts index 1f71bac83..18daeef7d 100644 --- a/server/tests/unit/nest/tours.mcp.test.ts +++ b/server/tests/unit/nest/tours.mcp.test.ts @@ -30,6 +30,7 @@ import { makeDayAssignment } from '../../helpers/factories/itinerary'; import { makePlace } from '../../helpers/factories/places'; import { countRows, findRow, insertRows, updateRows } from '../../helpers/factories/rows'; import { addTourWaypoints, makeTour, markStationVisit } from '../../helpers/factories/tours'; +import { oneByOne } from '../../helpers/one-by-one'; import { resetTestDb } from '../../helpers/test-db'; import { createTestModule, type TestModule } from '../../helpers/test-module'; import { createTestOrm } from '../../helpers/test-orm'; @@ -766,12 +767,12 @@ describe('ToursMcp', () => { ski_discipline: 'alpine', ski_options: JSON.stringify({ options, build: '2026-11-02' }), }); - for (const place of [timed, untimed]) { - await addTourWaypoints(orm, place.id, [ + await oneByOne([timed, untimed], (place) => + addTourWaypoints(orm, place.id, [ { lat: 46, lng: 7, station_key: `${place.id}-a` }, { lat: 46.01, lng: 7, station_key: `${place.id}-b` }, - ]); - } + ]), + ); await orm.close(); const plan = read(await mcp.getTourPlan({ tripId: trip.id, placeId: partly.id }, ctx(member.id))); expect(plan.legs.map((leg: { kind: string }) => leg.kind)).toEqual(['free', 'routed']); diff --git a/server/tests/unit/nest/trek-places.client.test.ts b/server/tests/unit/nest/trek-places.client.test.ts index d1d6cc815..61ba695f9 100644 --- a/server/tests/unit/nest/trek-places.client.test.ts +++ b/server/tests/unit/nest/trek-places.client.test.ts @@ -23,6 +23,7 @@ import { serviceLang, type TrekPlace, } from '../../../src/nest/maps/trek-places.client'; +import { oneByOne } from '../../helpers/one-by-one'; import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; @@ -1089,9 +1090,9 @@ describe('the layers breaker', () => { it('TREK-PLACES-BREAKER-01: busy layer answers never stop place search', async () => { stubFetch({ detail: 'busy' }, 503); - for (let i = 0; i < 4; i++) { - await expect(trekPlacesRoutes(VIEW, 'horse', CAPS)).rejects.toThrow(/503/); - } + await oneByOne(Array.from({ length: 4 }), () => + expect(trekPlacesRoutes(VIEW, 'horse', CAPS)).rejects.toThrow(/503/), + ); stubFetch({ query: 'x', results: [PLACE] }); await expect(trekPlacesSearch('x')).resolves.toHaveLength(1); expect(calls).toHaveLength(1); @@ -1099,7 +1100,7 @@ describe('the layers breaker', () => { it('TREK-PLACES-BREAKER-02: the layers stop dialling on their own after a few failures', async () => { stubFetch({ detail: 'busy' }, 503); - for (let i = 0; i < 4; i++) await expect(trekPlacesWays([1])).rejects.toThrow(/503/); + await oneByOne(Array.from({ length: 4 }), () => expect(trekPlacesWays([1])).rejects.toThrow(/503/)); const dialled = calls.length; await expect(trekPlacesRoutes(VIEW, 'horse', CAPS)).rejects.toThrow('unreachable, not retrying yet'); await expect(trekPlacesWays([1])).rejects.toThrow('unreachable, not retrying yet'); @@ -1108,7 +1109,7 @@ describe('the layers breaker', () => { it('TREK-PLACES-BREAKER-03: a layer not built yet does not clear the count of search failures', async () => { stubFetch({}, 503); - for (let i = 0; i < 3; i++) await expect(trekPlacesSearch('x')).rejects.toThrow(/503/); + await oneByOne(Array.from({ length: 3 }), () => expect(trekPlacesSearch('x')).rejects.toThrow(/503/)); stubFetch({ detail: 'not built' }, 404); await expect(trekPlacesWays([1])).rejects.toThrow(/404/); stubFetch({}, 503);