-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbed.js
69 lines (53 loc) · 2.05 KB
/
bed.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
'use strict';
var Bed = require('..');
describe('bed', function() {
describe('a basic github api', function() {
var bed = new Bed();
bed.auth('basic', 'foo', 'bar');
bed.base('https://api.github.com');
bed.type('application/json');
bed.accept('application/vnd.github.v3+json');
var gh = {
test: bed.head('/').make(),
listUsers: bed.get('/users').make(),
getUser: bed.get('/users/<id>').make(),
createUser: bed.post('/users').make()
};
it('should fail to authorize', function() {
return gh.test().should.eventually.be.rejectedWith(/Unauthorized/);
});
});
describe('a httpbin.org api', function() {
var bed = new Bed();
bed.auth('basic', 'foo', 'bar');
bed.base('http://httpbin.org');
var bin = {
auth: bed.get('/basic-auth/<user>/bar').make(),
multiAuth: bed.get('/basic-auth/<user>/<pass>').make(),
failAuth: bed.get('/basic-auth/foo/baz').make(),
get: bed.get('/get').make(),
post: bed.post('/post').make()
};
it('should fail to authorize', function() {
return bin.failAuth().should.eventually.be.rejectedWith(/Unauthorized/);
});
it('should fail without required user arg', function() {
return bin.auth().should.be.rejected;
});
it('should successfully authorize', function() {
return bin.auth('foo').should.eventually.have.deep.property('body.authenticated', true);
});
it('should successfully authorize with multiple required args', function() {
return bin.multiAuth('foo', 'bar').should.eventually.have.deep.property('body.authenticated', true);
});
it('should get back query args', function() {
return bin.get({q: 1}).should.eventually.have.deep.property('body.args.q', '1');
});
it('should get back body and query args', function() {
return bin.post({data: 1}, {q: 1}).should.eventually.have.deep.property('body.json.data', 1);
});
});
// yield exports.listUsers();
// yield exports.getUser(); // throws argument error (missing "id")
// yield exports.createUser({});
});