Skip to content

Commit

Permalink
Updated the tests to support changes in chai and mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
mbell8903 committed Nov 15, 2017
1 parent 4fbd185 commit 6bd576f
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 439 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
.idea/
.nyc_output/
build/
reports/

Expand Down
5 changes: 3 additions & 2 deletions lib/strategy.js
Expand Up @@ -45,7 +45,7 @@ var passport = require('passport-strategy'),
* @api public
*/
function Strategy (options, verify) {
if (typeof options == 'function') {
if (typeof options === 'function') {
verify = options;
options = {};
}
Expand All @@ -72,6 +72,7 @@ util.inherits(Strategy, passport.Strategy);
* Authenticate request based on the contents of a form submission.
*
* @param {Object} req
* @param {Object} options
* @api protected
*/
Strategy.prototype.authenticate = function(req, options) {
Expand Down Expand Up @@ -126,4 +127,4 @@ Strategy.prototype.authenticate = function(req, options) {
/**
* Expose `Strategy`.
*/
module.exports = Strategy;
module.exports = Strategy;
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/bootstrap/node.js
@@ -1,5 +1,5 @@
var chai = require('chai');
global.chai = require('chai');

chai.use(require('chai-passport-strategy'));
global.chai.use(require('chai-passport-strategy'));

global.expect = chai.expect;
10 changes: 5 additions & 5 deletions test/package.test.js
Expand Up @@ -2,11 +2,11 @@

var strategy = require('..');

describe('passport-auth-token', function() {
describe('passport-auth-token', function () {

it('should export Strategy constructor directly from package', function() {
expect(strategy).to.be.a('function');
expect(strategy).to.equal(strategy.Strategy);
});
it('should export Strategy constructor directly from package', function () {
expect(strategy).to.be.a('function');
expect(strategy).to.equal(strategy.Strategy);
});

});
112 changes: 55 additions & 57 deletions test/strategy.error.test.js
@@ -1,61 +1,59 @@
/* global describe, it, expect, before */

var chai = require('chai')
, Strategy = require('../lib/strategy');


describe('Strategy', function() {

describe('encountering an error during verification', function() {
var strategy = new Strategy(function(token, done) {
done(new Error('something went wrong'));
});

var err;

before(function(done) {
chai.passport(strategy)
.error(function(e) {
err = e;
done();
})
.req(function(req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should error', function() {
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.equal('something went wrong');
});
});

describe('encountering an exception during verification', function() {
var strategy = new Strategy(function(token, done) {
throw new Error('something went horribly wrong');
});

var err;

before(function(done) {
chai.passport(strategy)
.error(function(e) {
err = e;
done();
})
.req(function(req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should error', function() {
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.equal('something went horribly wrong');
});
});
var Strategy = require('../lib/strategy');

describe('Strategy', function () {

describe('encountering an error during verification', function () {
var strategy = new Strategy(function (token, done) {
done(new Error('something went wrong'));
});

var err;

before(function (done) {
chai.passport.use(strategy)
.error(function (e) {
err = e;
done();
})
.req(function (req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should error', function () {
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.equal('something went wrong');
});
});

describe('encountering an exception during verification', function () {
var strategy = new Strategy(function (token, done) {
throw new Error('something went horribly wrong');
});

var err;

before(function (done) {
chai.passport.use(strategy)
.error(function (e) {
err = e;
done();
})
.req(function (req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should error', function () {
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.equal('something went horribly wrong');
});
});

});
110 changes: 54 additions & 56 deletions test/strategy.fail.test.js
@@ -1,61 +1,59 @@
/* global describe, it, expect, before */
/* jshint expr: true */

var chai = require('chai')
, Strategy = require('../lib/strategy');


describe('Strategy', function() {

describe('failing authentication', function() {
var strategy = new Strategy(function(token, done) {
return done(null, false);
});

var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i) {
info = i;
done();
})
.req(function(req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should fail', function() {
expect(info).to.be.undefined;
});
});

describe('failing authentication with info', function() {
var strategy = new Strategy(function(token, done) {
return done(null, false, { message: 'authentication failed' });
});

var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i) {
info = i;
done();
})
.req(function(req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should fail', function() {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});
var Strategy = require('../lib/strategy');

describe('Strategy', function () {

describe('failing authentication', function () {
var strategy = new Strategy(function (token, done) {
return done(null, false);
});

var info;

before(function (done) {
chai.passport.use(strategy)
.fail(function (i) {
info = i;
done();
})
.req(function (req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should fail', function () {
expect(info).to.be.undefined;
});
});

describe('failing authentication with info', function () {
var strategy = new Strategy(function (token, done) {
return done(null, false, { message: 'authentication failed' });
});

var info;

before(function (done) {
chai.passport.use(strategy)
.fail(function (i) {
info = i;
done();
})
.req(function (req) {
req.body = {};
req.body.token = 'abcdefghijklmnopqrstuvwxyz';
})
.authenticate();
});

it('should fail', function () {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});

});

0 comments on commit 6bd576f

Please sign in to comment.