passport-stub
v1.1.1
Published
Passport.js stub for testing.
Downloads
10,765
Readme
passport-stub
Passport.js stub for testing – Based on Jonathon Kresner's (@jkresner) post.
Written with the idea of being simple to use.
Usage
I've been writing my Express API tests with Mocha and Supertest, so here is an example:
passportStub = require 'passport-stub'
request = require 'supertest'
app = require '../app'
passportStub.install app
req = request app
describe 'GET /admin', ->
it 'responds with 401 if not logged in', (done) ->
req.get('/admin').expect(401).end done
it 'responds with 200 when logged in', (done) ->
passportStub.login username: 'john.doe'
req.get('/admin').expect(200).end 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
Although I didn't use, I've included a few other functions that might be useful. The code itself is pretty simple, so take a look at it.
This module was written in coffee because that was what I was currently using in a project. Feel free to suggest improvements and even a rewrite in javascript.
Versions
passport-stub
's versions are not backwards compatible, so check this list out (hopefully it won't grow any longer):
- For
passport#<0.2.0
, usepassport-stub#0.1.x
; - For
passport#>=0.2.0
andexpress#<4.0.0
, usepassport-stub#0.2.0
; - For
express#>=4.0.0
andpassport#>=0.2.0
, usepassport-stub#1.0.0
; - Phew!
Bottom line: try to keep your deps updated. :-)
License
This is licensed under the feel-free-to-do-whatever-you-want-to-do license.