-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
74 lines (57 loc) · 1.99 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
/*
Name: openkvk - test.js
Description: Test script for openkvk.js
Author: Franklin van de Meent (https://frankl.in)
Source & docs: https://github.com/fvdm/nodejs-openkvk
Feedback: https://github.com/fvdm/nodejs-openkvk/issues
License: Unlicense (Public Domain) - see LICENSE file
*/
// Setup
var dotest = require ('dotest');
var app = require ('./');
var config = {
apikey: process.env.OPENKVK_APIKEY || null,
timeout: process.env.OPENKVK_TIMEOUT || null
};
var openkvk = app (config);
function testArrayObject (err, data) {
var rp = data && data._embedded && data._embedded.rechtspersoon;
var item = rp && rp instanceof Array && rp [0];
dotest.test (err)
.isObject ('fail', 'data', data)
.isCondition ('fail', 'data.totalItemCount', data && data.totalItemCount, '>', 0)
.isObject ('fail', 'data._embedded', data && data._embedded)
.isArray ('fail', 'data._embedded.rechtspersoon', rp)
.isNotEmpty ('fail', 'data._embbedded.rechtspersoon', rp)
.isObject ('fail', 'data._embedded.rechtspersoon[0]', item)
.isString ('fail', 'data._embedded.rechtspersoon[0].dossiernummer', item && item.dossiernummer)
.done ();
}
dotest.add ('Module', function (test) {
test ()
.isFunction ('fail', 'exports', app)
.isFunction ('fail', 'interface', openkvk)
.done ();
});
dotest.add ('search by keyword', function () {
var params = {
query: 'ahold',
size: 2
};
openkvk (params, testArrayObject);
});
dotest.add ('search by dossier', function () {
openkvk ('58488340', testArrayObject);
});
dotest.add ('search by subdossier', function (test) {
openkvk ('58488340/0000', function (err, data) {
test (err)
.isObject ('fail', 'data', data)
.isNotEmpty ('fail', 'data', data)
.isExactly ('warn', 'data.dossiernummer', data && data.dossiernummer, '58488340')
.isExactly ('warn', 'data.subdossiernummer', data && data.subdossiernummer, '0000')
.done ();
});
});
// Start the tests
dotest.run ();