import { getBuckets } from './get_buckets' ; import { APMConfig } from '../../..' ; import { ProcessorEvent } from '../../../../common/processor_event' ; describe ( 'get buckets' , ( ) => { let clientSpy ; beforeEach ( async ( ) => { clientSpy = jest . fn ( ) . mockResolvedValueOnce ( { hits : { total : 100 , } , aggregations : { distribution : { buckets : [ ] , } , } , } ) ; await getBuckets ( { environment : 'prod' , serviceName : 'myServiceName' , bucketSize : 10 , kuery : '' , setup : { apmEventClient : { search : clientSpy , } as any , internalClient : { search : clientSpy , } as any , config : new Proxy ( { } , { get : ( ) => 'myIndex' , } ) as APMConfig , indices : { sourcemap : 'apm-*' , error : 'apm-*' , onboarding : 'apm-*' , span : 'apm-*' , transaction : 'apm-*' , metric : 'apm-*' , apmAgentConfigurationIndex : '.apm-agent-configuration' , apmCustomLinkIndex : '.apm-custom-link' , } , } , start : 1528113600000 , end : 1528977600000 , } ) ; } ) ; it ( 'should make the correct query' , ( ) => { expect ( clientSpy . mock . calls ) . toMatchSnapshot ( ) ; } ) ; it ( 'should limit query results to error documents' , ( ) => { const query = clientSpy . mock . calls [ 0 ] [ 1 ] ; expect ( query . apm . events ) . toEqual ( [ ProcessorEvent . error ] ) ; } ) ; } ) ;