Skip to content

Commit

Permalink
Clarify test cases for userAuthorizationParams in subclass.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 10, 2016
1 parent 793d33d commit 7d9a738
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 74 deletions.
74 changes: 0 additions & 74 deletions test/oauth.sub.userauthorizationparams.test.js

This file was deleted.

57 changes: 57 additions & 0 deletions test/oauth.subclass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,63 @@ describe('OAuthStrategy subclass', function() {
}); // that overrides requestTokenParams


describe('that overrides userAuthorizationParams', function() {
function FooOAuthStrategy(options, verify) {
OAuthStrategy.call(this, options, verify);
}
util.inherits(FooOAuthStrategy, OAuthStrategy);

FooOAuthStrategy.prototype.userAuthorizationParams = function(options) {
return { screen_name: options.screenName };
}


describe('issuing authorization request that redirects to service provider', function() {
var strategy = new FooOAuthStrategy({
requestTokenURL: 'https://www.example.com/oauth/request_token',
accessTokenURL: 'https://www.example.com/oauth/access_token',
userAuthorizationURL: 'https://www.example.com/oauth/authorize',
consumerKey: 'ABC123',
consumerSecret: 'secret'
}, function() {});

strategy._oauth.getOAuthRequestToken = function(extraParams, callback) {
if (Object.keys(extraParams).length !== 1) { return callback(new Error('incorrect extraParams argument')); }
if (extraParams.oauth_callback !== undefined) { return callback(new Error('incorrect oauth_callback argument')); }

callback(null, 'hh5s93j4hdidpola', 'hdhd0244k9j7ao03', {});
}

var request
, url;

before(function(done) {
chai.passport.use(strategy)
.redirect(function(u) {
url = u;
done();
})
.req(function(req) {
request = req;
req.session = {};
})
.authenticate({ screenName: 'bob' });
});

it('should be redirected', function() {
expect(url).to.equal('https://www.example.com/oauth/authorize?oauth_token=hh5s93j4hdidpola&screen_name=bob');
});

it('should store token and token secret in session', function() {
expect(request.session['oauth']).to.not.be.undefined;
expect(request.session['oauth']['oauth_token']).to.equal('hh5s93j4hdidpola');
expect(request.session['oauth']['oauth_token_secret']).to.equal('hdhd0244k9j7ao03');
});
}); // issuing authorization request that redirects to service provider

}); // that overrides userAuthorizationParams


describe('that overrides parseErrorResponse', function() {
function FooOAuthStrategy(options, verify) {
OAuthStrategy.call(this, options, verify);
Expand Down

0 comments on commit 7d9a738

Please sign in to comment.