-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.test.js
37 lines (29 loc) · 1.04 KB
/
cron.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
import { RuleTester } from '../utils';
const tester = new RuleTester('cron');
suite('Rules: cron');
const valid = [
'0 4 8-14 * *',
'0 0 1,15 * 3',
'5 0 * 8 *',
'23 0-20/2 * * *',
'5-10 4 */3 * sun',
'0 0,5-12 1 */2 *'
];
test('Positive: cron', function () {
for (const cron of valid) {
tester.positive(cron, cron);
}
});
test('Positive: empty value', function () {
tester.positive(null, null);
tester.positive(undefined, undefined);
});
test('Negative: bad formats', function () {
tester.negative(true, 'NOT_STRING', 'The value is not a string');
tester.negative([ '0', '4', '8-14', '*', '*' ], 'NOT_STRING', 'The value is not a string');
});
test('Negative: malformed cron', function () {
tester.negative('0 22 * 1-5', 'INVALID_CRON', 'The value can not be parsed as cron string');
tester.negative('0 22 * * * *', 'INVALID_CRON', 'The value can not be parsed as cron string');
tester.negative('5-10 4 */3 * SUNDAY', 'INVALID_CRON', 'The value can not be parsed as cron string');
});