mirror of
https://github.com/strapi/strapi.git
synced 2025-08-28 18:51:33 +00:00
Make string input strict
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
9ad0744e4b
commit
6d490aa366
@ -23,7 +23,7 @@ describe('Entity validator', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const input = { title: 123 };
|
||||
const input = { title: 1234 };
|
||||
|
||||
expect.hasAssertions();
|
||||
|
||||
@ -59,6 +59,39 @@ describe('Entity validator', () => {
|
||||
expect(data).toEqual(input);
|
||||
});
|
||||
|
||||
it('Returns casted data when possible', async () => {
|
||||
const errors = {
|
||||
badRequest: jest.fn(),
|
||||
};
|
||||
|
||||
const entityValidator = createEntityValidator({
|
||||
strapi: {
|
||||
errors,
|
||||
},
|
||||
});
|
||||
|
||||
const model = {
|
||||
attributes: {
|
||||
title: {
|
||||
type: 'string',
|
||||
},
|
||||
number: {
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const input = { title: 'Test', number: '123' };
|
||||
|
||||
expect.hasAssertions();
|
||||
|
||||
const data = await entityValidator.validateEntity(model, input);
|
||||
expect(data).toEqual({
|
||||
title: 'Test',
|
||||
number: 123,
|
||||
});
|
||||
});
|
||||
|
||||
test('Throws on required not respected', async () => {
|
||||
const errors = {
|
||||
badRequest: jest.fn(),
|
||||
|
@ -66,7 +66,7 @@ const addMaxFloatValidator = ({ max }, validator) =>
|
||||
/* Type validators */
|
||||
|
||||
const stringValidator = composeValidators(
|
||||
() => yup.string(),
|
||||
() => yup.string().strict(),
|
||||
addMinLengthValidator,
|
||||
addMaxLengthValidator
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user