From d8c8369559bf32d1f867e70bc05853a41afd7dd9 Mon Sep 17 00:00:00 2001 From: adcoelho Date: Mon, 11 Sep 2023 11:15:44 +0200 Subject: [PATCH] Remove custom fields limit from cases domain type. --- .../plugins/cases/common/types/api/case/v1.ts | 17 +++++-- .../cases/common/types/domain/case/v1.test.ts | 50 ------------------- .../cases/common/types/domain/case/v1.ts | 11 +--- 3 files changed, 16 insertions(+), 62 deletions(-) diff --git a/x-pack/plugins/cases/common/types/api/case/v1.ts b/x-pack/plugins/cases/common/types/api/case/v1.ts index b7359531f991b..6187c87c097f2 100644 --- a/x-pack/plugins/cases/common/types/api/case/v1.ts +++ b/x-pack/plugins/cases/common/types/api/case/v1.ts @@ -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, @@ -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'; @@ -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, + }), }) ), ]); @@ -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, + }), }) ), /** diff --git a/x-pack/plugins/cases/common/types/domain/case/v1.test.ts b/x-pack/plugins/cases/common/types/domain/case/v1.test.ts index 3fd13a9beb59d..a8f0eab465b8f 100644 --- a/x-pack/plugins/cases/common/types/domain/case/v1.test.ts +++ b/x-pack/plugins/cases/common/types/domain/case/v1.test.ts @@ -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 { @@ -16,7 +14,6 @@ import { CasesRt, CaseStatuses, RelatedCaseRt, - CaseCustomFieldsRt, } from './v1'; const basicCase = { @@ -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.' - ); - }); -}); diff --git a/x-pack/plugins/cases/common/types/domain/case/v1.ts b/x-pack/plugins/cases/common/types/domain/case/v1.ts index b64582a0697c9..34216d0d9c6aa 100644 --- a/x-pack/plugins/cases/common/types/domain/case/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/case/v1.ts @@ -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 }; @@ -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({ /**