           chai.expect(data['grid-user']).to.eql userData
         receiveAction newAction, 'user:info', check, done
         send actionIn, action, payload
-        xhr.respondWith 'GET', "https://noflo-gate.herokuapp.com/authenticate/#{code}", (req) ->
+        mock.respondWith 'GET', "https://noflo-gate.herokuapp.com/authenticate/#{code}", (req) ->
           req.respond 200,
             'Content-Type': 'application/json'
           , JSON.stringify
             token: token
-        xhr.respondWith 'GET', "https://api.flowhub.io/user", (req) ->
+        mock.respondWith 'GET', "https://api.flowhub.io/user", (req) ->
           req.respond 200,
             'Content-Type': 'application/json'
           , JSON.stringify userData
-        do xhr.respond
-        do xhr.respond
+        do mock.respond
+        do mock.respond
   describe 'receiving user:login action', ->
     describe 'with app URL not matching redirect configuration', ->
       it 'should send user:error', (done) ->

          chai.expect(data.message).to.contain 'bad_code_foo'
        receiveAction newAction, 'user:error', check, done
        send actionIn, action, payload
        xhr.respondWith 'GET', "https://noflo-gate.herokuapp.com/authenticate/#{code}", [
          402
        ,
          'Content-Type': 'application/json'
        , JSON.stringify
          error: 'bad_code_foo'
        ]
        do xhr.respond
    describe 'without user and with grant code in URL yielding invalid API token', ->
      xhr = null
      code = null
      token = null
      beforeEach ->
        code = 'oivwehfh24890f84h'
        token = 'niov2o3wnnv4ioufuhh92348fh42q9'
        xhr = sinon.fakeServer.create()
      afterEach ->
        xhr.restore()
      it 'should perform a token exchange and fail at user fetch', (done) ->
        action = 'application:url'
        payload = "https://app.flowhub.io?code=#{code}"

        receiveAction newAction, 'user:error', check, done
        send actionIn, action, payload
    describe 'without user and with invalid grant code in URL', ->
      mock = null
      code = null
      beforeEach ->
        code = 'dj0328hf3d9cq3c'
        mock = sinon.fakeServer.create()
      afterEach ->
        mock.restore()
      it 'should perform a token exchange and fail', (done) ->
        action = 'application:url'
        payload = "https://app.flowhub.io?code=#{code}"
