From 28a4360ef3a733d4380f306140d893a1c40f80f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 27 Nov 2024 19:13:47 +0100 Subject: [PATCH] feat(http-server): support delay range --- packages/http-server/src/server.ts | 11 ++++++++++- packages/http/src/types.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/http-server/src/server.ts b/packages/http-server/src/server.ts index d6df34c66..981f2ef83 100644 --- a/packages/http-server/src/server.ts +++ b/packages/http-server/src/server.ts @@ -112,7 +112,16 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe const delay: E.Either> = pipe( requestConfig, - E.map(config => (config.mock.delay ? O.some(config.mock.delay) : O.none)) + E.map(config => + pipe( + O.fromNullable(config.mock.delay), + O.chain(delay => + Array.isArray(delay) + ? O.some(Math.floor(Math.random() * (delay[1] - delay[0] + 1) + delay[0])) + : O.some(delay) + ) + ) + ) ); void pipe( diff --git a/packages/http/src/types.ts b/packages/http/src/types.ts index 554e16c4b..9588ba5c4 100644 --- a/packages/http/src/types.ts +++ b/packages/http/src/types.ts @@ -11,7 +11,7 @@ export type PrismHttpComponents = IPrismComponents