Skip to content

Commit 987b191

Browse files
committed
Add tests.
1 parent f8a175f commit 987b191

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/http/request.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,61 @@ describe('http.ServerRequest', function() {
721721
});
722722
});
723723

724+
describe('existing session and not keeping session data', function() {
725+
var passport = new Passport();
726+
727+
var req = new Object();
728+
req.logout = request.logout;
729+
req.isAuthenticated = request.isAuthenticated;
730+
req.isUnauthenticated = request.isUnauthenticated;
731+
req.user = { id: '1', username: 'root' };
732+
req._passport = {};
733+
req._passport.instance = passport;
734+
req._sessionManager = passport._sm;
735+
req.session = { cart: [ '1', '2', ] };
736+
Object.defineProperty(req.session, 'id', { value: '1' });
737+
req.session['passport'] = {};
738+
req.session['passport'].user = '1';
739+
req.session.save = function(cb) {
740+
expect(req.session['passport'].user).to.be.undefined;
741+
process.nextTick(cb);
742+
};
743+
req.session.regenerate = function(cb) {
744+
req.session = { id: '2' };
745+
process.nextTick(cb);
746+
};
747+
748+
var error;
749+
750+
before(function(done) {
751+
req.logout(function(err) {
752+
error = err;
753+
done();
754+
});
755+
});
756+
757+
it('should not error', function() {
758+
expect(error).to.be.undefined;
759+
});
760+
761+
it('should not be authenticated', function() {
762+
expect(req.isAuthenticated()).to.be.false;
763+
expect(req.isUnauthenticated()).to.be.true;
764+
});
765+
766+
it('should clear user', function() {
767+
expect(req.user).to.be.null;
768+
});
769+
770+
it('should clear serialized user', function() {
771+
expect(req.session['passport']).to.be.undefined;
772+
});
773+
774+
it('should keep session data', function() {
775+
expect(req.session.cart).to.be.undefined;
776+
});
777+
});
778+
724779
describe('existing session and keeping session data', function() {
725780
var passport = new Passport();
726781

0 commit comments

Comments
 (0)