import { taskManagerMock } from '../../../../task_manager/server/mocks' ; import { IEventLogClient } from '../../../../event_log/server' ; import { actionsClientMock } from '../../../../actions/server/mocks' ; import { ConstructorOptions } from '../rules_client' ; import { eventLogClientMock } from '../../../../event_log/server/mocks' ; import { RuleTypeRegistry } from '../../rule_type_registry' ; import { RecoveredActionGroup } from '../../../common' ; export const mockedDateString = '2019-02-12T21:01:22.479Z' ; export function setGlobalDate ( ) { const mockedDate = new Date ( mockedDateString ) ; const DateOriginal = Date ; ( global as any ) . Date = class Date { constructor ( ... args ) { if ( args [ 0 ] == null ) { return mockedDate ; } else { return new DateOriginal ( ... args ) ; } } static now ( ) { return mockedDate . getTime ( ) ; } static parse ( string ) { return DateOriginal . parse ( string ) ; } } ; } export function getBeforeSetup ( rulesClientParams , taskManager , ruleTypeRegistry , eventLogClient ? ) { jest . resetAllMocks ( ) ; rulesClientParams . createAPIKey . mockResolvedValue ( { apiKeysEnabled : false } ) ; rulesClientParams . getUserName . mockResolvedValue ( 'elastic' ) ; taskManager . runNow . mockResolvedValue ( { id : '' } ) ; const actionsClient = actionsClientMock . create ( ) ; actionsClient . getBulk . mockResolvedValueOnce ( [ { id : '1' , isPreconfigured : false , actionTypeId : 'test' , name : 'test' , config : { foo : 'bar' , } , } , { id : '2' , isPreconfigured : false , actionTypeId : 'test2' , name : 'test2' , config : { foo : 'bar' , } , } , { id : 'testPreconfigured' , actionTypeId : '.slack' , isPreconfigured : true , name : 'test' , } , ] ) ; rulesClientParams . getActionsClient . mockResolvedValue ( actionsClient ) ; ruleTypeRegistry . get . mockImplementation ( ( ) => ( { id : '123' , name : 'Test' , actionGroups : [ { id : 'default' , name : 'Default' } ] , recoveryActionGroup : RecoveredActionGroup , defaultActionGroupId : 'default' , minimumLicenseRequired : 'basic' , isExportable : true , async executor ( ) { } , producer : 'alerts' , } ) ) ; rulesClientParams . getEventLogClient . mockResolvedValue ( eventLogClient ?? eventLogClientMock . create ( ) ) ; }