Skip to content

Commit

Permalink
Port test cases to mocha.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jan 23, 2014
1 parent 56f138c commit 270c6f4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/http/request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ vows.describe('HttpServerRequest').addBatch({
},
},

// OK
'request to login without a session and no callback': {
topic: function() {
var self = this;
Expand Down Expand Up @@ -250,6 +251,7 @@ vows.describe('HttpServerRequest').addBatch({
},
},

// OK
'request with a login session': {
topic: function() {
var req = new http.IncomingMessage();
Expand Down Expand Up @@ -279,6 +281,7 @@ vows.describe('HttpServerRequest').addBatch({
},
},

// OK
'request with a login session using a custom user property': {
topic: function() {
var req = new http.IncomingMessage();
Expand Down
85 changes: 85 additions & 0 deletions test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@ describe('http.ServerRequest', function() {
});
});

describe('not establishing a session and invoked without a callback', function() {
var passport = new Passport();

var req = new http.IncomingMessage();
req._passport = {};
req._passport.instance = passport;
req._passport.session = {};

var user = { id: '1', username: 'root' };
req.login(user, { session: false });

it('should be authenticated', function() {
expect(req.isAuthenticated()).to.be.true;
expect(req.isUnauthenticated()).to.be.false;
});

it('should set user', function() {
expect(req.user).to.be.an('object');
expect(req.user.id).to.equal('1');
expect(req.user.username).to.equal('root');
});

it('should not serialize user', function() {
expect(req._passport.session.user).to.be.undefined;
});
});

describe('establishing a session', function() {
var passport = new Passport();
passport.serializeUser(function(user, done) {
Expand Down Expand Up @@ -245,4 +272,62 @@ describe('http.ServerRequest', function() {

});


describe('#logout', function() {

describe('existing session', function() {
var passport = new Passport();

var req = new http.IncomingMessage();
req.user = { id: '1', username: 'root' };
req._passport = {};
req._passport.instance = passport;
req._passport.session = {};
req._passport.session.user = '1';

req.logout();

it('should not be authenticated', function() {
expect(req.isAuthenticated()).to.be.false;
expect(req.isUnauthenticated()).to.be.true;
});

it('should clear user', function() {
expect(req.user).to.be.null;
});

it('should clear serialized user', function() {
expect(req._passport.session.user).to.be.undefined;
});
});

describe('existing session and clearing custom user property', function() {
var passport = new Passport();

var req = new http.IncomingMessage();
req.currentUser = { id: '1', username: 'root' };
req._passport = {};
req._passport.instance = passport;
req._passport.instance._userProperty = 'currentUser';
req._passport.session = {};
req._passport.session.user = '1';

req.logout();

it('should not be authenticated', function() {
expect(req.isAuthenticated()).to.be.false;
expect(req.isUnauthenticated()).to.be.true;
});

it('should clear user', function() {
expect(req.currentUser).to.be.null;
});

it('should clear serialized user', function() {
expect(req._passport.session.user).to.be.undefined;
});
});

});

});

0 comments on commit 270c6f4

Please sign in to comment.