1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:59:28 +00:00

Add tests for validator 'values' type

This commit is contained in:
2022-04-22 03:17:53 +00:00
parent 62cfe7b643
commit 063c12b1db

View File

@@ -282,6 +282,48 @@ describe('validate', () => {
}).toThrow('Invalid'); }).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', () => { test('Invalid validation type', () => {
const body = { const body = {
name: 'Bob', name: 'Bob',