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 21, 2020
1 parent c7c9ea8 commit 44d7c36
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function initPatchCaseConfigure({ caseConfigureService, caseService, rout

if (version !== myCaseConfigure.saved_objects[0].version) {
throw Boom.conflict(
'This configuration has been updated. Please refresh before saving additional updates.'
'This configuration has been updated. Please refresh before saving additional updates'
);
}

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,80 @@
/*
* 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 @@ -11,8 +11,9 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
describe('case api security and spaces enabled', function() {
this.tags('ciGroup1');

loadTestFile(require.resolve('./configure/get_configure'));
loadTestFile(require.resolve('./configure/post_configure'));
loadTestFile(require.resolve('./configure/get_connectors'));
// 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 44d7c36

Please sign in to comment.