-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
100 lines (88 loc) · 2.91 KB
/
tests.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
// const fs = require('fs')
const chai = require("chai")
const chaiAsPromised = require("chai-as-promised");
const should = require("chai").should();
chai.use(chaiAsPromised);
const ipni = require('./main.js');
const useRecursion = true;
let params = {
perPage: 2,
cursor: "*",
}
describe('#powo.lookup(POWO_URL, params=\'distribution\')', function() {
beforeEach(function() {
params = 'distribution';
})
// chai-as-promised version
it('should return a record for \'Stanhopea oculata\' with a distribution', function() {
let urn = 'urn:lsid:ipni.org:names:658592-1';
// ipni.lookup(ipni.POWO_URL, params, urn).then((r)=>{console.log(r)});
return ipni.lookup(ipni.POWO_URL, params, urn)
.should.eventually.be.an('Object').to.include({"name": "Stanhopea oculata"})
.that.has.all.keys('fqId', 'distribution');
});
})
describe('#ipni.query(IPNI_URL, params.q={genus:___, species:___})', function() {
beforeEach(function() {
params = {
perPage: 100,
cursor: "*",
}
})
it('should return >= 6 results for Stanhopea oculata', function() {
params.q = {
genus: 'Stanhopea',
species: 'oculata'
}
return ipni.query(ipni.IPNI_URL, params, useRecursion).then((r)=>{
r.should.be.an('array').with.lengthOf.at.least(6);
})
});
// chai-as-promised version
it('should return >= 4 results for Stanhopea tigrina', function() {
params.q = {
genus: 'Stanhopea',
species: 'tigrina'
}
return ipni.query(ipni.IPNI_URL, params, useRecursion)
.should.eventually.be.an('array').with.lengthOf.at.least(4);
});
it('should return 0 results for Stanhopea typo', function() {
params.q = {
genus: 'Stanhopea',
species: 'typo'
}
return ipni.query(ipni.IPNI_URL, params, useRecursion)
.should.eventually.be.an('array').with.lengthOf(0);
});
})
describe('#ipni.query(IPNI_URL, params.q={"a plant name"})', function() {
beforeEach(function() {
params = {
perPage: 100,
cursor: "*",
}
})
it('should return >= 6 results for Stanhopea oculata', function() {
params.q = 'Stanhopea oculata'
return ipni.query(ipni.IPNI_URL, params, useRecursion).then((r)=>{
r.should.be.an('array').with.lengthOf.at.least(6);
})
});
// chai-as-promised version
it('should return >= 4 results for Stanhopea tigrina', function() {
params.q = 'Stanhopea tigrina'
return ipni.query(ipni.IPNI_URL, params, useRecursion)
.should.eventually.be.an('array').with.lengthOf.at.least(4);
});
it('should return 0 results for Stanhopea typo', function() {
params.q = 'Stanhopea typo'
return ipni.query(ipni.IPNI_URL, params, useRecursion)
.should.eventually.be.an('array').with.lengthOf(0);
});
})
// console.log(r);
// fs.writeFile('Output.json', JSON.stringify(r), (err) => {
// // In case of a error throw err.
// if (err) throw err;
// });