Git Product home page Git Product logo

passport-stub's Introduction

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, use passport-stub#0.1.x;
  • For passport#>=0.2.0 and express#<4.0.0, use passport-stub#0.2.0;
  • For express#>=4.0.0 and passport#>=0.2.0, use passport-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.

Bitdeli Badge

passport-stub's People

Contributors

gtramontina avatar tamlyn avatar benwilhelm avatar bitdeli-chef avatar qubyte avatar mortonfox avatar ssbb avatar geyang avatar jperkelens avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.