Skip to content

Commit

Permalink
Move test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Dec 9, 2019
1 parent 380b5c8 commit 5c288ae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
45 changes: 45 additions & 0 deletions test/authenticator.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,51 @@ describe('Authenticator', function() {
});
});

describe('handling a request with instantiated strategy', function() {
function Strategy() {
}
Strategy.prototype.authenticate = function(req) {
var user = { id: '1', username: 'jaredhanson' };
this.success(user);
};

var passport = new Authenticator();

var request, error;

before(function(done) {
chai.connect.use(passport.authenticate(new Strategy()))
.req(function(req) {
request = req;

req.logIn = function(user, options, done) {
this.user = user;
done();
};
})
.next(function(err) {
error = err;
done();
})
.dispatch();
});

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

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

it('should set authInfo', function() {
expect(request.authInfo).to.be.an('object');
expect(Object.keys(request.authInfo)).to.have.length(0);
});
});

});


Expand Down
51 changes: 1 addition & 50 deletions test/authenticator.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* global describe, it, expect, before */
/* jshint expr: true, sub: true */

var Authenticator = require('../lib/authenticator'),
chai = require('chai');
var Authenticator = require('../lib/authenticator');


describe('Authenticator', function() {
Expand Down Expand Up @@ -54,54 +53,6 @@ describe('Authenticator', function() {
});
});

describe('with object strategy', function() {
function Strategy() {
}
Strategy.prototype.authenticate = function(req) {
var user = { id: '1', username: 'jaredhanson' };
this.success(user);
};

var passport = new Authenticator();

var request, error;

before(function(done) {
chai.connect.use(passport.authorize(new Strategy()))
.req(function(req) {
request = req;

req.logIn = function(user, options, done) {
this.user = user;
done();
};
})
.next(function(err) {
error = err;
done();
})
.dispatch();
});

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

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

it('should set account', function() {
expect(request.account).to.be.an('object');
expect(request.account.id).to.equal('1');
expect(request.account.username).to.equal('jaredhanson');
});

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

it('should throw if lacking a name', function() {
function Strategy() {
}
Expand Down

0 comments on commit 5c288ae

Please sign in to comment.