import { pipe } from 'fp-ts/lib/pipeable' ; import { left } from 'fp-ts/lib/Either' ; import { DefaultEmptyString } from '.' ; import { foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ; describe ( 'default_empty_string' , ( ) => { test ( 'it should validate a regular string' , ( ) => { const payload = 'some string' ; const decoded = DefaultEmptyString . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( payload ) ; } ) ; test ( 'it should not validate a number' , ( ) => { const payload = 5 ; const decoded = DefaultEmptyString . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "5" supplied to "DefaultEmptyString"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should return a default of ""' , ( ) => { const payload = null ; const decoded = DefaultEmptyString . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( '' ) ; } ) ; } ) ;