import { pipe } from 'fp-ts/lib/pipeable' ; import { left } from 'fp-ts/lib/Either' ; import { DefaultUuid } from '.' ; import { foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ; describe ( 'default_uuid' , ( ) => { test ( 'it should validate a regular string' , ( ) => { const payload = '1' ; const decoded = DefaultUuid . 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 = DefaultUuid . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "5" supplied to "DefaultUuid"' ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should return a default of a uuid' , ( ) => { const payload = null ; const decoded = DefaultUuid . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toMatch ( /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i ) ; } ) ; } ) ;