import { ValidationSchemas } from '~/domain'; import { ManyTestsHelper } from './helper'; import { ShouldMakeTests } from './load'; import { ManyTestsOptions, TestFn } from './types'; export const doManyTests = (schema: ValidationSchemas, options: ManyTestsOptions = {}) => { const helper = new ManyTestsHelper(options); const should = new ShouldMakeTests(helper); const tests = Object.entries(should) .filter(([key]) => key !== 'help') .map(([_, t]) => t) as Array; const doAllTests = (values: V[], valid: boolean): void => { values.forEach((value: V, index: number) => { const model = helper.getTestFnModel(schema, valid, value, index); tests.forEach(doTest => doTest(model)); }); }; return { valid: (values: V[]) => doAllTests(values, true), invalid: (values: V[]) => doAllTests(values, false), input: (...values: any[]): any[] => { return values.map(value => ({ value })); }, }; };