Skip to content

Commit

Permalink
Add test case for existing message with successMessage option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Nov 3, 2012
1 parent bb9d357 commit 84d6940
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/middleware/authenticate-test.js
Expand Up @@ -629,6 +629,54 @@ vows.describe('authenticate').addBatch({
},
},

'with a successful authentication containing info message using string message option with existing messages': {
topic: function() {
var self = this;
var passport = new Passport();
passport.use('success', new MockSuccessInfoMessageStrategy);
return passport.authenticate('success', { successMessage: 'Login complete',
successRedirect: 'http://www.example.com/account' });
},

'when handling a request': {
topic: function(authenticate) {
var self = this;
var req = new MockRequest();
var res = new MockResponse();
req.session = {};
req.session.messages = [ 'I exist!' ];
res.redirect = function(url) {
this.location = url;
self.callback(null, req, res);
}

function next(err) {
self.callback(new Error('should not be called'));
}
process.nextTick(function () {
authenticate(req, res, next)
});
},

'should not generate an error' : function(err, req, res) {
assert.isNull(err);
},
'should set user on request' : function(err, req, res) {
assert.isObject(req.user);
assert.equal(req.user.id, '1');
assert.equal(req.user.username, 'jaredhanson');
},
'should set message on request' : function(err, req, res) {
assert.lengthOf(req.session.messages, 2);
assert.equal(req.session.messages[0], 'I exist!');
assert.equal(req.session.messages[1], 'Login complete');
},
'should redirect response' : function(err, req, res) {
assert.equal(res.location, 'http://www.example.com/account');
},
},
},

'with a successful authentication containing info message using boolean message option': {
topic: function() {
var self = this;
Expand Down

0 comments on commit 84d6940

Please sign in to comment.