Skip to content

Commit

Permalink
[Cases] Fixing a few more integration tests with arraysToEqual (elast…
Browse files Browse the repository at this point in the history
…ic#155942)

This PR fixes a few integration tests that were failing because the
ordering of the bulk creation of attachments isn't guaranteed. The
solution is to compare the results ignoring ordering within the arrays.

Fixes: elastic#154640

Flaky test runner results:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2178
🟢
  • Loading branch information
jonathan-buttner authored Apr 27, 2023
1 parent b8ca723 commit 7000f0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from '@kbn/expect';
import { RecordingServiceNowSimulator } from '@kbn/actions-simulators-plugin/server/servicenow_simulation';
import { arraysToEqual } from '../../../common/lib/validation';
import {
postCommentUserReq,
postCommentAlertReq,
Expand All @@ -32,8 +33,7 @@ export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('es');

// Failing: See https://github.com/elastic/kibana/issues/154640
describe.skip('push_case', () => {
describe('push_case', () => {
describe('incident recorder server', () => {
const actionsRemover = new ActionsRemover(supertest);
let serviceNowSimulatorURL: string = '';
Expand Down Expand Up @@ -114,6 +114,14 @@ export default ({ getService }: FtrProviderContext): void => {
Boolean(request.work_notes)
);

const allWorkNotes = allCommentRequests.map((request) => request.work_notes);
const expectedNotes = [
'This is a cool comment\n\nAdded by elastic.',
'Isolated host host-name with comment: comment text\n\nAdded by elastic.',
'Released host host-name with comment: comment text\n\nAdded by elastic.',
'Elastic Alerts attached to the case: 3',
];

/**
* For each of these comments a request is made:
* postCommentUserReq, postCommentActionsReq, postCommentActionsReleaseReq, and a comment with the
Expand All @@ -122,21 +130,9 @@ export default ({ getService }: FtrProviderContext): void => {
*/
expect(allCommentRequests.length).be(4);

// User comment: postCommentUserReq
expect(allCommentRequests[0].work_notes).eql('This is a cool comment\n\nAdded by elastic.');

// Isolate host comment: postCommentActionsReq
expect(allCommentRequests[1].work_notes).eql(
'Isolated host host-name with comment: comment text\n\nAdded by elastic.'
);

// Unisolate host comment: postCommentActionsReleaseReq
expect(allCommentRequests[2].work_notes).eql(
'Released host host-name with comment: comment text\n\nAdded by elastic.'
);

// Total alerts
expect(allCommentRequests[3].work_notes).eql('Elastic Alerts attached to the case: 3');
// since we're using a bulk create we can't guarantee the ordering so we'll check that the values exist but not
// there specific order in the results
expect(arraysToEqual(allWorkNotes, expectedNotes)).to.be(true);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
secOnlyRead,
superUser,
} from '../../../../common/lib/authentication/users';
import { arraysToEqual } from '../../../../common/lib/validation';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
Expand Down Expand Up @@ -217,6 +218,14 @@ export default ({ getService }: FtrProviderContext): void => {
Boolean(request.work_notes)
);

const allWorkNotes = allCommentRequests.map((request) => request.work_notes);
const expectedNotes = [
'This is a cool comment\n\nAdded by elastic.',
'Isolated host host-name with comment: comment text\n\nAdded by elastic.',
'Released host host-name with comment: comment text\n\nAdded by elastic.',
`Elastic Alerts attached to the case: 3\n\nFor more details, view the alerts in Kibana\nAlerts URL: https://localhost:5601/app/management/insightsAndAlerting/cases/${patchedCase.id}/?tabId=alerts`,
];

/**
* For each of these comments a request is made:
* postCommentUserReq, postCommentActionsReq, postCommentActionsReleaseReq, and a comment with the
Expand All @@ -225,23 +234,9 @@ export default ({ getService }: FtrProviderContext): void => {
*/
expect(allCommentRequests.length).be(4);

// User comment: postCommentUserReq
expect(allCommentRequests[0].work_notes).eql('This is a cool comment\n\nAdded by elastic.');

// Isolate host comment: postCommentActionsReq
expect(allCommentRequests[1].work_notes).eql(
'Isolated host host-name with comment: comment text\n\nAdded by elastic.'
);

// Unisolate host comment: postCommentActionsReleaseReq
expect(allCommentRequests[2].work_notes).eql(
'Released host host-name with comment: comment text\n\nAdded by elastic.'
);

// Total alerts
expect(allCommentRequests[3].work_notes).eql(
`Elastic Alerts attached to the case: 3\n\nFor more details, view the alerts in Kibana\nAlerts URL: https://localhost:5601/app/management/insightsAndAlerting/cases/${patchedCase.id}/?tabId=alerts`
);
// since we're using a bulk create we can't guarantee the ordering so we'll check that the values exist but not
// there specific order in the results
expect(arraysToEqual(allWorkNotes, expectedNotes)).to.be(true);
});

it('should format the totalAlerts with spaceId correctly', async () => {
Expand Down

0 comments on commit 7000f0d

Please sign in to comment.