Skip to content

Commit

Permalink
Test patch_configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 23, 2020
1 parent edbd8e4 commit 30e8e4f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function initPatchCaseConfigure({ caseConfigureService, caseService, rout

if (myCaseConfigure.saved_objects.length === 0) {
throw Boom.conflict(
'You can not patch this configuration since you did not created first with a post'
'You can not patch this configuration since you did not created first with a post.'
);
}

Expand Down
4 changes: 2 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 @@ -14,11 +14,11 @@ export const getConfiguration = (connector_id: string = 'connector-1'): CasesCon
};
};

export const getConfigurationOutput = (): Partial<CasesConfigureResponse> => {
export const getConfigurationOutput = (update = false): Partial<CasesConfigureResponse> => {
return {
...getConfiguration(),
created_by: { email: null, full_name: null, username: 'elastic' },
updated_by: null,
updated_by: update ? { email: null, full_name: null, username: 'elastic' } : null,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export default ({ getService }: FtrProviderContext): void => {
const es = getService('legacyEs');

describe('get_configure', () => {
beforeEach(async () => {
await deleteConfiguration(es);
});

after(async () => {
afterEach(async () => {
await deleteConfiguration(es);
});

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

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

import { CASE_CONFIGURE_URL } from '../../../../../plugins/case/common/constants';
import {
getConfiguration,
removeServerGeneratedPropertiesFromConfigure,
getConfigurationOutput,
deleteConfiguration,
} from '../../../common/lib/utils';

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

describe('post_configure', () => {
afterEach(async () => {
await deleteConfiguration(es);
});

it('should patch a configuration', async () => {
const res = await supertest
.post(CASE_CONFIGURE_URL)
.set('kbn-xsrf', 'true')
.send(getConfiguration())
.expect(200);

const { body } = await supertest
.patch(CASE_CONFIGURE_URL)
.set('kbn-xsrf', 'true')
.send({ closure_type: 'close-by-pushing', version: res.body.version })
.expect(200);

const data = removeServerGeneratedPropertiesFromConfigure(body);
expect(data).to.eql({ ...getConfigurationOutput(true), closure_type: 'close-by-pushing' });
});

it('should handle patch request when there is no configuration', async () => {
const { body } = await supertest
.patch(CASE_CONFIGURE_URL)
.set('kbn-xsrf', 'true')
.send({ closure_type: 'close-by-pushing', version: 'no-version' })
.expect(409);

expect(body).to.eql({
error: 'Conflict',
message:
'You can not patch this configuration since you did not created first with a post.',
statusCode: 409,
});
});

it('should handle patch request when versions are different', async () => {
await supertest
.post(CASE_CONFIGURE_URL)
.set('kbn-xsrf', 'true')
.send(getConfiguration())
.expect(200);

const { body } = await supertest
.patch(CASE_CONFIGURE_URL)
.set('kbn-xsrf', 'true')
.send({ closure_type: 'close-by-pushing', version: 'no-version' })
.expect(409);

expect(body).to.eql({
error: 'Conflict',
message:
'This configuration has been updated. Please refresh before saving additional updates.',
statusCode: 409,
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export default ({ getService }: FtrProviderContext): void => {
const es = getService('legacyEs');

describe('post_configure', () => {
beforeEach(async () => {
await deleteConfiguration(es);
});

after(async () => {
afterEach(async () => {
await deleteConfiguration(es);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default ({ loadTestFile }: FtrProviderContext): void => {

loadTestFile(require.resolve('./configure/get_configure'));
loadTestFile(require.resolve('./configure/post_configure'));
loadTestFile(require.resolve('./configure/patch_configure'));
loadTestFile(require.resolve('./configure/get_connectors'));
});
};

0 comments on commit 30e8e4f

Please sign in to comment.