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 { SearchEsListItemSchema , searchEsListItemSchema } from './search_es_list_item_schema' ; import { getSearchEsListItemMock } from './search_es_list_item_schema.mock' ; describe ( 'search_es_list_item_schema' , ( ) => { test ( 'it should validate against the mock' , ( ) => { const payload = getSearchEsListItemMock ( ) ; const decoded = searchEsListItemSchema . 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 = { ... getSearchEsListItemMock ( ) , madeupValue : 'madeupvalue' , } ; const decoded = searchEsListItemSchema . 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 ( { } ) ; } ) ; } ) ;