Skip to content

Commit

Permalink
[Alerts] fix failing executionStatus function test with null deref (#…
Browse files Browse the repository at this point in the history
…79809) (#79992)

resolves #79248

Added some additional checks for potential null/undefined objects before
dereferencing them.
  • Loading branch information
pmuellr authored Oct 8, 2020
1 parent 9ab16bb commit 7b0a053
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -307,6 +309,7 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
}

function expectErrorExecutionStatus(executionStatus: Record<string, any>, startDate: number) {
expect(executionStatus).to.be.ok();
expect(executionStatus.status).to.equal('error');

const statusDate = Date.parse(executionStatus.lastExecutionDate);
Expand Down

0 comments on commit 7b0a053

Please sign in to comment.