Skip to content

Commit

Permalink
Improve integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 19, 2022
1 parent cad32ca commit f117f09
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 142 deletions.
13 changes: 13 additions & 0 deletions x-pack/test/cases_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ export const getWebhookConnector = () => ({
},
});

export const getEmailConnector = () => ({
name: 'An email action',
connector_type_id: '.email',
config: {
service: '__json',
from: '[email protected]',
},
secrets: {
user: 'bob',
password: 'supersecret',
},
});

interface CommonSavedObjectAttributes {
id?: string | null;
created_at?: string | null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import { getCaseConnectors } from '../../../../common/lib/utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');

describe('get_connectors', () => {
/**
* A ServiceNow preconfigured connector is registered here
* x-pack/test/cases_api_integration/common/config.ts
*
* The license for this test is set to basic. ServiceNow connectors
* needs license >= platinum. The test below ensures
* that connectors without valid license are being filtered correctly
*/
it('should return an empty list of connectors', async () => {
const connectors = await getCaseConnectors({ supertest });

expect(connectors).to.eql([]);
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default ({ loadTestFile, getService }: FtrProviderContext): void => {

// Basic
loadTestFile(require.resolve('./cases/push_case'));
loadTestFile(require.resolve('./configure/get_connectors'));

// Common
loadTestFile(require.resolve('../common'));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./cases/tags/get_tags'));
loadTestFile(require.resolve('./user_actions/get_all_user_actions'));
loadTestFile(require.resolve('./configure/get_configure'));
loadTestFile(require.resolve('./configure/get_connectors'));
loadTestFile(require.resolve('./configure/patch_configure'));
loadTestFile(require.resolve('./configure/post_configure'));
loadTestFile(require.resolve('./metrics/get_case_metrics'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import expect from '@kbn/expect';
import { CASE_CONFIGURE_CONNECTORS_URL } from '@kbn/cases-plugin/common/constants';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
Expand All @@ -16,6 +15,8 @@ import {
getResilientConnector,
createConnector,
getServiceNowSIRConnector,
getEmailConnector,
getCaseConnectors,
} from '../../../../common/lib/utils';

// eslint-disable-next-line import/no-default-export
Expand All @@ -29,41 +30,10 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should return the correct connectors', async () => {
const { body: snConnector } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'true')
.send(getServiceNowConnector())
.expect(200);

const { body: emailConnector } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'true')
.send({
name: 'An email action',
connector_type_id: '.email',
config: {
service: '__json',
from: '[email protected]',
},
secrets: {
user: 'bob',
password: 'supersecret',
},
})
.expect(200);

const { body: jiraConnector } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'true')
.send(getJiraConnector())
.expect(200);

const { body: resilientConnector } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'true')
.send(getResilientConnector())
.expect(200);

const snConnector = await createConnector({ supertest, req: getServiceNowConnector() });
const emailConnector = await createConnector({ supertest, req: getEmailConnector() });
const jiraConnector = await createConnector({ supertest, req: getJiraConnector() });
const resilientConnector = await createConnector({ supertest, req: getResilientConnector() });
const sir = await createConnector({ supertest, req: getServiceNowSIRConnector() });

actionsRemover.add('default', sir.id, 'action', 'actions');
Expand All @@ -72,11 +42,7 @@ export default ({ getService }: FtrProviderContext): void => {
actionsRemover.add('default', jiraConnector.id, 'action', 'actions');
actionsRemover.add('default', resilientConnector.id, 'action', 'actions');

const { body: connectors } = await supertest
.get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
const connectors = await getCaseConnectors({ supertest });

expect(connectors).to.eql([
{
Expand All @@ -91,6 +57,17 @@ export default ({ getService }: FtrProviderContext): void => {
isMissingSecrets: false,
referencedByCount: 0,
},
/**
* Preconfigured connectors are being registered here:
* x-pack/test/cases_api_integration/common/config.ts
*/
{
actionTypeId: '.servicenow',
id: 'preconfigured-servicenow',
isPreconfigured: true,
name: 'preconfigured-servicenow',
referencedByCount: 0,
},
{
id: resilientConnector.id,
actionTypeId: '.resilient',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getAuthWithSuperUser,
getCaseConnectors,
getActionsSpace,
getEmailConnector,
} from '../../../../common/lib/utils';

// eslint-disable-next-line import/no-default-export
Expand All @@ -38,32 +39,25 @@ export default ({ getService }: FtrProviderContext): void => {
req: getServiceNowConnector(),
auth: authSpace1,
});

const emailConnector = await createConnector({
supertest,
req: {
name: 'An email action',
connector_type_id: '.email',
config: {
service: '__json',
from: '[email protected]',
},
secrets: {
user: 'bob',
password: 'supersecret',
},
},
req: getEmailConnector(),
auth: authSpace1,
});

const jiraConnector = await createConnector({
supertest,
req: getJiraConnector(),
auth: authSpace1,
});

const resilientConnector = await createConnector({
supertest,
req: getResilientConnector(),
auth: authSpace1,
});

const sir = await createConnector({
supertest,
req: getServiceNowSIRConnector(),
Expand Down Expand Up @@ -91,6 +85,17 @@ export default ({ getService }: FtrProviderContext): void => {
isMissingSecrets: false,
referencedByCount: 0,
},
/**
* Preconfigured connectors are being registered here:
* x-pack/test/cases_api_integration/common/config.ts
*/
{
actionTypeId: '.servicenow',
id: 'preconfigured-servicenow',
isPreconfigured: true,
name: 'preconfigured-servicenow',
referencedByCount: 0,
},
{
id: resilientConnector.id,
actionTypeId: '.resilient',
Expand Down Expand Up @@ -136,32 +141,25 @@ export default ({ getService }: FtrProviderContext): void => {
req: getServiceNowConnector(),
auth: authSpace1,
});

const emailConnector = await createConnector({
supertest,
req: {
name: 'An email action',
connector_type_id: '.email',
config: {
service: '__json',
from: '[email protected]',
},
secrets: {
user: 'bob',
password: 'supersecret',
},
},
req: getEmailConnector(),
auth: authSpace1,
});

const jiraConnector = await createConnector({
supertest,
req: getJiraConnector(),
auth: authSpace1,
});

const resilientConnector = await createConnector({
supertest,
req: getResilientConnector(),
auth: authSpace1,
});

const sir = await createConnector({
supertest,
req: getServiceNowSIRConnector(),
Expand All @@ -179,7 +177,19 @@ export default ({ getService }: FtrProviderContext): void => {
auth: getAuthWithSuperUser('space2'),
});

expect(connectors).to.eql([]);
expect(connectors).to.eql([
/**
* Preconfigured connectors are being registered here:
* x-pack/test/cases_api_integration/common/config.ts
*/
{
actionTypeId: '.servicenow',
id: 'preconfigured-servicenow',
isPreconfigured: true,
name: 'preconfigured-servicenow',
referencedByCount: 0,
},
]);
});
});
};

0 comments on commit f117f09

Please sign in to comment.