Skip to content

Commit

Permalink
remove notRegisteredCustomFields - duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
jcger committed Oct 2, 2023
1 parent af0df9e commit d1c8bb8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
29 changes: 0 additions & 29 deletions x-pack/plugins/cases/server/client/cases/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,34 +403,5 @@ describe('validators', () => {
})
).toThrowErrorMatchingInlineSnapshot(`"Missing required custom fields: first_key"`);
});

it('throws if request sends a custom field that is not part of the configuration', () => {
const requestCustomFields: CaseCustomFields = [
{
key: 'first_key',
type: CustomFieldTypes.TEXT as const,
value: ['foo'],
},
{
key: 'second_key',
type: CustomFieldTypes.TOGGLE,
value: true,
},
];
const customFieldsConfiguration: CustomFieldsConfiguration = [
{
key: 'first_key',
type: CustomFieldTypes.TEXT,
label: 'foo',
required: true,
},
];
expect(() =>
validateRequiredCustomFields({
requestCustomFields,
customFieldsConfiguration,
})
).toThrowErrorMatchingInlineSnapshot(`"Unknown custom fields: second_key"`);
});
});
});
10 changes: 0 additions & 10 deletions x-pack/plugins/cases/server/client/cases/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ export const validateRequiredCustomFields = ({
}
}

const notRegisteredCustomFields = differenceWith(
requestCustomFields ?? [],
customFieldsConfiguration,
(requestedVal, requiredVal) => requestedVal.key === requiredVal.key
).map((e) => e.key);

if (notRegisteredCustomFields.length) {
throw Boom.badRequest(`Unknown custom fields: ${notRegisteredCustomFields}`);
}

const requiredCustomFields = customFieldsConfiguration.filter(
(customField) => customField.required
);
Expand Down

0 comments on commit d1c8bb8

Please sign in to comment.