Skip to content

Commit

Permalink
Use the enums
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 20, 2020
1 parent 49582f0 commit dbaba7e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 27 deletions.
Expand Up @@ -210,7 +210,7 @@ describe('PATCH comment', () => {
case_id: 'mock-id-1',
},
body: {
type: 'alert',
type: CommentType.alert,
alertId: 'test-id',
index: 'test-index',
id: 'mock-comment-1',
Expand Down
Expand Up @@ -348,7 +348,7 @@ describe('Case Configuration API', () => {
method: 'PATCH',
body: JSON.stringify({
comment: 'updated comment',
type: 'user',
type: CommentType.user,
id: basicCase.comments[0].id,
version: basicCase.comments[0].version,
}),
Expand Down
Expand Up @@ -18,6 +18,7 @@ import {
ServiceConnectorCaseParams,
ServiceConnectorCaseResponse,
ActionTypeExecutorResult,
CommentType,
} from '../../../../case/common/api';

import {
Expand Down Expand Up @@ -205,7 +206,12 @@ export const patchComment = async (
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(getCaseCommentsUrl(caseId), {
method: 'PATCH',
body: JSON.stringify({ comment: commentUpdate, type: 'user', id: commentId, version }),
body: JSON.stringify({
comment: commentUpdate,
type: CommentType.user,
id: commentId,
version,
}),
signal,
});
return convertToCamelCase<CaseResponse, Case>(decodeCaseResponse(response));
Expand Down
Expand Up @@ -8,6 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import { CASES_URL } from '../../../../../../plugins/case/common/constants';
import { CommentType } from '../../../../../../plugins/case/common/api';
import { postCaseReq, postCommentUserReq } from '../../../../common/lib/mock';
import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils';

Expand Down Expand Up @@ -69,7 +70,7 @@ export default ({ getService }: FtrProviderContext): void => {
const { body: patchedCase } = await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send({ comment: 'unique', type: 'user' })
.send({ comment: 'unique', type: CommentType.user })
.expect(200);

const { body: caseComments } = await supertest
Expand Down
Expand Up @@ -9,6 +9,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import { CASES_URL } from '../../../../../../plugins/case/common/constants';
import { CommentType } from '../../../../../../plugins/case/common/api';
import {
defaultUser,
postCaseReq,
Expand Down Expand Up @@ -50,7 +51,7 @@ export default ({ getService }: FtrProviderContext): void => {
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
comment: newComment,
type: 'user',
type: CommentType.user,
})
.expect(200);

Expand Down Expand Up @@ -78,7 +79,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
type: 'alert',
type: CommentType.alert,
alertId: 'new-id',
index: postCommentAlertReq.index,
})
Expand All @@ -103,7 +104,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: 'id',
version: 'version',
type: 'user',
type: CommentType.user,
comment: 'comment',
})
.expect(404);
Expand All @@ -116,7 +117,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: 'id',
version: 'version',
type: 'user',
type: CommentType.user,
comment: 'comment',
})
.expect(404);
Expand All @@ -141,7 +142,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
type: 'alert',
type: CommentType.alert,
alertId: 'test-id',
index: 'test-index',
})
Expand Down Expand Up @@ -192,7 +193,7 @@ export default ({ getService }: FtrProviderContext): void => {
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
comment: 'a comment',
type: 'user',
type: CommentType.user,
[attribute]: attribute,
})
.expect(400);
Expand All @@ -213,7 +214,7 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const allRequestAttributes = {
type: 'alert',
type: CommentType.alert,
index: 'test-index',
alertId: 'test-id',
};
Expand Down Expand Up @@ -252,7 +253,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
type: 'alert',
type: CommentType.alert,
index: 'test-index',
alertId: 'test-id',
[attribute]: attribute,
Expand Down Expand Up @@ -281,7 +282,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send({
id: patchedCase.comments[0].id,
version: 'version-mismatch',
type: 'user',
type: CommentType.user,
comment: newComment,
})
.expect(409);
Expand Down
Expand Up @@ -9,6 +9,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import { CASES_URL } from '../../../../../../plugins/case/common/constants';
import { CommentType } from '../../../../../../plugins/case/common/api';
import {
defaultUser,
postCaseReq,
Expand Down Expand Up @@ -92,7 +93,7 @@ export default ({ getService }: FtrProviderContext): void => {
await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send({ type: 'user' })
.send({ type: CommentType.user })
.expect(400);
});

Expand All @@ -107,7 +108,7 @@ export default ({ getService }: FtrProviderContext): void => {
await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send({ type: 'user', [attribute]: attribute, comment: 'a comment' })
.send({ type: CommentType.user, [attribute]: attribute, comment: 'a comment' })
.expect(400);
}
});
Expand All @@ -120,7 +121,7 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const allRequestAttributes = {
type: 'alert',
type: CommentType.alert,
index: 'test-index',
alertId: 'test-id',
};
Expand All @@ -146,7 +147,12 @@ export default ({ getService }: FtrProviderContext): void => {
await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send({ type: 'alert', [attribute]: attribute, alertId: 'test-id', index: 'test-index' })
.send({
type: CommentType.alert,
[attribute]: attribute,
alertId: 'test-id',
index: 'test-index',
})
.expect(400);
}
});
Expand Down
Expand Up @@ -8,6 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import { CASE_CONFIGURE_URL, CASES_URL } from '../../../../../../plugins/case/common/constants';
import { CommentType } from '../../../../../../plugins/case/common/api';
import { defaultUser, postCaseReq, postCommentUserReq } from '../../../../common/lib/mock';
import {
deleteCases,
Expand Down Expand Up @@ -285,7 +286,7 @@ export default ({ getService }: FtrProviderContext): void => {
id: patchedCase.comments[0].id,
version: patchedCase.comments[0].version,
comment: newComment,
type: 'user',
type: CommentType.user,
});

const { body } = await supertest
Expand All @@ -301,7 +302,7 @@ export default ({ getService }: FtrProviderContext): void => {
expect(body[2].new_value).to.eql(
JSON.stringify({
comment: newComment,
type: 'user',
type: CommentType.user,
})
);
});
Expand Down
13 changes: 7 additions & 6 deletions x-pack/test/case_api_integration/basic/tests/connectors/case.ts
Expand Up @@ -9,6 +9,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

import { CASES_URL } from '../../../../../plugins/case/common/constants';
import { CommentType } from '../../../../../plugins/case/common/api';
import {
postCaseReq,
postCaseResp,
Expand Down Expand Up @@ -619,7 +620,7 @@ export default ({ getService }: FtrProviderContext): void => {
const params = {
subAction: 'addComment',
subActionParams: {
comment: { comment: 'a comment', type: 'user' },
comment: { comment: 'a comment', type: CommentType.user },
},
};

Expand Down Expand Up @@ -684,7 +685,7 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

createdActionId = createdAction.id;
const comment = { alertId: 'test-id', index: 'test-index', type: 'alert' };
const comment = { alertId: 'test-id', index: 'test-index', type: CommentType.alert };
const params = {
subAction: 'addComment',
subActionParams: {
Expand Down Expand Up @@ -731,7 +732,7 @@ export default ({ getService }: FtrProviderContext): void => {
subAction: 'addComment',
subActionParams: {
caseId: '123',
comment: { comment: 'a comment', type: 'user' },
comment: { comment: 'a comment', type: CommentType.user },
},
};

Expand Down Expand Up @@ -775,7 +776,7 @@ export default ({ getService }: FtrProviderContext): void => {
subAction: 'addComment',
subActionParams: {
caseId: '123',
comment: { alertId: 'test-id', index: 'test-index', type: 'alert' },
comment: { alertId: 'test-id', index: 'test-index', type: CommentType.alert },
},
};

Expand Down Expand Up @@ -861,7 +862,7 @@ export default ({ getService }: FtrProviderContext): void => {
subAction: 'addComment',
subActionParams: {
caseId: caseRes.body.id,
comment: { comment: 'a comment', type: 'user' },
comment: { comment: 'a comment', type: CommentType.user },
},
};

Expand Down Expand Up @@ -914,7 +915,7 @@ export default ({ getService }: FtrProviderContext): void => {
subAction: 'addComment',
subActionParams: {
caseId: caseRes.body.id,
comment: { alertId: 'test-id', index: 'test-index', type: 'alert' },
comment: { alertId: 'test-id', index: 'test-index', type: CommentType.alert },
},
};

Expand Down
5 changes: 3 additions & 2 deletions x-pack/test/case_api_integration/common/lib/mock.ts
Expand Up @@ -12,6 +12,7 @@ import {
ConnectorTypes,
CommentRequestUserType,
CommentRequestAlertType,
CommentType,
} from '../../../../plugins/case/common/api';
export const defaultUser = { email: null, full_name: null, username: 'elastic' };
export const postCaseReq: CasePostRequest = {
Expand All @@ -28,13 +29,13 @@ export const postCaseReq: CasePostRequest = {

export const postCommentUserReq: CommentRequestUserType = {
comment: 'This is a cool comment',
type: 'user',
type: CommentType.user,
};

export const postCommentAlertReq: CommentRequestAlertType = {
alertId: 'test-id',
index: 'test-index',
type: 'alert',
type: CommentType.alert,
};

export const postCaseResp = (
Expand Down

0 comments on commit dbaba7e

Please sign in to comment.