import { pipe } from 'fp-ts/lib/pipeable' ; import { left } from 'fp-ts/lib/Either' ; import { exactCheck , foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ; import { SearchEsListSchema , searchEsListSchema } from './search_es_list_schema' ; import { getSearchEsListMock } from './search_es_list_schema.mock' ; describe ( 'search_es_list_schema' , ( ) => { test ( 'it should validate against the mock' , ( ) => { const payload = getSearchEsListMock ( ) ; const decoded = searchEsListSchema . decode ( payload ) ; const checked = exactCheck ( payload , decoded ) ; const message = pipe ( checked , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( payload ) ; } ) ; test ( 'it should FAIL validation when a madeup value' , ( ) => { const payload = { ... getSearchEsListMock ( ) , madeupValue : 'madeupvalue' , } ; const decoded = searchEsListSchema . decode ( payload ) ; const checked = exactCheck ( payload , decoded ) ; const message = pipe ( checked , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'invalid keys "madeupValue"' ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; } ) ;