mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 17:59:25 +00:00
Added new validation type 'date' to validator module
This commit is contained in:
@@ -233,6 +233,55 @@ describe('validate', () => {
|
||||
}).toThrow('Invalid');
|
||||
});
|
||||
|
||||
test('Valid date validation', () => {
|
||||
const body = {
|
||||
name: 'Bob',
|
||||
message: 'Hi Jim!',
|
||||
date: '01/02/2004'
|
||||
};
|
||||
|
||||
const fields = [
|
||||
'name',
|
||||
'message',
|
||||
'date'
|
||||
];
|
||||
|
||||
const validation = {
|
||||
date: 'date'
|
||||
};
|
||||
|
||||
const result = validator.validate(body, fields, validation);
|
||||
|
||||
expect(result).toBeObject();
|
||||
expect(result).toContainKey('fields');
|
||||
expect(result.fields.get('date')).toEqual({
|
||||
raw: body.date,
|
||||
date: new Date(body.date)
|
||||
});
|
||||
});
|
||||
|
||||
test('Invalid date validation', () => {
|
||||
const body = {
|
||||
name: 'Bob',
|
||||
message: 'Hi Jim!',
|
||||
date: 'Jeffery'
|
||||
};
|
||||
|
||||
const fields = [
|
||||
'name',
|
||||
'message',
|
||||
'date'
|
||||
];
|
||||
|
||||
const validation = {
|
||||
date: 'date'
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
validator.validate(body, fields, validation);
|
||||
}).toThrow('Invalid');
|
||||
});
|
||||
|
||||
test('Invalid validation type', () => {
|
||||
const body = {
|
||||
name: 'Bob',
|
||||
|
||||
Reference in New Issue
Block a user