forked from extern/bruno
feat: yup schema should not allow unknown keys
This commit is contained in:
parent
8763ff2ad1
commit
e46e3d5b22
@ -2,7 +2,8 @@ const Yup = require('yup');
|
||||
|
||||
const uidSchema = Yup.string()
|
||||
.length(21, 'uid must be 21 characters in length')
|
||||
.matches(/^[a-zA-Z0-9]*$/, 'uid must be alphanumeric');
|
||||
.matches(/^[a-zA-Z0-9]*$/, 'uid must be alphanumeric')
|
||||
.strict();
|
||||
|
||||
module.exports = {
|
||||
uidSchema
|
||||
|
@ -8,7 +8,7 @@ const workspaceSchema = Yup.object({
|
||||
.max(50, 'name must be 50 characters or less')
|
||||
.required('name is required'),
|
||||
collectionUids: Yup.array().of(uidSchema)
|
||||
});
|
||||
}).noUnknown(true).strict();
|
||||
|
||||
module.exports = {
|
||||
workspaceSchema
|
||||
|
@ -69,4 +69,18 @@ describe('Workspace Schema Validation', () => {
|
||||
)
|
||||
]);
|
||||
});
|
||||
|
||||
it('workspace schema must throw error when unknown key is present', async () => {
|
||||
const workspace = {
|
||||
uid: uuid(),
|
||||
name: 'My Workspace',
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
return Promise.all([
|
||||
expect(workspaceSchema.validate(workspace)).rejects.toEqual(
|
||||
validationErrorWithMessages('this field has unspecified keys: foo')
|
||||
)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user