import { KibanaRequest , KibanaResponseFactory } from 'kibana/server' ; import { identity } from 'lodash' ; import type { MethodKeysOf } from '@kbn/utility-types' ; import { httpServerMock } from '../../../../../src/core/server/mocks' ; import { rulesClientMock , RulesClientMock } from '../rules_client.mock' ; import { AlertsHealth , RuleType } from '../../common' ; import type { AlertingRequestHandlerContext } from '../types' ; export function mockHandlerArguments ( { rulesClient = rulesClientMock . create ( ) , listTypes : listTypesRes = [ ] , getFrameworkHealth , areApiKeysEnabled , } , req , res ? ) { const listTypes = jest . fn ( ( ) => listTypesRes ) ; return [ { alerting : { listTypes , getRulesClient ( ) { return rulesClient || rulesClientMock . create ( ) ; } , getFrameworkHealth , areApiKeysEnabled : areApiKeysEnabled ? areApiKeysEnabled : ( ) => Promise . resolve ( true ) , } , } as unknown as AlertingRequestHandlerContext , req as KibanaRequest < unknown , unknown , unknown > , mockResponseFactory ( res ) , ] ; } export const mockResponseFactory = ( resToMock = [ ] ) => { const factory = httpServerMock . createResponseFactory ( ) ; resToMock . forEach ( ( key ) => { if ( key in factory ) { Object . defineProperty ( factory , key , { value : jest . fn ( identity ) , } ) ; } } ) ; return factory as unknown as KibanaResponseFactory ; } ;