Skip to content

Commit

Permalink
PR comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Jun 29, 2023
1 parent be13b94 commit c865f86
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 16 deletions.
53 changes: 48 additions & 5 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ const CaseBasicRt = rt.strict({
/**
* The description of the case
*/
description: limitedStringSchema('description', 1, MAX_DESCRIPTION_LENGTH),
description: rt.string,
/**
* The current status of the case (open, closed, in-progress)
*/
status: CaseStatusRt,
/**
* The identifying strings for filter a case
*/
tags: limitedArraySchema(limitedStringSchema('tag', 1, MAX_TAG_LENGTH), 0, MAX_TAGS, 'tags'),
tags: rt.array(rt.string),
/**
* The title of a case
*/
title: limitedStringSchema('title', 1, MAX_TITLE_LENGTH),
title: rt.string,
/**
* The external system that the case can be synced with
*/
Expand All @@ -96,7 +96,7 @@ const CaseBasicRt = rt.strict({
/**
* The category of the case.
*/
category: rt.union([limitedStringSchema('category', 1, MAX_CATEGORY_LENGTH), rt.null]),
category: rt.union([rt.string, rt.null]),
});

/**
Expand Down Expand Up @@ -343,7 +343,50 @@ export const CasesFindResponseRt = rt.intersection([
]);

export const CasePatchRequestRt = rt.intersection([
rt.exact(rt.partial(CaseBasicRt.type.props)),
rt.exact(
rt.partial({
/**
* The description of the case
*/
description: limitedStringSchema('description', 1, MAX_DESCRIPTION_LENGTH),
/**
* The current status of the case (open, closed, in-progress)
*/
status: CaseStatusRt,
/**
* The identifying strings for filter a case
*/
tags: limitedArraySchema(limitedStringSchema('tag', 1, MAX_TAG_LENGTH), 0, MAX_TAGS, 'tags'),
/**
* The title of a case
*/
title: limitedStringSchema('title', 1, MAX_TITLE_LENGTH),
/**
* The external system that the case can be synced with
*/
connector: CaseConnectorRt,
/**
* The alert sync settings
*/
settings: SettingsRt,
/**
* The plugin owner of the case
*/
owner: rt.string,
/**
* The severity of the case
*/
severity: CaseSeverityRt,
/**
* The users assigned to this case
*/
assignees: CaseAssigneesRt,
/**
* The category of the case.
*/
category: rt.union([limitedStringSchema('category', 1, MAX_CATEGORY_LENGTH), rt.null]),
})
),
/**
* The saved object ID and version
*/
Expand Down
22 changes: 11 additions & 11 deletions x-pack/plugins/cases/server/client/cases/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ describe('update', () => {
).resolves.not.toThrow();
});

it('does not update the title if the length is too long', async () => {
it('throws error if the title is too long', async () => {
await expect(
update(
{
Expand All @@ -427,7 +427,7 @@ describe('update', () => {
);
});

it('does not update the title if it is just an empty string', async () => {
it('throws error if title is just an empty string', async () => {
await expect(
update(
{
Expand All @@ -446,7 +446,7 @@ describe('update', () => {
);
});

it('does not update the title if it is a string with empty characters', async () => {
it('throws error if title is a string with empty characters', async () => {
await expect(
update(
{
Expand Down Expand Up @@ -501,7 +501,7 @@ describe('update', () => {
).resolves.not.toThrow();
});

it('does not update the description if the length is too long', async () => {
it('throws error when the description is too long', async () => {
const description = Array(MAX_DESCRIPTION_LENGTH + 1)
.fill('a')
.toString();
Expand All @@ -524,7 +524,7 @@ describe('update', () => {
);
});

it('does not update the description if it is just an empty string', async () => {
it('throws error if description is just an empty string', async () => {
await expect(
update(
{
Expand All @@ -543,7 +543,7 @@ describe('update', () => {
);
});

it('does not update the description if it is a string with empty characters', async () => {
it('throws error if description is a string with empty characters', async () => {
await expect(
update(
{
Expand Down Expand Up @@ -577,7 +577,7 @@ describe('update', () => {
});
});

it(`does not throw error when tags array is empty`, async () => {
it('does not throw error when tags array is empty', async () => {
clientArgs.services.caseService.patchCases.mockResolvedValue({
saved_objects: [{ ...mockCases[0] }],
});
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('update', () => {
).resolves.not.toThrow();
});

it('does not update the tags if the array length is too long', async () => {
it('throws error if the tags array length is too long', async () => {
const tags = Array(MAX_TAGS + 1).fill('foo');

await expect(
Expand All @@ -640,7 +640,7 @@ describe('update', () => {
);
});

it('does not update the tags if tag length is too long', async () => {
it('throws error if the tag length is too long', async () => {
const tag = Array(MAX_TAG_LENGTH + 1)
.fill('f')
.toString();
Expand All @@ -663,7 +663,7 @@ describe('update', () => {
);
});

it('does not update the tags if tag is empty string', async () => {
it('throws error if tag is empty string', async () => {
await expect(
update(
{
Expand All @@ -682,7 +682,7 @@ describe('update', () => {
);
});

it('does not update the tags if tag is a string with empty characters', async () => {
it('throws error if tag is a string with empty characters', async () => {
await expect(
update(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,40 @@ export default ({ getService }: FtrProviderContext): void => {
});
});

it('400s if the title an empty string', async () => {
const postedCase = await createCase(supertest, postCaseReq);
await updateCase({
supertest,
params: {
cases: [
{
id: postedCase.id,
version: postedCase.version,
title: '',
},
],
},
expectedHttpCode: 400,
});
});

it('400s if the title is a string with empty characters', async () => {
const postedCase = await createCase(supertest, postCaseReq);
await updateCase({
supertest,
params: {
cases: [
{
id: postedCase.id,
version: postedCase.version,
title: ' ',
},
],
},
expectedHttpCode: 400,
});
});

it('400s if the description is too long', async () => {
const longDescription = 'a'.repeat(30001);

Expand All @@ -599,6 +633,40 @@ export default ({ getService }: FtrProviderContext): void => {
});
});

it('400s if the description an empty string', async () => {
const postedCase = await createCase(supertest, postCaseReq);
await updateCase({
supertest,
params: {
cases: [
{
id: postedCase.id,
version: postedCase.version,
description: '',
},
],
},
expectedHttpCode: 400,
});
});

it('400s if the description is a string with empty characters', async () => {
const postedCase = await createCase(supertest, postCaseReq);
await updateCase({
supertest,
params: {
cases: [
{
id: postedCase.id,
version: postedCase.version,
description: ' ',
},
],
},
expectedHttpCode: 400,
});
});

describe('categories', async () => {
it('400s when a too long category value is passed', async () => {
const postedCase = await createCase(supertest, postCaseReq);
Expand Down

0 comments on commit c865f86

Please sign in to comment.