Skip to content

Commit

Permalink
feat(http-server): support delay range
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Nov 28, 2024
1 parent 9dbe170 commit 28a4360
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/http-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe

const delay: E.Either<Error, O.Option<number>> = 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(
Expand Down
2 changes: 1 addition & 1 deletion packages/http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PrismHttpComponents = IPrismComponents<IHttpOperation, IHttpRequest,
export interface IHttpOperationConfig {
mediaTypes?: string[];
code?: number;
delay?: number;
delay?: number | [number, number];
chaos?: {
rate: number;
} & (
Expand Down

0 comments on commit 28a4360

Please sign in to comment.