import { ValidationSchemas, schemaTypes, ValidationError } from '~/domain'; import { themis } from '~/main'; export * from '../helpers'; export const expectResult = (actual: ValidationError | null) => { const toBeInvalid = () => { expect(actual).not.toBeValidResult(); }; const toBeValid = () => { expect(actual).toBeValidResult(); }; return { toBeInvalid, toBeValid, toBe: (valid: boolean) => { return (valid ? toBeValid : toBeInvalid)(); }, }; }; export const falsyValues: [undefined, null] = [undefined, null]; export const testEachAdapter = (cb: (type: ValidationSchemas.Type) => void, testMethod?: 'test' | 'describe') => { const m = testMethod === 'test' ? test : describe; schemaTypes.forEach(type => { m(type, () => cb(type)); }); }; export const getMakeSut = (type: T) => { const makeSut = (rules?: ValidationSchemas.Rules) => { const sut = themis[type](rules || ({} as any)); return { sut: { validate: (input: Parameters[0]) => { return sut.validate(input); }, }, }; }; return makeSut; }; export const capitalize = (str: string) => { return str.charAt(0).toUpperCase() + str.slice(1); }; export const desc = (parent: string) => { return `Integration - ${capitalize(parent)} Tests`; };