From 7000f0d38d8827327bf90b025008643d3c7208dd Mon Sep 17 00:00:00 2001 From: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com> Date: Thu, 27 Apr 2023 11:13:30 -0400 Subject: [PATCH] [Cases] Fixing a few more integration tests with arraysToEqual (#155942) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/elastic/kibana/issues/154640 Flaky test runner results: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2178 🟢 --- .../tests/no_public_base_url/push.ts | 30 ++++++++----------- .../tests/trial/cases/push_case.ts | 29 ++++++++---------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/no_public_base_url/push.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/no_public_base_url/push.ts index f0b07da160674..062a697ebb22e 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/no_public_base_url/push.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/no_public_base_url/push.ts @@ -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, @@ -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 = ''; @@ -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 @@ -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); }); }); }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts index a9d4382fc08bc..608153386ffe5 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts @@ -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 => { @@ -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 @@ -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 () => {