mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 13:39:26 +00:00
Add tests for validator 'values' type
This commit is contained in:
@@ -282,6 +282,48 @@ describe('validate', () => {
|
||||
}).toThrow('Invalid');
|
||||
});
|
||||
|
||||
test('Valid values validation', () => {
|
||||
const body = {
|
||||
times: '1'
|
||||
};
|
||||
|
||||
const fields = [
|
||||
'times'
|
||||
];
|
||||
|
||||
const validation = {
|
||||
values: {
|
||||
times: [ '5', '6', '7', '1' ]
|
||||
}
|
||||
};
|
||||
|
||||
const result = validator.validate(body, fields, validation);
|
||||
|
||||
expect(result).toBeObject();
|
||||
expect(result).toContainKey('fields');
|
||||
expect(result.fields.get('times')).toEqual('1');
|
||||
});
|
||||
|
||||
test('Invalid values validation', () => {
|
||||
const body = {
|
||||
times: '1'
|
||||
};
|
||||
|
||||
const fields = [
|
||||
'times'
|
||||
];
|
||||
|
||||
const validation = {
|
||||
values: {
|
||||
times: [ '5', '6', '7' ]
|
||||
}
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
validator.validate(body, fields, validation);
|
||||
}).toThrow('Invalid');
|
||||
});
|
||||
|
||||
test('Invalid validation type', () => {
|
||||
const body = {
|
||||
name: 'Bob',
|
||||
|
||||
Reference in New Issue
Block a user