Files
TREK/server/tests/helpers/one-by-one.ts
T
Maurice 4d81180fc1 test(tours): bring the server tests in line with the tours board
Expectations follow createAssignment's options, the stage_ends column, the editor's trip access and the broadcasts of the take-over. Refusals in the run and ski e2e tests go one by one so supertest does not reset a connection under another request. A parity test keeps the source hint enums in step with the contract.
2026-10-20 17:51:27 +02:00

17 lines
751 B
TypeScript

/**
* Sends requests one after another and answers their results in order.
*
* Supertest given an app's HTTP server that is not listening opens it on a
* port of its own for every request and closes it again once that request is
* answered. Several requests sent together against the same server race: a
* refusal answered at once closes it under another one still in flight, which
* then fails with ECONNRESET instead of its status. Sent one by one, each
* request has the server to itself.
*/
export async function oneByOne<T, R>(items: readonly T[], send: (item: T) => PromiseLike<R>): Promise<R[]> {
return await items.reduce<Promise<R[]>>(
async (sent, item) => [...(await sent), await send(item)],
Promise.resolve([]),
);
}