import { CompareFieldsValidation } from '@/validation/validators' ; import { InvalidFieldError } from '@/validation/errors' ; import faker from 'faker' ; const makeSut = ( field , fieldToCompare ) : CompareFieldsValidation => new CompareFieldsValidation ( field , fieldToCompare ) ; describe ( 'CompareFieldsValidation' , ( ) => { test ( 'Should return error if compare is invalid' , ( ) => { const field = 'any_field' ; const fieldToCompare = 'other_field' ; const sut = makeSut ( field , fieldToCompare ) ; const error = sut . validate ( { [ field ] : 'any_value' , [ fieldToCompare ] : 'other_value' } ) ; expect ( error ) . toEqual ( new InvalidFieldError ( ) ) ; } ) ; test ( 'Should return falsy if compare is valid' , ( ) => { const field = 'any_field' ; const fieldToCompare = 'other_field' ; const value = faker . random . word ( ) ; const sut = makeSut ( field , fieldToCompare ) ; const error = sut . validate ( { [ field ] : value , [ fieldToCompare ] : value } ) ; expect ( error ) . toBeFalsy ( ) ; } ) ; } ) ;