import { IAnySchemaRules } from '~/domain/entities/schemas/any-schema'; import { expectResult, getMakeSut, testEachAdapter, falsyValues } from '../helpers'; const testEachFalsy = (cb: (value: undefined | null) => void): void => { falsyValues.forEach(value => { const name = value === null ? 'null' : String(value); test(name, () => { cb(value); }); }); }; describe('Integration - Common Tests', () => { testEachAdapter(type => { const makeSut = getMakeSut(type); const req = (value: boolean): IAnySchemaRules => ({ required: value }); test('[required = true], should throw error if value is falsy', () => { const { sut } = makeSut(req(true)); falsyValues.forEach(value => { expectResult(sut.validate(value)).toBeInvalid(); }); }); describe('[required = false], should not throw error if value is falsy', () => { testEachFalsy(value => { const { sut } = makeSut(req(false)); expectResult(sut.validate(value)).toBeValid(); }); }); }); });