title: Testing Express and Passport OAuth2 with Mocha and Chai
body: <p>I have an app that is using Express and Passport.  I am using the Google OAuth2 Strategy with Passport.  I have a few routes that require a login through this strategy.  </p>
  
  <p>I'm doing integration tests with Mocha and Chai currently, but I'm unsure how to bypass or work with the OAuth2 authentication that is required for some of my routes.  </p>
  
  <p>For instance, here is one of my tests:</p>
  
  <pre><code>it("should list a single item on /items/&lt;id&gt; GET", function(done) {                                                                             
    chai.request(server)
      .get('/items/' + id) 
      .end(function(err, res) {
        res.should.have.status(200);
        res.should.be.json;
        res.body.should.be.a('object');
        res.body.should.have.property('description');
        done();
      }); 
  }); 
  </code></pre>
  
  <p>My route for <code>/items/:id</code></p>
  
  <pre><code>router.get('/items/:id', auth.isLoggedIn, function(req, res) {
    var item = getItem();
    res.json(item);
  });
  </code></pre>
  
  <p><code>/items/:id</code> requires a login.  Is there a way to bypass the login for testing, or mock a user to that my integration testing will work?</p>