From 6db02cd80810be522fe2915eed82a699a02bc6a9 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Wed, 14 Apr 2021 11:55:06 +0300 Subject: [PATCH] PR feedback --- .../cases/server/client/cases/create.ts | 2 +- .../case_api_integration/common/config.ts | 1 + .../case_api_integration/common/lib/utils.ts | 5 +-- .../tests/common/cases/post_case.ts | 35 ++++++++++++++----- .../tests/common/configure/get_connectors.ts | 2 +- .../tests/trial/cases/push_case.ts | 25 +++++++------ 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/cases/server/client/cases/create.ts b/x-pack/plugins/cases/server/client/cases/create.ts index 61f36050758502..67496599d225da 100644 --- a/x-pack/plugins/cases/server/client/cases/create.ts +++ b/x-pack/plugins/cases/server/client/cases/create.ts @@ -132,7 +132,7 @@ export const create = async ({ actionAt: createdDate, actionBy: { username, full_name, email }, caseId: newCase.id, - fields: ['description', 'status', 'tags', 'title', 'connector', 'settings'], + fields: ['description', 'status', 'tags', 'title', 'connector', 'settings', 'owner'], newValue: JSON.stringify(query), }), ], diff --git a/x-pack/test/case_api_integration/common/config.ts b/x-pack/test/case_api_integration/common/config.ts index 888ae107f221d7..d9dacc649c9f5a 100644 --- a/x-pack/test/case_api_integration/common/config.ts +++ b/x-pack/test/case_api_integration/common/config.ts @@ -62,6 +62,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) fs.statSync(path.resolve(__dirname, 'fixtures', 'plugins', file)).isDirectory() ); + // This is needed so that we can correctly use the alerting test frameworks mock implementation for the connectors. const alertingAllFiles = fs.readdirSync( path.resolve( __dirname, diff --git a/x-pack/test/case_api_integration/common/lib/utils.ts b/x-pack/test/case_api_integration/common/lib/utils.ts index 70b1f249f0b872..32094e60832a97 100644 --- a/x-pack/test/case_api_integration/common/lib/utils.ts +++ b/x-pack/test/case_api_integration/common/lib/utils.ts @@ -613,7 +613,8 @@ export const deleteCases = async ({ expectedHttpCode?: number; }) => { const { body } = await supertest - .delete(`${CASES_URL}?ids=${JSON.stringify(caseIDs)}`) + .delete(`${CASES_URL}`) + .query({ ids: caseIDs }) .set('kbn-xsrf', 'true') .send() .expect(expectedHttpCode); @@ -640,7 +641,7 @@ export const getAllUserAction = async ( supertest: st.SuperTest, caseId: string, expectedHttpCode: number = 200 -) => { +): Promise => { const { body: userActions } = await supertest .get(`${CASES_URL}/${caseId}/user_actions`) .set('kbn-xsrf', 'true') diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/post_case.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/post_case.ts index aa6f33f0294720..1971cb5398b526 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/post_case.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/post_case.ts @@ -5,6 +5,8 @@ * 2.0. */ +/* eslint-disable @typescript-eslint/naming-convention */ + import expect from '@kbn/expect'; import { CASES_URL } from '../../../../../../plugins/cases/common/constants'; @@ -12,6 +14,7 @@ import { ConnectorTypes, ConnectorJiraTypeFields, CaseStatuses, + CaseUserActionResponse, } from '../../../../../../plugins/cases/common/api'; import { getPostCaseRequest, postCaseResp, defaultUser } from '../../../../common/lib/mock'; import { @@ -107,22 +110,36 @@ export default ({ getService }: FtrProviderContext): void => { const userActions = await getAllUserAction(supertest, postedCase.id); const creationUserAction = removeServerGeneratedPropertiesFromUserAction(userActions[0]); - expect(creationUserAction).to.eql({ - action_field: ['description', 'status', 'tags', 'title', 'connector', 'settings'], + const { new_value, ...rest } = creationUserAction as CaseUserActionResponse; + const parsedNewValue = JSON.parse(new_value!); + + expect(rest).to.eql({ + action_field: [ + 'description', + 'status', + 'tags', + 'title', + 'connector', + 'settings', + 'owner', + ], action: 'create', action_by: defaultUser, - new_value: `{"type":"${postedCase.type}","description":"${ - postedCase.description - }","title":"${postedCase.title}","tags":${JSON.stringify( - postedCase.tags - )},"connector":${JSON.stringify(postedCase.connector)},"settings":${JSON.stringify( - postedCase.settings - )},"owner":"${postedCase.owner}"}`, old_value: null, case_id: `${postedCase.id}`, comment_id: null, sub_case_id: '', }); + + expect(parsedNewValue).to.eql({ + type: postedCase.type, + description: postedCase.description, + title: postedCase.title, + tags: postedCase.tags, + connector: postedCase.connector, + settings: postedCase.settings, + owner: postedCase.owner, + }); }); it('creates the case without connector in the configuration', async () => { diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts index bee8ffec233cb3..cfa23a968182f7 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts @@ -89,7 +89,7 @@ export default ({ getService }: FtrProviderContext): void => { }); it.skip('filters out connectors that are not enabled in license', async () => { - // Should find a way to downgrade license to gold and upgrade back to trial + // TODO: Should find a way to downgrade license to gold and upgrade back to trial }); }); }; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/trial/cases/push_case.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/trial/cases/push_case.ts index d78e6a157e7f5e..67773067ad2d49 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/trial/cases/push_case.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/trial/cases/push_case.ts @@ -37,6 +37,7 @@ import { CaseConnector, CaseResponse, CaseStatuses, + CaseUserActionResponse, ConnectorTypes, } from '../../../../../../plugins/cases/common/api'; @@ -149,24 +150,28 @@ export default ({ getService }: FtrProviderContext): void => { const userActions = await getAllUserAction(supertest, pushedCase.id); const pushUserAction = removeServerGeneratedPropertiesFromUserAction(userActions[1]); - expect(pushUserAction).to.eql({ + const { new_value, ...rest } = pushUserAction as CaseUserActionResponse; + const parsedNewValue = JSON.parse(new_value!); + + expect(rest).to.eql({ action_field: ['pushed'], action: 'push-to-service', action_by: defaultUser, - new_value: `{"pushed_at":"${ - pushedCase.external_service!.pushed_at - }","pushed_by":${JSON.stringify({ - username: 'elastic', - full_name: null, - email: null, - })},"connector_id":"${connector.id}","connector_name":"${ - connector.name - }","external_id":"123","external_title":"INC01","external_url":"${servicenowSimulatorURL}/nav_to.do?uri=incident.do?sys_id=123"}`, old_value: null, case_id: `${postedCase.id}`, comment_id: null, sub_case_id: '', }); + + expect(parsedNewValue).to.eql({ + pushed_at: pushedCase.external_service!.pushed_at, + pushed_by: defaultUser, + connector_id: connector.id, + connector_name: connector.name, + external_id: '123', + external_title: 'INC01', + external_url: `${servicenowSimulatorURL}/nav_to.do?uri=incident.do?sys_id=123`, + }); }); // ENABLE_CASE_CONNECTOR: once the case connector feature is completed unskip these tests