import { IndexPatternsService } from '../../../../../../data/common' ; import { from } from 'rxjs' ; import { AbstractSearchStrategy } from './abstract_search_strategy' ; import type { FieldSpec } from '../../../../../../data/common' ; import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher' ; import type { VisTypeTimeseriesRequestHandlerContext , VisTypeTimeseriesVisDataRequest , } from '../../../types' ; class FooSearchStrategy extends AbstractSearchStrategy { } describe ( 'AbstractSearchStrategy' , ( ) => { let abstractSearchStrategy ; let mockedFields ; let requestContext ; beforeEach ( ( ) => { mockedFields = [ ] ; requestContext = { core : { elasticsearch : { client : { asCurrentUser : jest . fn ( ) , } , } , uiSettings : { client : jest . fn ( ) , } , } , search : { search : jest . fn ( ) . mockReturnValue ( from ( Promise . resolve ( { } ) ) ) , } , } as unknown as VisTypeTimeseriesRequestHandlerContext ; abstractSearchStrategy = new FooSearchStrategy ( ) ; } ) ; test ( 'should init an AbstractSearchStrategy instance' , ( ) => { expect ( abstractSearchStrategy . search ) . toBeDefined ( ) ; expect ( abstractSearchStrategy . getFieldsForWildcard ) . toBeDefined ( ) ; expect ( abstractSearchStrategy . checkForViability ) . toBeDefined ( ) ; } ) ; test ( 'should return fields for wildcard' , async ( ) => { const fields = await abstractSearchStrategy . getFieldsForWildcard ( { indexPatternString : '' , indexPattern : undefined } , { getDefault : jest . fn ( ) , getFieldsForWildcard : jest . fn ( ( ) => Promise . resolve ( mockedFields ) ) , } as unknown as IndexPatternsService , ( ( ) => Promise . resolve ( { } ) as unknown ) as CachedIndexPatternFetcher ) ; expect ( fields ) . toEqual ( mockedFields ) ; } ) ; test ( 'should return response' , async ( ) => { const searches = [ { body : 'body' , index : 'index' } ] ; const responses = await abstractSearchStrategy . search ( requestContext , { body : { searchSession : { sessionId : '1' , isRestore : false , isStored : true , } , } , } as unknown as VisTypeTimeseriesVisDataRequest , searches ) ; expect ( responses ) . toEqual ( [ { } ] ) ; expect ( requestContext . search . search ) . toHaveBeenCalledWith ( { params : { body : 'body' , index : 'index' , } , indexType : undefined , } , { sessionId : '1' , isRestore : false , isStored : true , } ) ; } ) ; } ) ;