I\'m using Passport.js for authentication (Facebook strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest for
This example shows how to do the SuperTest part of the testing:
describe('request', function() {
describe('persistent agent', function() {
var agent1 = request.agent();
var agent2 = request.agent();
var agent3 = request.agent();
var agent4 = request.agent();
it('should gain a session on POST', function(done) {
agent3
.post('http://localhost:4000/signin')
.end(function(err, res) {
should.not.exist(err);
res.should.have.status(200);
should.not.exist(res.headers['set-cookie']);
res.text.should.include('dashboard');
done();
});
});
Here's a blog post about it.