Skip to content

Commit

Permalink
Convert get comment test
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 12, 2021
1 parent bd34566 commit 3b8ca25
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 121 deletions.

This file was deleted.

30 changes: 30 additions & 0 deletions x-pack/test/case_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
SubCaseResponse,
CommentResponse,
CasesPatchRequest,
AllCommentsResponse,
} from '../../../../plugins/cases/common/api';
import { getPostCaseRequest, postCollectionReq, postCommentGenAlertReq } from './mock';
import { getSubCasesUrl } from '../../../../plugins/cases/common/api/helpers';
Expand Down Expand Up @@ -615,3 +616,32 @@ export const deleteComment = async (

return comment;
};

export const getAllComments = async (
supertest: st.SuperTest<supertestAsPromised.Test>,
caseId: string,
expectedHttpCode: number = 204
): Promise<AllCommentsResponse> => {
const { body: comments } = await supertest
.get(`${CASES_URL}/${caseId}/comments`)
.set('kbn-xsrf', 'true')
.send()
.expect(expectedHttpCode);

return comments;
};

export const getComment = async (
supertest: st.SuperTest<supertestAsPromised.Test>,
caseId: string,
commentId: string,
expectedHttpCode: number = 204
): Promise<CommentResponse> => {
const { body: comment } = await supertest
.get(`${CASES_URL}/${caseId}/comments/${commentId}`)
.set('kbn-xsrf', 'true')
.send()
.expect(expectedHttpCode);

return comment;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
createSubCase,
deleteAllCaseItems,
deleteCaseAction,
createCase,
createComment,
getAllComments,
} from '../../../../common/lib/utils';
import { CommentType } from '../../../../../../plugins/cases/common/api';

Expand All @@ -29,29 +32,10 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should get multiple comments for a single case', 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(postCommentUserReq)
.expect(200);

await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send(postCommentUserReq)
.expect(200);

const { body: comments } = await supertest
.get(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
const postedCase = await createCase(supertest, postCaseReq);
await createComment(supertest, postedCase.id, postCommentUserReq);
await createComment(supertest, postedCase.id, postCommentUserReq);
const comments = await getAllComments(supertest, postedCase.id);

expect(comments.length).to.eql(2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import {
createSubCase,
deleteAllCaseItems,
deleteCaseAction,
createCase,
createComment,
getComment,
} from '../../../../common/lib/utils';
import { CommentResponse, CommentType } from '../../../../../../plugins/cases/common/api';
import { CommentType } from '../../../../../../plugins/cases/common/api';

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

it('should get a comment', async () => {
const { body: postedCase } = await supertest
.post(CASES_URL)
.set('kbn-xsrf', 'true')
.send(postCaseReq)
.expect(200);
const postedCase = await createCase(supertest, postCaseReq);
const patchedCase = await createComment(supertest, postedCase.id, postCommentUserReq);
const comment = await getComment(supertest, postedCase.id, patchedCase.comments![0].id);

const { body: patchedCase } = await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.set('kbn-xsrf', 'true')
.send(postCommentUserReq)
.expect(200);

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]);
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);
await getComment(supertest, 'fake-id', 'fake-id', 404);
});

// ENABLE_CASE_CONNECTOR: once the case connector feature is completed unskip these tests
Expand All @@ -69,9 +54,7 @@ export default ({ getService }: FtrProviderContext): void => {
});
it('should get a sub case comment', async () => {
const { newSubCaseInfo: caseInfo } = await createSubCase({ supertest, actionID });
const { body: comment }: { body: CommentResponse } = await supertest
.get(`${CASES_URL}/${caseInfo.id}/comments/${caseInfo.comments![0].id}`)
.expect(200);
const comment = await getComment(supertest, caseInfo.id, caseInfo.comments![0].id);
expect(comment.type).to.be(CommentType.generatedAlert);
});
});
Expand Down

0 comments on commit 3b8ca25

Please sign in to comment.