diff --git a/examples/mongodb/model.js b/examples/mongodb/model.js index 1dc6a1f..f856c1b 100755 --- a/examples/mongodb/model.js +++ b/examples/mongodb/model.js @@ -90,16 +90,21 @@ module.exports.saveToken = function(token, client, user) { // Can't just chain `lean()` to `save()` as we did with `findOne()` elsewhere. Instead we use `Promise` to resolve the data. return new Promise( function(resolve,reject){ accessToken.save(function(err,data){ - if( err ) reject( err ); - else resolve( data ); + if( err ) { + reject( err ); + } else { + resolve( data ); + } }) ; }).then(function(saveResult){ // `saveResult` is mongoose wrapper object, not doc itself. Calling `toJSON()` returns the doc. - saveResult = saveResult && typeof saveResult == 'object' ? saveResult.toJSON() : saveResult; + saveResult = saveResult && typeof saveResult === 'object' ? saveResult.toJSON() : saveResult; // Unsure what else points to `saveResult` in oauth2-server, making copy to be safe - var data = new Object(); - for( var prop in saveResult ) data[prop] = saveResult[prop]; + var data = {}; + for( var prop in saveResult ) { + data[prop] = saveResult[prop]; + } // /oauth-server/lib/models/token-model.js complains if missing `client` and `user`. Creating missing properties. data.client = data.clientId; diff --git a/test/integration/index_test.js b/test/integration/index_test.js index 91f91b7..f5fbb14 100644 --- a/test/integration/index_test.js +++ b/test/integration/index_test.js @@ -108,7 +108,7 @@ describe('ExpressOAuthServer', function() { request(app.listen()) .get('/') .set('Authorization', 'Bearer foobar') - .expect(200, function(err, res){ + .expect(200, function(err){ spy.called.should.be.True(); done(err); }); @@ -146,7 +146,7 @@ describe('ExpressOAuthServer', function() { .post('/?state=foobiz') .set('Authorization', 'Bearer foobar') .send({ client_id: 12345, response_type: 'code' }) - .expect(302, function(err, res){ + .expect(302, function(err){ spy.called.should.be.True(); done(err); }); @@ -243,7 +243,7 @@ describe('ExpressOAuthServer', function() { .post('/') .send('client_id=foo&client_secret=bar&grant_type=password&username=qux&password=biz') .expect({ access_token: 'foobar', token_type: 'Bearer' }) - .expect(200, function(err, res){ + .expect(200, function(err){ spy.called.should.be.True(); done(err); }); @@ -261,7 +261,6 @@ describe('ExpressOAuthServer', function() { return { accessToken: 'foobar', client: {}, user: {} }; } }; - var spy = sinon.spy(); var oauth = new ExpressOAuthServer({ model: model, continueMiddleware: true }); app.use(oauth.token()); diff --git a/test/unit/index_test.js b/test/unit/index_test.js index d06e11d..0bb132c 100644 --- a/test/unit/index_test.js +++ b/test/unit/index_test.js @@ -38,7 +38,7 @@ describe('ExpressOAuthServer', function() { oauth.server.authenticate.firstCall.args.should.have.length(3); oauth.server.authenticate.firstCall.args[0].should.be.an.instanceOf(Request); oauth.server.authenticate.firstCall.args[1].should.be.an.instanceOf(Response); - should.not.exist(oauth.server.authenticate.firstCall.args[2]) + should.not.exist(oauth.server.authenticate.firstCall.args[2]); oauth.server.authenticate.restore(); done(); @@ -68,7 +68,7 @@ describe('ExpressOAuthServer', function() { describe('authorize()', function() { it('should call `authorize()` and end middleware execution', function(done) { - var nextMiddleware = sinon.spy() + var nextMiddleware = sinon.spy(); var oauth = new ExpressOAuthServer({ model: {} }); sinon.stub(oauth.server, 'authorize').returns({}); @@ -91,7 +91,7 @@ describe('ExpressOAuthServer', function() { }); it('should call `authorize()` and continue middleware chain', function(done) { - var nextMiddleware = sinon.spy() + var nextMiddleware = sinon.spy(); var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true }); sinon.stub(oauth.server, 'authorize').returns({}); @@ -137,7 +137,7 @@ describe('ExpressOAuthServer', function() { describe('token()', function() { it('should call `token()` and end middleware chain', function(done) { - var nextMiddleware = sinon.spy() + var nextMiddleware = sinon.spy(); var oauth = new ExpressOAuthServer({ model: {} }); sinon.stub(oauth.server, 'token').returns({}); @@ -160,7 +160,7 @@ describe('ExpressOAuthServer', function() { }); it('should call `token()` and continue middleware chain', function(done) { - var nextMiddleware = sinon.spy() + var nextMiddleware = sinon.spy(); var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true }); sinon.stub(oauth.server, 'token').returns({});