1.0.0 • Published 8 years ago
passport-stub-es6 v1.0.0
passport-stub
This is a JavaScript (ES6) version of Guilherme J. Tramontina's @gtramontina passport-stub.
Passport.js stub for testing. | Based on Jonathon Kresner's (@jkresner) post.
Written with the idea of being simple to use.
This version works with Express v4.x
Usage
I've been writing my Express API tests with Mocha and Supertest, so here is an example:
var passportStub = require('passport-stub')
, request = require('supertest')
, app = require('../app');
passportStub.install(app);
req = request(app);
describe('GET /admin', function() {
it('responds with 401 if not logged in', function(done){
req.get('/admin').expect(401);
done();
});
it('responds with 200 when logged in', function(done){
passportStub.login({username: 'john.doe'});
req.get('/admin').expect(200);
done();
});
});
The user you log in with can be whatever user your app would expect to deal with. It could be a mongoose model, for example.
Functions
.install(app)
.uninstall()
.login(user)
.logout()
Notes
The code itself is pretty simple, so take a look at it.
License
This is licensed under the feel-free-to-do-whatever-you-want-to-do license.
1.0.0
8 years ago