Skip to content

Commit

Permalink
Remove custom fields limit from cases domain type.
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed Sep 11, 2023
1 parent 6a85352 commit d8c8369
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 62 deletions.
17 changes: 14 additions & 3 deletions x-pack/plugins/cases/common/types/api/case/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
MAX_BULK_GET_CASES,
MAX_CATEGORY_FILTER_LENGTH,
MAX_ASSIGNEES_PER_CASE,
MAX_CUSTOM_FIELDS_PER_CASE,
} from '../../../constants';
import {
limitedStringSchema,
Expand All @@ -32,10 +33,10 @@ import {
CaseRt,
CaseSettingsRt,
CaseSeverityRt,
CaseCustomFieldsRt,
CasesRt,
CaseStatusRt,
RelatedCaseRt,
CustomFieldRt,
} from '../../domain/case/v1';
import { CaseConnectorRt } from '../../domain/connector/v1';
import { CaseUserProfileRt, UserRt } from '../../domain/user/v1';
Expand Down Expand Up @@ -107,7 +108,12 @@ export const CasePostRequestRt = rt.intersection([
/**
* The list of custom field values of the case.
*/
customFields: CaseCustomFieldsRt,
customFields: limitedArraySchema({
codec: CustomFieldRt,
fieldName: 'customFields',
min: 0,
max: MAX_CUSTOM_FIELDS_PER_CASE,
}),
})
),
]);
Expand Down Expand Up @@ -365,7 +371,12 @@ export const CasePatchRequestRt = rt.intersection([
/**
* Custom fields of the case
*/
customFields: CaseCustomFieldsRt,
customFields: limitedArraySchema({
codec: CustomFieldRt,
fieldName: 'customFields',
min: 0,
max: MAX_CUSTOM_FIELDS_PER_CASE,
}),
})
),
/**
Expand Down
50 changes: 0 additions & 50 deletions x-pack/plugins/cases/common/types/domain/case/v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { MAX_CUSTOM_FIELDS_PER_CASE } from '../../../constants';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { AttachmentType } from '../attachment/v1';
import { ConnectorTypes } from '../connector/v1';
import {
Expand All @@ -16,7 +14,6 @@ import {
CasesRt,
CaseStatuses,
RelatedCaseRt,
CaseCustomFieldsRt,
} from './v1';

const basicCase = {
Expand Down Expand Up @@ -267,50 +264,3 @@ describe('CasesRt', () => {
});
});
});

describe('CaseCustomFieldsRt', () => {
const customFields = [
{
key: 'string_custom_field_1',
type: 'text',
field: { value: ['this is a text field value', 'this is second'] },
},
{
key: 'string_custom_field_2',
type: 'text',
field: { value: null },
},
{
key: 'boolean_custom_field_1',
type: 'toggle',
field: { value: [true] },
},
{
key: 'boolean_custom_field_2',
type: 'toggle',
field: { value: null },
},
{
key: 'list_custom_field_1',
type: 'list',
field: { value: ['this is a text field value'] },
},
];

it('has expected attributes in request', () => {
const query = CaseCustomFieldsRt.decode(customFields);

expect(query).toStrictEqual({
_tag: 'Right',
right: customFields,
});
});

it('throws an error when there are too many custom fields', () => {
const tooLongCustomFields = Array(MAX_CUSTOM_FIELDS_PER_CASE + 1).fill(customFields[0]);

expect(PathReporter.report(CaseCustomFieldsRt.decode(tooLongCustomFields))).toContain(
'The length of the field customFields is too long. Array must be of length <= 5.'
);
});
});
11 changes: 2 additions & 9 deletions x-pack/plugins/cases/common/types/domain/case/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import * as rt from 'io-ts';
import { CaseStatuses } from '@kbn/cases-components/src/status/types';
import { limitedArraySchema } from '../../../schema';
import { ExternalServiceRt } from '../external_service/v1';
import { CaseAssigneesRt, UserRt } from '../user/v1';
import { CaseConnectorRt } from '../connector/v1';
import { AttachmentRt } from '../attachment/v1';
import { MAX_CUSTOM_FIELDS_PER_CASE } from '../../../constants';

export { CaseStatuses };

Expand Down Expand Up @@ -74,14 +72,9 @@ const CustomFieldList = rt.strict({
field: customFieldValue(rt.string),
});

const CustomFieldRt = rt.union([CustomFieldText, CustomFieldToggle, CustomFieldList]);
export const CustomFieldRt = rt.union([CustomFieldText, CustomFieldToggle, CustomFieldList]);

export const CaseCustomFieldsRt = limitedArraySchema({
codec: CustomFieldRt,
fieldName: 'customFields',
min: 0,
max: MAX_CUSTOM_FIELDS_PER_CASE,
});
const CaseCustomFieldsRt = rt.array(CustomFieldRt);

const CaseBasicRt = rt.strict({
/**
Expand Down

0 comments on commit d8c8369

Please sign in to comment.