import { Logger } from 'kibana/server' ; import { of } from 'rxjs' ; import { elasticsearchServiceMock } from 'src/core/server/mocks' ; import { IRuleDataClient } from '../../../../../rule_registry/server' ; import { ruleRegistryMocks } from '../../../../../rule_registry/server/mocks' ; import { PluginSetupContract as AlertingPluginSetupContract } from '../../../../../alerting/server' ; import { APMConfig , APM_SERVER_FEATURE_ID } from '../../..' ; export const createRuleTypeMocks = ( ) => { let alertExecutor ; const mockedConfig$ = of ( { indices : { error : 'apm-*' , transaction : 'apm-*' , } , } as APMConfig ) ; const loggerMock = { debug : jest . fn ( ) , warn : jest . fn ( ) , error : jest . fn ( ) , } as unknown as Logger ; const alerting = { registerType : ( { executor } ) => { alertExecutor = executor ; } , } as AlertingPluginSetupContract ; const scheduleActions = jest . fn ( ) ; const services = { scopedClusterClient : elasticsearchServiceMock . createScopedClusterClient ( ) , savedObjectsClient : { get : ( ) => ( { attributes : { consumer : APM_SERVER_FEATURE_ID } } ) , } , alertInstanceFactory : jest . fn ( ( ) => ( { scheduleActions } ) ) , alertWithLifecycle : jest . fn ( ) , logger : loggerMock , shouldWriteAlerts : ( ) => true , } ; return { dependencies : { alerting , config$ : mockedConfig$ , logger : loggerMock , ruleDataClient : ruleRegistryMocks . createRuleDataClient ( '.alerts-observability.apm.alerts' ) as IRuleDataClient , } , services , scheduleActions , executor : async ( { params } ) => { return alertExecutor ( { services , params , rule : { consumer : APM_SERVER_FEATURE_ID , name : 'name' , producer : 'producer' , ruleTypeId : 'ruleTypeId' , ruleTypeName : 'ruleTypeName' , } , startedAt : new Date ( ) , } ) ; } , } ; } ;