Skip to content

Commit

Permalink
Improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rwky committed Jul 13, 2019
1 parent 04d0043 commit 06e3b05
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ describe('http.ServerRequest', () => {
});

describe('#login', () => {
describe('passport not in use', () => {
const { req } = setupPassport();
const user = { id: '1', username: 'root' };
delete req._passport;
it('should throw an exception', () => {
expect(() => {
req.logIn(user, () => {});
}).to.throw(Error, 'passport.initialize() middleware not in use');
});
});

describe('not establishing a session', () => {
const { req } = setupPassport();
req._passport.session = {};
Expand Down
61 changes: 61 additions & 0 deletions test/sessionmanager.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

const SessionManager = require('../lib/sessionmanager');


describe('SessionManager', () => {
describe('#constuctor', () => {
it('accept two arguments', () => {
const func = () => { };
const options = { key: 'test' };
const sessionManager = new SessionManager(options, func);
expect(sessionManager._serializeUser).to.equal(func);
expect(sessionManager._key).to.equal('test');
});
it('accept one argument', () => {
const func = () => { };
const sessionManager = new SessionManager(func);
expect(sessionManager._serializeUser).to.equal(func);
expect(sessionManager._key).to.equal('passport');
});
});
describe('#logIn', () => {
const func = (user, req, cb) => {
cb(null, JSON.stringify(user));
};
const sessionManager = new SessionManager(func);
const user = {
username: 'dummy'
};
const req = {
_passport: {}
};
before((done) => {
sessionManager.logIn(req, user, done);
});
it('serializes user', () => {
expect(req.session.passport.user).to.equal('{"username":"dummy"}');
});
});
describe('#logOut', () => {
const func = (user, req, cb) => {
cb(null, JSON.stringify(user));
};
const sessionManager = new SessionManager(func);
const user = {
username: 'dummy'
};
const req = {
_passport: {}
};
before((done) => {
sessionManager.logIn(req, user, () => {
sessionManager.logOut(req, done);
});
});
it('deletes the session', () => {
// eslint-disable-next-line no-unused-expressions
expect(req.session.passport.user).to.undefined;
});
});
});

0 comments on commit 06e3b05

Please sign in to comment.