How to integration test a passport.js Twitter strategy implemented in express.js?

666 views Asked by At

How can you test this as part of a typical Mocha/Supertest implementation?

1

There are 1 answers

1
AudioBubble On BEST ANSWER

I don't know how reliable this is, but it was pretty easy to set up a bogus Twitter account and simulate the flow with Zombie:

describe('GET /auth/twitter', function(){

    it('should redirect to /account', function(done){
        this.timeout(20e3)
        var zombie = new Zombie()
        zombie.visit(url.resolve(YOUR_HOST, '/auth/twitter'), function(err){
            if (err) throw err
            zombie
                .fill('#username_or_email', 'YOUR_USERNAME')
                .fill('#password', 'YOUR_PASSWORD')
                .pressButton('#allow', function(err){
                    if (err) throw err
                    zombie.clickLink('.maintain-context', function(err){
                        if (err) throw err
                        // Signed in! Do some assertions here.
                        return done()
                    })
                })
        })
    })

})