Skip to content

Commit

Permalink
Improve integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jun 9, 2021
1 parent 9eaa654 commit 7746cd9
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export const FIELD_MAPPING_DESC = (thirdPartyName: string): string => {
export const FIELD_MAPPING_DESC_ERR = (thirdPartyName: string): string => {
return i18n.translate('xpack.cases.configureCases.fieldMappingDescErr', {
values: { thirdPartyName },
defaultMessage:
'Field mappings require an established connection to { thirdPartyName }. Please check your connection credentials.',
defaultMessage: 'Failed to retrieve mappings for { thirdPartyName }.',
});
};
export const EDIT_FIELD_MAPPING_TITLE = (thirdPartyName: string): string => {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ async function update(
} catch (e) {
error = e.isBoom
? e.output.payload.message
: `Error connecting to ${
: `Error creating mapping for ${
connector != null ? connector.name : configuration.attributes.connector.name
} instance`;
}`;
}

const patch = await caseConfigureService.patch({
Expand Down Expand Up @@ -413,7 +413,7 @@ async function create(
} catch (e) {
error = e.isBoom
? e.output.payload.message
: `Error connecting to ${configuration.connector.name} instance`;
: `Error creating mapping for ${configuration.connector.name}`;
}

const post = await caseConfigureService.post({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
import { ConnectorTypes } from '../../../../../../plugins/cases/common/api';

import {
getConfigurationRequest,
removeServerGeneratedPropertiesFromSavedObject,
getConfigurationOutput,
deleteConfiguration,
createConfiguration,
updateConfiguration,
getConfigurationRequest,
getConfiguration,
} from '../../../../common/lib/utils';
import {
secOnly,
Expand Down Expand Up @@ -52,6 +54,39 @@ export default ({ getService }: FtrProviderContext): void => {
expect(data).to.eql({ ...getConfigurationOutput(true), closure_type: 'close-by-pushing' });
});

it('should update mapping when changing connector', async () => {
const configuration = await createConfiguration(supertest);
await updateConfiguration(supertest, configuration.id, {
connector: {
id: 'serviceNowITSM',
name: 'ServiceNow ITSM',
type: ConnectorTypes.serviceNowITSM,
fields: null,
},
version: configuration.version,
});
const newConfiguration = await getConfiguration({ supertest });

expect(configuration.mappings).to.eql([]);
expect(newConfiguration[0].mappings).to.eql([
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
]);
});

it('should not patch a configuration with unsupported connector type', async () => {
const configuration = await createConfiguration(supertest);
await updateConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,135 @@ export default ({ getService }: FtrProviderContext): void => {
expect(configuration.length).to.be(1);
});

it('should return an error when failing to get mapping', async () => {
it('should return an empty mapping when they type is none', async () => {
const postRes = await createConfiguration(
supertest,
getConfigurationRequest({
id: 'not-exists',
name: 'not-exists',
type: ConnectorTypes.jira,
type: ConnectorTypes.none,
})
);

expect(postRes.error).to.not.be(null);
expect(postRes.mappings).to.eql([]);
});

it('should return the correct mapping for Jira', async () => {
const postRes = await createConfiguration(
supertest,
getConfigurationRequest({
id: 'jira',
name: 'Jira',
type: ConnectorTypes.jira,
})
);

expect(postRes.mappings).to.eql([
{
action_type: 'overwrite',
source: 'title',
target: 'summary',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'comments',
},
]);
});

it('should return the correct mapping for IBM Resilient', async () => {
const postRes = await createConfiguration(
supertest,
getConfigurationRequest({
id: 'resilient',
name: 'Resilient',
type: ConnectorTypes.resilient,
})
);

expect(postRes.mappings).to.eql([
{
action_type: 'overwrite',
source: 'title',
target: 'name',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'comments',
},
]);
});

it('should return the correct mapping for ServiceNow ITSM', async () => {
const postRes = await createConfiguration(
supertest,
getConfigurationRequest({
id: 'serviceNowITSM',
name: 'ServiceNow ITSM',
type: ConnectorTypes.serviceNowITSM,
})
);

expect(postRes.mappings).to.eql([
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
]);
});

it('should return the correct mapping for ServiceNow SecOps', async () => {
const postRes = await createConfiguration(
supertest,
getConfigurationRequest({
id: 'serviceNowSIR',
name: 'ServiceNow SecOps',
type: ConnectorTypes.serviceNowSIR,
})
);

expect(postRes.mappings).to.eql([
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
]);
});

it('should not create a configuration when missing connector.id', async () => {
await createConfiguration(
supertest,
Expand Down

0 comments on commit 7746cd9

Please sign in to comment.