1
|
|
|
import { RuleTester } from '../utils'; |
2
|
|
|
|
3
|
|
|
suite('Rules: min'); |
4
|
|
|
|
5
|
|
|
test('Positive: numbers', function () { |
6
|
|
|
const tester = new RuleTester([ 'number', { 'min': 5 } ]); |
7
|
|
|
|
8
|
|
|
tester.positive(10, 10); |
9
|
|
|
tester.positive(15.8, 15.8); |
10
|
|
|
}); |
11
|
|
|
|
12
|
|
|
test('Positive: empty value', function () { |
13
|
|
|
const tester = new RuleTester({ 'min': 5 }); |
14
|
|
|
|
15
|
|
|
tester.positive(null, null); |
16
|
|
|
tester.positive(undefined, undefined); |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
test('Positive: string', function () { |
20
|
|
|
const tester = new RuleTester([ 'string', { 'min': 2 } ]); |
21
|
|
|
|
22
|
|
|
tester.positive('abc', 'abc'); |
23
|
|
|
tester.positive('-123', '-123'); |
24
|
|
|
}); |
25
|
|
|
|
26
|
|
|
test('Positive: array', function () { |
27
|
|
|
const tester = new RuleTester([ { 'min': 2 } ]); |
28
|
|
|
|
29
|
|
|
tester.positive([ 0, 1, 2, 3 ], [ 0, 1, 2, 3 ]); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
test('Negative: numbers', function () { |
33
|
|
|
const tester = new RuleTester([ 'number', { 'min': 3 } ]); |
34
|
|
|
|
35
|
|
|
tester.negative(-10, 'TOO_LOW', 'The number is lower than the limit', { limit: 3 }); |
36
|
|
|
tester.negative(0.5, 'TOO_LOW', 'The number is lower than the limit', { limit: 3 }); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
test('Negative: string', function () { |
40
|
|
|
const tester = new RuleTester([ 'string', { 'min': 5 } ]); |
41
|
|
|
|
42
|
|
|
tester.negative('abd', 'TOO_SHORT', 'The value is shorter than the limit', { limit: 5 }); |
43
|
|
|
tester.negative('', 'TOO_SHORT', 'The value is shorter than the limit', { limit: 5 }); |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
test('Negative: array', function () { |
47
|
|
|
const tester = new RuleTester([ { 'min': 5 } ]); |
48
|
|
|
|
49
|
|
|
tester.negative([ 1, 2 ], 'TOO_SHORT', 'The value is shorter than the limit', { limit: 5 }); |
50
|
|
|
tester.negative([], 'TOO_SHORT', 'The value is shorter than the limit', { limit: 5 }); |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
test('Negative: bad format', function () { |
54
|
|
|
const tester = new RuleTester([ { 'min': 5 } ]); |
55
|
|
|
|
56
|
|
|
tester.negative(false, 'WRONG_FORMAT', 'Format not supported'); |
57
|
|
|
}); |
58
|
|
|
|