import { left } from 'fp-ts/lib/Either' ; import { enumeration } from '.' ; import { foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ; describe ( 'enumeration' , ( ) => { enum TestEnum { 'test' = 'test' } it ( 'should validate a string from the enum' , ( ) => { const input = TestEnum . test ; const codec = enumeration ( 'TestEnum' , TestEnum ) ; const decoded = codec . decode ( input ) ; const message = foldLeftRight ( decoded ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( input ) ; } ) ; it ( 'should NOT validate a random string' , ( ) => { const input = 'some string' ; const codec = enumeration ( 'TestEnum' , TestEnum ) ; const decoded = codec . decode ( input ) ; const message = foldLeftRight ( decoded ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "some string" supplied to "TestEnum"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; } ) ;