This repository was archived by the owner on Aug 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasicTest.js
More file actions
executable file
·152 lines (150 loc) · 5.31 KB
/
basicTest.js
File metadata and controls
executable file
·152 lines (150 loc) · 5.31 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
150
151
152
var ebird = require('./src/index.js');
var expect = require('chai').expect;
var instance = new ebird();
var instance2 = new ebird();
instance
.auth('projectbabblertest1', 'babblebabble')
.then((token) => {
console.log('successful login to test 1');
return token;
})
.catch(() => {
console.log('failed to log in');
process.exit(1);
})
.then((token) => {
var instance3 = new ebird(token);
// Should use token to log in. Sending a fake password ensure's it looking at the token.
return instance3
.auth('projectbabblertest1', 'wrong_password')
.then((token) => {
console.log('Logged in with a token');
})
.catch(() => {
console.log('Using token failed');
process.exit(1);
});
})
.then(() => {
var instance4 = new ebird(12345);
// If token is false, fallback to username and password.
return instance4
.auth('projectbabblertest1', 'babblebabble')
.then((token) => {
console.log('Logged in with username and password when token was invalid');
})
.catch(() => {
console.log('Usename/Password fallback failed');
process.exit(1);
});
})
.then(() => {
var instance2 = new ebird();
return instance2
.auth('projectbabblertest1', 'wrong_password')
.then(() => {
console.log('Logged in with a bad password');
process.exit(1);
})
.catch(() => {
console.log('successful failure with bad password');
});
})
.then(() => {
return instance.totals.countries().then((results) => {
expect(results.length).to.equal(0);
console.log('Counties returns zero results');
});
})
.then(() => {
return instance.list('US-VA', 'life').then((results) => {
expect(results.length).to.equal(0);
console.log('VA life list returns zero results');
});
})
.then(() => {
return instance2.auth('projectbabblertest2', 'babblebabble').then(() => {
console.log('successful login to test 2');
});
})
.then(() => {
return instance2.totals.countries().then((results) => {
expect(results.length).to.equal(1);
expect(results).to.deep.equal([
{
name: 'United States',
code: 'US',
items: [
{ listType: 'US', time: 'life', number: '5', listable: true },
{ listType: 'US', time: 'year', number: '0', listable: true },
{ listType: 'US', time: 'month', number: '0', listable: true },
],
},
]);
console.log('Counties returns 1 results');
});
})
.then(() => {
return instance2.list('US-CA', 'year', 2016).then((results) => {
expect(results.length).to.equal(4);
var species = results.map((row) => {
return row.commonName;
});
expect(species).to.deep.equal(['Western Gull', 'Double-crested Cormorant', 'Black Phoebe', 'White-crowned Sparrow']);
console.log('CA 2016 list has 4 results');
});
})
.then(() => {
return instance2.list('ABA', 'life').then((results) => {
expect(results.length).to.equal(5);
var species = results.map((row) => {
return row.commonName;
});
expect(species).to.deep.equal(['Rock Pigeon', 'Western Gull', 'Double-crested Cormorant', 'Black Phoebe', 'White-crowned Sparrow']);
console.log('ABA life list has 5 results');
});
})
.then(() => {
return instance2.list('south_america', 'life').then((results) => {
expect(results).to.deep.equal([]);
console.log('south_america life list has 0 results');
});
})
/*.then(() => {
return instance2.alerts.rarities('US-CA').then((results) => {
expect(results.length).to.be.above(1);
console.log('Pulled some Rarities for CA');
});
})
.then(() => {
return instance2.alerts.needs('US-CA').then((results) => {
expect(results.length).to.be.above(1);
console.log('Pulled some Needs for CA');
});
})*/
.then(() => {
return instance2.targets
.species({
location: 'US-CA',
startMonth: 7,
endMonth: 7,
locationFilter: 'US-CA',
timefilter: 'year',
})
.then((results) => {
expect(results.length).to.be.above(1);
expect(results[0].frequency).to.be.above(1);
expect(results[0].species.code).to.not.be.empty;
expect(results[0].species.name).to.not.be.empty;
expect(results[0].map).to.not.be.empty;
console.log('Pulled some targets for CA');
});
})
.then(() => {
console.log('Tests Pass');
process.exit(0);
})
.catch((e) => {
console.log(e);
process.exit(1);
});