Skip to content

Commit a1b572f

Browse files
committed
[Alerts] fix failing executionStatus function test with null deref
resolves #79248 Added some additional checks for potential null/undefined objects before dereferencing them.
1 parent 30695fb commit a1b572f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

x-pack/test/alerting_api_integration/spaces_only/tests/alerting/execution_status.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import { FtrProviderContext } from '../../../common/ftr_provider_context';
1919
export default function executionStatusAlertTests({ getService }: FtrProviderContext) {
2020
const supertest = getService('supertest');
2121

22-
// Failing: See https://github.com/elastic/kibana/issues/79248
23-
describe.skip('executionStatus', () => {
22+
describe('executionStatus', () => {
2423
const objectRemover = new ObjectRemover(supertest);
2524

2625
after(async () => await objectRemover.removeAll());
@@ -257,14 +256,16 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
257256
`${getUrlPrefix(Spaces.space1.id)}/api/alerts/alert/${id}`
258257
);
259258
expect(response.status).to.eql(200);
260-
const { status } = response.body.executionStatus;
259+
260+
const { executionStatus } = response.body || {};
261+
const { status } = executionStatus || {};
261262

262263
const message = `waitForStatus(${Array.from(statuses)}): got ${JSON.stringify(
263-
response.body.executionStatus
264+
executionStatus
264265
)}`;
265266

266267
if (statuses.has(status)) {
267-
return response.body.executionStatus;
268+
return executionStatus;
268269
}
269270

270271
// eslint-disable-next-line no-console
@@ -288,13 +289,14 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
288289
const response = await supertest.get(`${getUrlPrefix(Spaces.space1.id)}/${findUri}`);
289290

290291
expect(response.status).to.eql(200);
291-
const { executionStatus } = response.body.data.find((obj: any) => obj.id === id);
292+
const { executionStatus } = response.body.data.find((obj: any) => obj.id === id) || {};
293+
const { status } = executionStatus || {};
292294

293295
const message = `waitForFindStatus(${Array.from(statuses)}): got ${JSON.stringify(
294296
executionStatus
295297
)}`;
296298

297-
if (statuses.has(executionStatus.status)) {
299+
if (statuses.has(status)) {
298300
return executionStatus;
299301
}
300302

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

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

312315
const statusDate = Date.parse(executionStatus.lastExecutionDate);

0 commit comments

Comments
 (0)