-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM] [Cases] Case API tests (#65777)
- Loading branch information
1 parent
56c46ae
commit 2082648
Showing
18 changed files
with
1,580 additions
and
33 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
x-pack/test/case_api_integration/basic/tests/cases/comments/delete_comment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('delete_comment', () => { | ||
afterEach(async () => { | ||
await deleteCases(es); | ||
await deleteComments(es); | ||
await deleteCasesUserActions(es); | ||
}); | ||
|
||
it('should delete a comment', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body: comment } = await supertest | ||
.delete(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`) | ||
.set('kbn-xsrf', 'true') | ||
.send(); | ||
|
||
expect(comment).to.eql({}); | ||
}); | ||
|
||
it('unhappy path - 404s when comment belongs to different case', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body } = await supertest | ||
.delete(`${CASES_URL}/fake-id/comments/${patchedCase.comments[0].id}`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(404); | ||
expect(body.message).to.eql( | ||
`This comment ${patchedCase.comments[0].id} does not exist in fake-id).` | ||
); | ||
}); | ||
|
||
it('unhappy path - 404s when comment is not there', async () => { | ||
await supertest | ||
.delete(`${CASES_URL}/fake-id/comments/fake-id`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(404); | ||
}); | ||
}); | ||
}; |
93 changes: 93 additions & 0 deletions
93
x-pack/test/case_api_integration/basic/tests/cases/comments/find_comments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('find_comments', () => { | ||
afterEach(async () => { | ||
await deleteCases(es); | ||
await deleteComments(es); | ||
await deleteCasesUserActions(es); | ||
}); | ||
|
||
it('should find all case comment', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
// post 2 comments | ||
await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body: caseComments } = await supertest | ||
.get(`${CASES_URL}/${postedCase.id}/comments/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send(); | ||
|
||
expect(caseComments.comments).to.eql(patchedCase.comments); | ||
}); | ||
|
||
it('should filter case comments', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
// post 2 comments | ||
await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ comment: 'unique' }); | ||
|
||
const { body: caseComments } = await supertest | ||
.get(`${CASES_URL}/${postedCase.id}/comments/_find?search=unique`) | ||
.set('kbn-xsrf', 'true') | ||
.send(); | ||
|
||
expect(caseComments.comments).to.eql([patchedCase.comments[1]]); | ||
}); | ||
|
||
it('unhappy path - 400s when query is bad', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
await supertest | ||
.get(`${CASES_URL}/${postedCase.id}/comments/_find?perPage=true`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(400); | ||
}); | ||
}); | ||
}; |
53 changes: 53 additions & 0 deletions
53
x-pack/test/case_api_integration/basic/tests/cases/comments/get_comment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('get_comment', () => { | ||
afterEach(async () => { | ||
await deleteCases(es); | ||
await deleteComments(es); | ||
await deleteCasesUserActions(es); | ||
}); | ||
|
||
it('should get a comment', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
|
||
const { body: comment } = await supertest | ||
.get(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(comment).to.eql(patchedCase.comments[0]); | ||
}); | ||
it('unhappy path - 404s when comment is not there', async () => { | ||
await supertest | ||
.get(`${CASES_URL}/fake-id/comments/fake-comment`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(404); | ||
}); | ||
}); | ||
}; |
123 changes: 123 additions & 0 deletions
123
x-pack/test/case_api_integration/basic/tests/cases/comments/patch_comment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* 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 { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
import { defaultUser, postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('patch_comment', () => { | ||
afterEach(async () => { | ||
await deleteCases(es); | ||
await deleteComments(es); | ||
await deleteCasesUserActions(es); | ||
}); | ||
|
||
it('should patch a comment', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
const newComment = 'Well I decided to update my comment. So what? Deal with it.'; | ||
const { body } = await supertest | ||
.patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ | ||
id: patchedCase.comments[0].id, | ||
version: patchedCase.comments[0].version, | ||
comment: newComment, | ||
}); | ||
expect(body.comments[0].comment).to.eql(newComment); | ||
expect(body.updated_by).to.eql(defaultUser); | ||
}); | ||
|
||
it('unhappy path - 404s when comment is not there', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq); | ||
await supertest | ||
.patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ | ||
id: 'id', | ||
version: 'version', | ||
comment: 'comment', | ||
}) | ||
.expect(404); | ||
}); | ||
|
||
it('unhappy path - 404s when case is not there', async () => { | ||
await supertest | ||
.patch(`${CASES_URL}/fake-id/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ | ||
id: 'id', | ||
version: 'version', | ||
comment: 'comment', | ||
}) | ||
.expect(404); | ||
}); | ||
|
||
it('unhappy path - 400s when patch body is bad', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
await supertest | ||
.patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ | ||
id: patchedCase.comments[0].id, | ||
version: patchedCase.comments[0].version, | ||
comment: true, | ||
}) | ||
.expect(400); | ||
}); | ||
|
||
it('unhappy path - 409s when conflict', async () => { | ||
const { body: postedCase } = await supertest | ||
.post(CASES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCaseReq) | ||
.expect(200); | ||
|
||
const { body: patchedCase } = await supertest | ||
.post(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send(postCommentReq); | ||
const newComment = 'Well I decided to update my comment. So what? Deal with it.'; | ||
await supertest | ||
.patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
.set('kbn-xsrf', 'true') | ||
.send({ | ||
id: patchedCase.comments[0].id, | ||
version: 'version-mismatch', | ||
comment: newComment, | ||
}) | ||
.expect(409); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.