-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminDateTime.test.js
53 lines (42 loc) · 2.67 KB
/
minDateTime.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const expect = require('chai').expect;
const moment = require('moment');
const validators = require('../src/common-validators');
describe('minDateTime', function() {
it('empty is valid', function() {
expect(validators.minDateTime(undefined, new Date())).to.be.undefined;
});
it('not date is invalid', function() {
expect(validators.minDateTime('abc', new Date(2000, 0, 1, 0, 0, 5, 0))).to.have.property('error');
expect(validators.minDateTime({a: 1}, new Date(2000, 0, 1, 0, 0, 5, 0))).to.have.property('error');
expect(validators.minDateTime([1,2,3], new Date(2000, 0, 1, 0, 0, 5, 0))).to.have.property('error');
});
it('date less then minDateTime is invalid', function() {
expect(validators.minDateTime(new Date(2000, 0, 1, 0, 0, 4, 0), new Date(2000, 0, 1, 0, 0, 5, 0))).to.have.property('error');
});
it('date more then minDateTime is valid', function() {
expect(validators.minDateTime(new Date(2000, 0, 1, 0, 0, 6, 0), new Date(2000, 0, 1, 0, 0, 5, 0))).to.be.undefined;
});
it('date equal minDateTime is valid', function() {
expect(validators.minDateTime(new Date(2000, 0, 1, 0, 0, 5, 0), new Date(2000, 0, 1, 0, 0, 5, 0))).to.be.undefined;
});
it('date equal minDateTime is invalid if inclusive=false', function() {
expect(validators.minDateTime(new Date(2000, 0, 1, 0, 0, 5, 0), new Date(2000, 0, 1, 0, 0, 5, 0), {exclusive: true})).to.have.property('error');
});
it('date in GMT format is correct', function() {
expect(validators.minDateTime('Sat Jan 01 2000 00:00:04 GMT+0300 (MSK)', 'Sat Jan 01 2000 00:00:05 GMT+0300 (MSK)')).to.have.property('error');
expect(validators.minDateTime('Sat Jan 01 2000 00:00:06 GMT+0300 (MSK)', 'Sat Jan 01 2000 00:00:05 GMT+0300 (MSK)')).to.be.undefined;
});
it('date in ISO format is correct', function() {
expect(validators.minDateTime('2000-01-01T00:00:04.000Z', '2000-01-01T00:00:05.000Z')).to.have.property('error');
expect(validators.minDateTime('2000-01-01T00:00:06.000Z', '2000-01-01T00:00:05.000Z')).to.be.undefined;
});
it('date in time format is correct', function() {
expect(validators.minDateTime(946684804000, 946684805000)).to.have.property('error');
expect(validators.minDateTime(946684806000, 946684805000)).to.be.undefined;
});
it('date in moment.js format is correct', function() {
expect(validators.minDateTime(moment('2000-01-01T00:00:04.000Z'), moment('2000-01-01T00:00:05.000Z'))).to.have.property('error');
expect(validators.minDateTime(moment('2000-01-01T00:00:06.000Z'), moment('2000-01-01T00:00:05.000Z'))).to.be.undefined;
});
});