feat(utils): add utils library with a fake ramdon generator

This commit is contained in:
thomas
2022-12-15 17:04:07 +01:00
parent 0979a9f3db
commit c60791a530
13 changed files with 192 additions and 10 deletions

View File

@@ -0,0 +1 @@
export * from './lib/random-http-error.utils';

View File

@@ -0,0 +1,24 @@
import { randNumber } from '@ngneat/falso';
/**
* Execute success function if value is above threshold and error function otherwise
* Success and error function should return the same ReturnType
* @param success
* @param error
* @param threashold default to 0.5
*/
export const randomError = <T>({
success,
error,
threashold,
}: {
success: () => T;
error: () => T;
threashold?: number;
}): T => {
const randomNumber = randNumber({ min: 0.1, max: 1, fraction: 2 });
if (randomNumber > (threashold ?? 0.5)) {
return success();
}
return error();
};

View File

@@ -0,0 +1 @@
import 'jest-preset-angular/setup-jest';