tests/rules/cron.test.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 36
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 23
mnd 1
bc 1
fnc 4
dl 0
loc 36
bpm 0.25
cpm 1.25
noi 0
c 0
b 0
f 0
rs 10
1
import { RuleTester } from '../utils';
2
3
const tester = new RuleTester('cron');
4
5
suite('Rules: cron');
6
7
const valid = [
8
    '0 4 8-14 * *',
9
    '0 0 1,15 * 3',
10
    '5 0 * 8 *',
11
    '23 0-20/2 * * *',
12
    '5-10 4 */3 * sun',
13
    '0 0,5-12 1 */2 *'
14
];
15
16
test('Positive: cron', function () {
17
    for (const cron of valid) {
18
        tester.positive(cron, cron);
19
    }
20
});
21
22
test('Positive: empty value', function () {
23
    tester.positive(null, null);
24
    tester.positive(undefined, undefined);
25
});
26
27
test('Negative: bad formats', function () {
28
    tester.negative(true, 'NOT_STRING', 'The value is not a string');
29
    tester.negative([ '0', '4', '8-14', '*', '*' ], 'NOT_STRING', 'The value is not a string');
30
});
31
32
test('Negative: malformed cron', function () {
33
    tester.negative('0 22 * 1-5', 'INVALID_CRON', 'The value can not be parsed as cron string');
34
    tester.negative('0 22 * * * *', 'INVALID_CRON', 'The value can not be parsed as cron string');
35
    tester.negative('5-10 4 */3 * SUNDAY', 'INVALID_CRON', 'The value can not be parsed as cron string');
36
});
37
38