Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Jul 5, 2023
1 parent f87deb5 commit c719484
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
18 changes: 18 additions & 0 deletions x-pack/plugins/cases/common/api/cases/comment/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
BulkGetAttachmentsRequestRt,
BulkGetAttachmentsResponseRt,
} from '.';
import { MAX_COMMENT_LENGTH } from '../../../constants';

describe('Comments', () => {
describe('CommentAttributesBasicRt', () => {
Expand Down Expand Up @@ -340,6 +341,23 @@ describe('Comments', () => {
right: defaultRequest,
});
});

it.skip('throws error when comment is too long', () => {
const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1);

expect(CommentRequestRt.decode({ ...defaultRequest, comment: longComment })).toMatchObject({
_tag: 'Left',
left: [{
context:[{
actual: {
...defaultRequest,
comment: longComment,
message: "The length of the comment is too long. The maximum length is 30000."
}
}]
}]
});
});
});

describe('CommentRt', () => {
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/cases/server/client/attachments/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ describe('addComment', () => {
});

it('should throw an error if the comment length is too long', async () => {
const longComment = Array(MAX_COMMENT_LENGTH + 1)
.fill('x')
.toString();
const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1);

await expect(
addComment({ comment: { ...comment, comment: longComment }, caseId: 'test-case' }, clientArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ export default ({ getService }: FtrProviderContext): void => {
});
});

it('400s when comment is too long', async () => {
const longComment = 'x'.repeat(30001);

await bulkCreateAttachments({
supertest,
caseId: 'case-id',
params: [
{
type: CommentType.user,
comment: longComment,
owner: 'securitySolutionFixture',
},
],
expectedHttpCode: 400,
});
});

it('400s when adding excess attributes for type user', async () => {
const postedCase = await createCase(supertest, postCaseReq);

Expand Down

0 comments on commit c719484

Please sign in to comment.