import * as callApiExports from './rest/callApi' ; import { createCallApmApi , callApmApi } from './rest/createCallApmApi' ; import { CoreStart } from 'kibana/public' ; const callApi = jest . spyOn ( callApiExports , 'callApi' ) . mockImplementation ( ( ) => Promise . resolve ( null ) ) ; describe ( 'callApmApi' , ( ) => { beforeEach ( ( ) => { createCallApmApi ( { } as CoreStart ) ; } ) ; afterEach ( ( ) => { callApi . mockClear ( ) ; } ) ; it ( 'should format the pathname with the given path params' , async ( ) => { await callApmApi ( { endpoint : 'GET /internal/apm/{param1}/to/{param2}' , params : { path : { param1 : 'foo' , param2 : 'bar' , } , } , } as never ) ; expect ( callApi ) . toHaveBeenCalledWith ( { } , expect . objectContaining ( { pathname : '/internal/apm/foo/to/bar' , } ) ) ; } ) ; it ( 'should add the query parameters to the options object' , async ( ) => { await callApmApi ( { endpoint : 'GET /internal/apm' , params : { query : { foo : 'bar' , bar : 'foo' , } , } , } as never ) ; expect ( callApi ) . toHaveBeenCalledWith ( { } , expect . objectContaining ( { pathname : '/internal/apm' , query : { foo : 'bar' , bar : 'foo' , } , } ) ) ; } ) ; it ( 'should stringify the body and add it to the options object' , async ( ) => { await callApmApi ( { endpoint : 'POST /internal/apm' , params : { body : { foo : 'bar' , bar : 'foo' , } , } , } as never ) ; expect ( callApi ) . toHaveBeenCalledWith ( { } , expect . objectContaining ( { pathname : '/internal/apm' , method : 'post' , body : { foo : 'bar' , bar : 'foo' , } , } ) ) ; } ) ; } ) ;