forked from lelylan/simple-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.js
33 lines (26 loc) · 994 Bytes
/
password.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
var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
var request, result, error;
describe('OAuth2.Password',function() {
describe('#getToken',function() {
beforeEach(function(done) {
var params = { 'username': 'alice', 'password': 'secret', 'grant_type': 'password' };
request = nock('https://example.org:443').post('/oauth/token', qs.stringify(params)).replyWithFile(200, __dirname + '/fixtures/access_token.json');
done();
})
beforeEach(function(done) {
var params = { 'username': 'alice', 'password': 'secret' };
OAuth2.Password.getToken(params, function(e, r) {
error = e; result = r; done();
})
})
it('makes the HTTP request', function() {
request.isDone();
});
it('returns an access token',function() {
result.should.have.property('access_token');
});
});
});