From a17107dc75569eda5839fb44f581b73c2b4cf875 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Thu, 8 Oct 2020 08:26:16 -0400 Subject: [PATCH] [Alerts] fix failing executionStatus function test with null deref (#79809) resolves https://github.com/elastic/kibana/issues/79248 Added some additional checks for potential null/undefined objects before dereferencing them. --- .../tests/alerting/execution_status.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/execution_status.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/execution_status.ts index e19406c4c8452..5ebce8edf6fb7 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/execution_status.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/execution_status.ts @@ -19,8 +19,7 @@ import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function executionStatusAlertTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - // Failing: See https://github.com/elastic/kibana/issues/79248 - describe.skip('executionStatus', () => { + describe('executionStatus', () => { const objectRemover = new ObjectRemover(supertest); after(async () => await objectRemover.removeAll()); @@ -257,14 +256,16 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon `${getUrlPrefix(Spaces.space1.id)}/api/alerts/alert/${id}` ); expect(response.status).to.eql(200); - const { status } = response.body.executionStatus; + + const { executionStatus } = response.body || {}; + const { status } = executionStatus || {}; const message = `waitForStatus(${Array.from(statuses)}): got ${JSON.stringify( - response.body.executionStatus + executionStatus )}`; if (statuses.has(status)) { - return response.body.executionStatus; + return executionStatus; } // eslint-disable-next-line no-console @@ -288,13 +289,14 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon const response = await supertest.get(`${getUrlPrefix(Spaces.space1.id)}/${findUri}`); expect(response.status).to.eql(200); - const { executionStatus } = response.body.data.find((obj: any) => obj.id === id); + const { executionStatus } = response.body.data.find((obj: any) => obj.id === id) || {}; + const { status } = executionStatus || {}; const message = `waitForFindStatus(${Array.from(statuses)}): got ${JSON.stringify( executionStatus )}`; - if (statuses.has(executionStatus.status)) { + if (statuses.has(status)) { return executionStatus; } @@ -307,6 +309,7 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon } function expectErrorExecutionStatus(executionStatus: Record, startDate: number) { + expect(executionStatus).to.be.ok(); expect(executionStatus.status).to.equal('error'); const statusDate = Date.parse(executionStatus.lastExecutionDate);