import { MinLengthValidation } from '@/validation/validators' ; import { InvalidFieldError } from '@/validation/errors' ; import faker from 'faker' ; const makeSut = ( field ) : MinLengthValidation => new MinLengthValidation ( field , 5 ) ; describe ( 'MinLengthValidation' , ( ) => { test ( 'Should return error if value is invalid' , ( ) => { const field = faker . database . column ( ) ; const sut = makeSut ( field ) ; const error = sut . validate ( { [ field ] : faker . random . alphaNumeric ( 4 ) } ) ; expect ( error ) . toEqual ( new InvalidFieldError ( ) ) ; } ) ; test ( 'Should return falsy if value is valid' , ( ) => { const field = faker . database . column ( ) ; const sut = makeSut ( field ) ; const error = sut . validate ( { [ field ] : faker . random . alphaNumeric ( 5 ) } ) ; expect ( error ) . toBeFalsy ( ) ; } ) ; test ( 'Should return falsy if field does not exists in schema' , ( ) => { const sut = makeSut ( 'any_field' ) ; const error = sut . validate ( { invalidField : faker . random . alphaNumeric ( 5 ) } ) ; expect ( error ) . toBeFalsy ( ) ; } ) ; } ) ;