Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 14, 2021
1 parent 484ce16 commit 6db02cd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
],
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/case_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions x-pack/test/case_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -640,7 +641,7 @@ export const getAllUserAction = async (
supertest: st.SuperTest<supertestAsPromised.Test>,
caseId: string,
expectedHttpCode: number = 200
) => {
): Promise<CaseUserActionResponse[]> => {
const { body: userActions } = await supertest
.get(`${CASES_URL}/${caseId}/user_actions`)
.set('kbn-xsrf', 'true')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
* 2.0.
*/

/* eslint-disable @typescript-eslint/naming-convention */

import expect from '@kbn/expect';

import { CASES_URL } from '../../../../../../plugins/cases/common/constants';
import {
ConnectorTypes,
ConnectorJiraTypeFields,
CaseStatuses,
CaseUserActionResponse,
} from '../../../../../../plugins/cases/common/api';
import { getPostCaseRequest, postCaseResp, defaultUser } from '../../../../common/lib/mock';
import {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CaseConnector,
CaseResponse,
CaseStatuses,
CaseUserActionResponse,
ConnectorTypes,
} from '../../../../../../plugins/cases/common/api';

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6db02cd

Please sign in to comment.