Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 19, 2022
1 parent 29a90d6 commit f8a175f
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('http.ServerRequest', function() {
expect(req.session.id).to.equal('2');
});

it('should keep session data', function() {
it('should not keep session data', function() {
expect(req.session.cart).to.be.undefined;
});

Expand Down Expand Up @@ -721,6 +721,61 @@ describe('http.ServerRequest', function() {
});
});

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

var req = new Object();
req.logout = request.logout;
req.isAuthenticated = request.isAuthenticated;
req.isUnauthenticated = request.isUnauthenticated;
req.user = { id: '1', username: 'root' };
req._passport = {};
req._passport.instance = passport;
req._sessionManager = passport._sm;
req.session = { cart: [ '1', '2', ] };
Object.defineProperty(req.session, 'id', { value: '1' });
req.session['passport'] = {};
req.session['passport'].user = '1';
req.session.save = function(cb) {
expect(req.session['passport'].user).to.be.undefined;
process.nextTick(cb);
};
req.session.regenerate = function(cb) {
req.session = { id: '2' };
process.nextTick(cb);
};

var error;

before(function(done) {
req.logout({ keepSessionData: true }, function(err) {
error = err;
done();
});
});

it('should not error', function() {
expect(error).to.be.undefined;
});

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.session['passport'].user).to.be.undefined;
});

it('should keep session data', function() {
expect(req.session.cart).to.deep.equal([ '1', '2' ]);
});
});

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

Expand Down

0 comments on commit f8a175f

Please sign in to comment.