@@ -25,12 +25,12 @@ import { alertsMock, alertsClientMock } from '../mocks';
2525import { eventLoggerMock } from '../../../event_log/server/event_logger.mock' ;
2626import { IEventLogger } from '../../../event_log/server' ;
2727import { SavedObjectsErrorHelpers } from '../../../../../src/core/server' ;
28- import { Alert } from '../../common' ;
28+ import { Alert , ResolvedActionGroup } from '../../common' ;
2929import { omit } from 'lodash' ;
3030const alertType = {
3131 id : 'test' ,
3232 name : 'My test alert' ,
33- actionGroups : [ { id : 'default' , name : 'Default' } ] ,
33+ actionGroups : [ { id : 'default' , name : 'Default' } , ResolvedActionGroup ] ,
3434 defaultActionGroupId : 'default' ,
3535 executor : jest . fn ( ) ,
3636 producer : 'alerts' ,
@@ -91,7 +91,7 @@ describe('Task Runner', () => {
9191 throttle : null ,
9292 muteAll : false ,
9393 enabled : true ,
94- alertTypeId : '123' ,
94+ alertTypeId : alertType . id ,
9595 apiKey : '' ,
9696 apiKeyOwner : 'elastic' ,
9797 schedule : { interval : '10s' } ,
@@ -112,6 +112,14 @@ describe('Task Runner', () => {
112112 foo : true ,
113113 } ,
114114 } ,
115+ {
116+ group : ResolvedActionGroup . id ,
117+ id : '2' ,
118+ actionTypeId : 'action' ,
119+ params : {
120+ isResolved : true ,
121+ } ,
122+ } ,
115123 ] ,
116124 executionStatus : {
117125 status : 'unknown' ,
@@ -507,6 +515,79 @@ describe('Task Runner', () => {
507515 ` ) ;
508516 } ) ;
509517
518+ test ( 'fire resolved actions for execution for the alertInstances which is in the resolved state' , async ( ) => {
519+ taskRunnerFactoryInitializerParams . actionsPlugin . isActionTypeEnabled . mockReturnValue ( true ) ;
520+ taskRunnerFactoryInitializerParams . actionsPlugin . isActionExecutable . mockReturnValue ( true ) ;
521+
522+ alertType . executor . mockImplementation (
523+ ( { services : executorServices } : AlertExecutorOptions ) => {
524+ executorServices . alertInstanceFactory ( '1' ) . scheduleActions ( 'default' ) ;
525+ }
526+ ) ;
527+ const taskRunner = new TaskRunner (
528+ alertType ,
529+ {
530+ ...mockedTaskInstance ,
531+ state : {
532+ ...mockedTaskInstance . state ,
533+ alertInstances : {
534+ '1' : { meta : { } , state : { bar : false } } ,
535+ '2' : { meta : { } , state : { bar : false } } ,
536+ } ,
537+ } ,
538+ } ,
539+ taskRunnerFactoryInitializerParams
540+ ) ;
541+ alertsClient . get . mockResolvedValue ( mockedAlertTypeSavedObject ) ;
542+ encryptedSavedObjectsClient . getDecryptedAsInternalUser . mockResolvedValue ( {
543+ id : '1' ,
544+ type : 'alert' ,
545+ attributes : {
546+ apiKey : Buffer . from ( '123:abc' ) . toString ( 'base64' ) ,
547+ } ,
548+ references : [ ] ,
549+ } ) ;
550+ const runnerResult = await taskRunner . run ( ) ;
551+ expect ( runnerResult . state . alertInstances ) . toMatchInlineSnapshot ( `
552+ Object {
553+ "1": Object {
554+ "meta": Object {
555+ "lastScheduledActions": Object {
556+ "date": 1970-01-01T00:00:00.000Z,
557+ "group": "default",
558+ },
559+ },
560+ "state": Object {
561+ "bar": false,
562+ },
563+ },
564+ }
565+ ` ) ;
566+
567+ const eventLogger = taskRunnerFactoryInitializerParams . eventLogger ;
568+ expect ( eventLogger . logEvent ) . toHaveBeenCalledTimes ( 5 ) ;
569+ expect ( actionsClient . enqueueExecution ) . toHaveBeenCalledTimes ( 2 ) ;
570+ expect ( actionsClient . enqueueExecution . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
571+ Array [
572+ Object {
573+ "apiKey": "MTIzOmFiYw==",
574+ "id": "2",
575+ "params": Object {
576+ "isResolved": true,
577+ },
578+ "source": Object {
579+ "source": Object {
580+ "id": "1",
581+ "type": "alert",
582+ },
583+ "type": "SAVED_OBJECT",
584+ },
585+ "spaceId": undefined,
586+ },
587+ ]
588+ ` ) ;
589+ } ) ;
590+
510591 test ( 'persists alertInstances passed in from state, only if they are scheduled for execution' , async ( ) => {
511592 alertType . executor . mockImplementation (
512593 ( { services : executorServices } : AlertExecutorOptions ) => {
0 commit comments