mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 08:04:51 +00:00
Fix validations for custom field types (#8297)
Signed-off-by: Sam Williams <spwilliams91@icloud.com>
This commit is contained in:
parent
ba9711d134
commit
96a33ed942
@ -102,6 +102,25 @@ describe('Entity validator', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Supports custom field types', async () => {
|
||||
const model = {
|
||||
attributes: {
|
||||
uuid: {
|
||||
type: 'uuid',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const input = { uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7' };
|
||||
|
||||
expect.hasAssertions();
|
||||
|
||||
const data = await entityValidator.validateEntityCreation(model, input);
|
||||
expect(data).toEqual({
|
||||
uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('String validator', () => {
|
||||
@ -335,6 +354,25 @@ describe('Entity validator', () => {
|
||||
);
|
||||
expect(data).toEqual({ title: null });
|
||||
});
|
||||
|
||||
it('Supports custom field types', async () => {
|
||||
const model = {
|
||||
attributes: {
|
||||
uuid: {
|
||||
type: 'uuid',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const input = { uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7' };
|
||||
|
||||
expect.hasAssertions();
|
||||
|
||||
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
||||
expect(data).toEqual({
|
||||
uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('String validator', () => {
|
||||
|
||||
@ -126,7 +126,13 @@ const createRelationValidator = createOrUpdate => (attr, data, { isDraft }) => {
|
||||
const createSimpleAttributeValidator = createOrUpdate => (attr, { isDraft }) => {
|
||||
let validator;
|
||||
|
||||
validator = validators[attr.type](attr, { isDraft });
|
||||
if (attr.type in validators) {
|
||||
validator = validators[attr.type](attr, { isDraft });
|
||||
} else {
|
||||
// No validators specified - fall back to mixed
|
||||
validator = yup.mixed();
|
||||
}
|
||||
|
||||
validator = addRequiredValidation(createOrUpdate)(!isDraft && attr.required, validator);
|
||||
|
||||
return validator;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user