forked from bencevans/oyster-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
79 lines (67 loc) · 1.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
var assert = require('assert');
var request = require('request').defaults({ json: true });
require('./app');
var validAuth = {
username: process.env.OYSTER_USER,
password: process.env.OYSTER_PASS
};
function url(path) {
return require('url').resolve('http://localhost:3000', path);
}
describe('/valid_auth', function() {
describe('Invalid', function() {
it('should return 401 & message', function(done) {
request({
uri: url('/valid_auth'),
auth: {
user: '[email protected]',
pass: 'turbothis',
sendImmediately: true
}
}, function(err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(body.error, 'Authentication Invalid');
done();
});
});
});
describe('Missing', function() {
it('should return 401 & message', function(done) {
request(url('/valid_auth'), function(err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(body.error, 'Authentication Not Provided');
done();
});
});
});
describe('Correct', function() {
it('should return 200 & valid_auth=true', function(done) {
request({
uri: url('/valid_auth'),
auth: validAuth
}, function(err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body.valid_auth, true);
done();
});
});
});
});
describe('/balance', function() {
describe('Correct', function() {
it('should return 200 & balance', function(done) {
request({
uri: url('/balance'),
auth: validAuth
}, function(err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(typeof body.balance, 'number');
done();
});
});
});
});