From 5dfe01ca7770e78c062eef8ba48e70d58df71f90 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 17 Jan 2022 21:08:31 -0800 Subject: [PATCH] fixed tests --- .../server/lib/action_executor.test.ts | 4 +- .../actions/server/lib/action_executor.ts | 41 ++++++++----------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/actions/server/lib/action_executor.test.ts b/x-pack/plugins/actions/server/lib/action_executor.test.ts index a8fa17c9840fd..aea6bdfa72b1b 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.test.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.test.ts @@ -18,7 +18,6 @@ import { actionsMock, actionsClientMock } from '../mocks'; import { pick } from 'lodash'; const actionExecutor = new ActionExecutor({ isESOCanEncrypt: true }); -getActionsClientWithRequest.mockResolvedValue(actionsClient); const services = actionsMock.createServices(); const actionsClient = actionsClientMock.create(); @@ -51,6 +50,7 @@ actionExecutor.initialize({ beforeEach(() => { jest.resetAllMocks(); spacesMock.getSpaceId.mockReturnValue('some-namespace'); + getActionsClientWithRequest.mockResolvedValue(actionsClient); }); test('successfully executes', async () => { @@ -115,6 +115,7 @@ test('successfully executes', async () => { Object { "event": Object { "action": "execute-start", + "kind": "action", }, "kibana": Object { "saved_objects": Array [ @@ -134,6 +135,7 @@ test('successfully executes', async () => { Object { "event": Object { "action": "execute", + "kind": "action", "outcome": "success", }, "kibana": Object { diff --git a/x-pack/plugins/actions/server/lib/action_executor.ts b/x-pack/plugins/actions/server/lib/action_executor.ts index 0f78a060928e7..1f99e7fc55381 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.ts @@ -69,7 +69,6 @@ export class ActionExecutor { private isInitialized = false; private actionExecutorContext?: ActionExecutorContext; private readonly isESOCanEncrypt: boolean; - private actionInfo: ActionInfo | undefined; constructor({ isESOCanEncrypt }: { isESOCanEncrypt: boolean }) { this.isESOCanEncrypt = isESOCanEncrypt; @@ -126,17 +125,15 @@ export class ActionExecutor { const spaceId = spaces && spaces.getSpaceId(request); const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {}; - if (!this.actionInfo || this.actionInfo.actionId !== actionId) { - this.actionInfo = await getActionInfoInternal( - await getActionsClientWithRequest(request, source), - encryptedSavedObjectsClient, - preconfiguredActions, - actionId, - namespace.namespace - ); - } + const actionInfo = await getActionInfoInternal( + await getActionsClientWithRequest(request, source), + encryptedSavedObjectsClient, + preconfiguredActions, + actionId, + namespace.namespace + ); - const { actionTypeId, name, config, secrets } = this.actionInfo; + const { actionTypeId, name, config, secrets } = actionInfo; if (span) { span.name = `execute_action ${actionTypeId}`; @@ -299,15 +296,13 @@ export class ActionExecutor { const spaceId = spaces && spaces.getSpaceId(request); const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {}; - if (!this.actionInfo || this.actionInfo.actionId !== actionId) { - this.actionInfo = await getActionInfoInternal( - await getActionsClientWithRequest(request, source), - encryptedSavedObjectsClient, - preconfiguredActions, - actionId, - namespace.namespace - ); - } + const actionInfo = await getActionInfoInternal( + await getActionsClientWithRequest(request, source), + encryptedSavedObjectsClient, + preconfiguredActions, + actionId, + namespace.namespace + ); const task = taskInfo ? { task: { @@ -320,8 +315,8 @@ export class ActionExecutor { const event = createActionEventLogRecordObject({ actionId, action: EVENT_LOG_ACTIONS.executeTimeout, - message: `action: ${this.actionInfo.actionTypeId}:${actionId}: '${ - this.actionInfo.name ?? '' + message: `action: ${actionInfo.actionTypeId}:${actionId}: '${ + actionInfo.name ?? '' }' execution cancelled due to timeout - exceeded default timeout of "5m"`, ...namespace, ...task, @@ -329,7 +324,7 @@ export class ActionExecutor { { type: 'action', id: actionId, - typeId: this.actionInfo.actionTypeId, + typeId: actionInfo.actionTypeId, relation: SAVED_OBJECT_REL_PRIMARY, }, ],