forked from sailshq/anchor
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmiscellaneousRules.test.js
More file actions
149 lines (129 loc) · 3.55 KB
/
miscellaneousRules.test.js
File metadata and controls
149 lines (129 loc) · 3.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var _ = require('lodash');
var validator = require('../index.js');
var testRules = require('./util/testRules.js');
describe('miscellaneous rules', function() {
describe ('max/min',function () {
it (' should support "max" rule ', function () {
return testRules({
max: 3
},2,5);
});
});
describe ('greaterThan/lessThan',function () {
it (' should support "greaterThan" rule ', function () {
return testRules({
greaterThan: 3.5
}, 4, 3);
});
it (' should support "greaterThan" rule ', function () {
return testRules({
greaterThan: 3.5
}, 3.6, 3.5);
});
it (' should support "lessThan" rule ', function () {
return testRules({
lessThan: 3.5
}, 3, 4);
});
it (' should support "lessThan" rule ', function () {
return testRules({
lessThan: 3.5
}, 3.4, 3.5);
});
});
describe('url', function () {
it ('should support "url" rule with no options', function () {
return testRules({ url: true }, 'http://sailsjs.org', 'sailsjs');
});
it ('should support "url" rule with options', function () {
return testRules({ url: { require_protocol: true } }, 'http://sailsjs.org', 'www.sailsjs.org');
});
});
describe('before/after date', function () {
it (' should support "before" rule ', function () {
return testRules({
before: new Date()
}, new Date(Date.now() - 100000), new Date(Date.now() + 1000000));
});
});
describe('required', function () {
it(' should support "required" with boolean', function() {
testRules({
type: 'boolean',
required: true
}, true, undefined);
});
it(' should support "required" with boolean value false', function() {
testRules({
type: 'boolean',
required: true
}, false, null);
});
it(' should support "required" with integer value 0', function() {
testRules({
type: 'integer',
required: true
}, 0, NaN);
});
it(' should support "required" with string', function() {
testRules({
type: 'string',
required: true
}, 'some', '');
});
it(' should support "required" with empty object', function() {
testRules({
type: 'json',
required: true
}, {}, undefined);
});
it(' should support "required" with array', function() {
testRules({
type: [],
required: true
}, ['one'], []);
});
});
describe('geojson', function () {
var jsondef = {
type: 'json',
geojson: true
};
var stringdef = {
type: 'string',
geojson: true
};
var validGeoJson = [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
];
it(' should support "json" type', function () {
testRules(jsondef, validGeoJson[0], { foo: 'bar' });
});
it(' should support "string" type', function () {
testRules(stringdef, JSON.stringify(validGeoJson[0]), JSON.stringify({ foo: 'bar' }));
});
});
describe('dbType', function () {
it(' should support "dbType" with existing validation rule', function() {
testRules({
type: 'float',
dbType: 'float'
}, 10.9, 'hi');
});
it(' should support "dbType" with non-existing validation rule', function() {
testRules({
type: 'float',
dbType: 'age'
}, 10, 'hi');
});
});
});