@@ -23,6 +23,7 @@ describe('execute()', () => {
2323 actionTypeRegistry : actionTypeRegistryMock . create ( ) ,
2424 getScopedSavedObjectsClient : jest . fn ( ) . mockReturnValueOnce ( savedObjectsClient ) ,
2525 isESOUsingEphemeralEncryptionKey : false ,
26+ preconfiguredActions : [ ] ,
2627 } ) ;
2728 savedObjectsClient . get . mockResolvedValueOnce ( {
2829 id : '123' ,
@@ -68,6 +69,68 @@ describe('execute()', () => {
6869 } ) ;
6970 } ) ;
7071
72+ test ( 'schedules the action with all given parameters with a preconfigured action' , async ( ) => {
73+ const executeFn = createExecuteFunction ( {
74+ getBasePath,
75+ taskManager : mockTaskManager ,
76+ actionTypeRegistry : actionTypeRegistryMock . create ( ) ,
77+ getScopedSavedObjectsClient : jest . fn ( ) . mockReturnValueOnce ( savedObjectsClient ) ,
78+ isESOUsingEphemeralEncryptionKey : false ,
79+ preconfiguredActions : [
80+ {
81+ id : '123' ,
82+ actionTypeId : 'mock-action-preconfigured' ,
83+ config : { } ,
84+ isPreconfigured : true ,
85+ name : 'x' ,
86+ secrets : { } ,
87+ } ,
88+ ] ,
89+ } ) ;
90+ savedObjectsClient . get . mockResolvedValueOnce ( {
91+ id : '123' ,
92+ type : 'action' ,
93+ attributes : {
94+ actionTypeId : 'mock-action' ,
95+ } ,
96+ references : [ ] ,
97+ } ) ;
98+ savedObjectsClient . create . mockResolvedValueOnce ( {
99+ id : '234' ,
100+ type : 'action_task_params' ,
101+ attributes : { } ,
102+ references : [ ] ,
103+ } ) ;
104+ await executeFn ( {
105+ id : '123' ,
106+ params : { baz : false } ,
107+ spaceId : 'default' ,
108+ apiKey : Buffer . from ( '123:abc' ) . toString ( 'base64' ) ,
109+ } ) ;
110+ expect ( mockTaskManager . schedule ) . toHaveBeenCalledTimes ( 1 ) ;
111+ expect ( mockTaskManager . schedule . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
112+ Array [
113+ Object {
114+ "params": Object {
115+ "actionTaskParamsId": "234",
116+ "spaceId": "default",
117+ },
118+ "scope": Array [
119+ "actions",
120+ ],
121+ "state": Object {},
122+ "taskType": "actions:mock-action-preconfigured",
123+ },
124+ ]
125+ ` ) ;
126+ expect ( savedObjectsClient . get ) . not . toHaveBeenCalled ( ) ;
127+ expect ( savedObjectsClient . create ) . toHaveBeenCalledWith ( 'action_task_params' , {
128+ actionId : '123' ,
129+ params : { baz : false } ,
130+ apiKey : Buffer . from ( '123:abc' ) . toString ( 'base64' ) ,
131+ } ) ;
132+ } ) ;
133+
71134 test ( 'uses API key when provided' , async ( ) => {
72135 const getScopedSavedObjectsClient = jest . fn ( ) . mockReturnValueOnce ( savedObjectsClient ) ;
73136 const executeFn = createExecuteFunction ( {
@@ -76,6 +139,7 @@ describe('execute()', () => {
76139 getScopedSavedObjectsClient,
77140 isESOUsingEphemeralEncryptionKey : false ,
78141 actionTypeRegistry : actionTypeRegistryMock . create ( ) ,
142+ preconfiguredActions : [ ] ,
79143 } ) ;
80144 savedObjectsClient . get . mockResolvedValueOnce ( {
81145 id : '123' ,
@@ -125,6 +189,7 @@ describe('execute()', () => {
125189 getScopedSavedObjectsClient,
126190 isESOUsingEphemeralEncryptionKey : false ,
127191 actionTypeRegistry : actionTypeRegistryMock . create ( ) ,
192+ preconfiguredActions : [ ] ,
128193 } ) ;
129194 savedObjectsClient . get . mockResolvedValueOnce ( {
130195 id : '123' ,
@@ -171,6 +236,7 @@ describe('execute()', () => {
171236 getScopedSavedObjectsClient,
172237 isESOUsingEphemeralEncryptionKey : true ,
173238 actionTypeRegistry : actionTypeRegistryMock . create ( ) ,
239+ preconfiguredActions : [ ] ,
174240 } ) ;
175241 await expect (
176242 executeFn ( {
@@ -193,6 +259,7 @@ describe('execute()', () => {
193259 getScopedSavedObjectsClient,
194260 isESOUsingEphemeralEncryptionKey : false ,
195261 actionTypeRegistry : mockedActionTypeRegistry ,
262+ preconfiguredActions : [ ] ,
196263 } ) ;
197264 mockedActionTypeRegistry . ensureActionTypeEnabled . mockImplementation ( ( ) => {
198265 throw new Error ( 'Fail' ) ;
0 commit comments