-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
151 lines (128 loc) · 3.86 KB
/
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
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
150
151
/*
Name: overheid.io - test.js
Description: Access overheid.io endpoints like OpenKvK, RDW and BAG with node.js
Author: Franklin van de Meent (https://frankl.in)
Source code: https://github.com/fvdm/nodejs-overheid.io
Feedback: https://github.com/fvdm/nodejs-overheid.io/issues
License: Unlicense (Public Domain) - see LICENSE file
(https://github.com/fvdm/nodejs-overheid.io/raw/master/LICENSE)
*/
var dotest = require ('dotest');
var app = require ('./');
// Setup
var config = {
apikey: process.env.OVIO_APIKEY || null,
timeout: process.env.OVIO_TIMEOUT || 5000,
dataset: 'voertuiggegevens'
};
var ovio = app (config);
// Tests
dotest.add ('Module', function (test) {
test()
.isFunction ('fail', 'exports', app)
.isFunction ('fail', 'interface', ovio)
.done();
});
dotest.add ('item', function (test) {
ovio ({
path: '4-TFL-24',
callback: function (err, data) {
test (err)
.isNull ('fail', 'err', err)
.isNotEmpty ('fail', 'data', data)
.isObject ('fail', 'data', data)
.isExactly ('fail', 'data.kenteken', data && data.kenteken, '4-TFL-24')
.isString ('fail', 'data.eerstekleur', data && data.eerstekleur)
.done();
}
});
});
dotest.add ('list', function (test) {
ovio ({
params: {
query: '*X*',
queryFields: ['handelsbenaming'],
filters: { merk: 'bmw' },
fields: ['eerstekleur', 'vermogen']
},
callback: function (err, data) {
var embedded = data && data._embedded;
test (err)
.isNull ('fail', 'err', err)
.isObject ('fail', 'data', data)
.isCondition ('fail', 'data.totalItemCount', data && data.totalItemCount, '>=', 1)
.isObject ('fail', 'data._embedded', embedded)
.isArray ('fail', 'data._embedded.kenteken', embedded && embedded.kenteken)
.isNotEmpty ('warn', 'data._embedded.kenteken', embedded && embedded.kenteken)
.done();
}
});
});
dotest.add ('Error: no result', function (test) {
ovio ({
path: 'error.test',
callback: function (err, data) {
test()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'no result')
.isUndefined ('fail', 'data', data)
.done();
}
});
});
dotest.add ('Error: request failed', function (test) {
ovio ({
path: '4-TFL-24',
params: {
fields: ['eerstekleur']
},
timeout: 1,
callback: function (err, data) {
var error = err && err.error;
test()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'request failed')
.isError ('fail', 'err.error', error)
.isExactly ('fail', 'err.error.code', error && error.code, 'TIMEOUT')
.isUndefined ('fail', 'data', data)
.done();
}
});
});
dotest.add ('Error: invalid response', function (test) {
ovio ({
params: {
fields: ''
},
callback: function (err, data) {
test()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'invalid response')
.isCondition ('warn', 'err.code', err && err.code, '>=', 300)
.isUndefined ('fail', 'data', data)
.done();
}
});
});
dotest.add ('Error: API error', function (test) {
var tmp = app ({
dataset: 'voertuiggegevens'
});
tmp ({
params: {
filters: { merk: 'bmw' }
},
callback: function (err, data) {
test()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'API error')
.isString ('fail', 'err.error', err && err.error)
.isNotEmpty ('fail', 'err.error', err && err.error)
.isCondition ('fail', 'err.code', err && err.code, '>=', 300)
.isUndefined ('fail', 'data', data)
.done();
}
});
});
// Start the tests
dotest.run();