 
       it 'handles the callback response', ->
         state = { msg: 'msg', args: 'testing' }
-        sinon.stub @giphy.api, 'search', (options, callback) -> callback null, 'response'
+        sinon.stub @giphy.api, 'search', (options, callback) -> callback null, sampleCollectionResult
         sinon.stub @giphy, 'sendResponse'
+        sinon.spy @giphy, 'getRandomResult'
         @giphy.getSearchUri state
         @giphy.sendResponse.should.have.been.called.once
         @giphy.sendResponse.should.have.been.calledWith state
+        @giphy.getRandomResult.should.have.been.called.once
+        @giphy.getRandomResult.should.have.been.calledWith sampleCollectionResult.data, sinon.match.func
         @giphy.api.search.restore()
         @giphy.sendResponse.restore()
+        @giphy.getRandomResult.restore()
         should.exist state.uri
+        state.uri.should.eql sampleUri
+
+      it 'calls getRandomUri for empty args', ->
+        sinon.spy @giphy, 'getRandomUri'
+        @giphy.getSearchUri {}
+        @giphy.getSearchUri { args: null }
+        @giphy.getSearchUri { args: '' }
+        @giphy.getRandomUri.should.have.callCount 3
+        @giphy.getRandomUri.restore()
 
       it 'handles errors in the callback', ->
         state = { msg: 'msg', args: 'testing' }

        should.exist state.options
        state.options.should.eql { test1: 1, test3: 'test3' }

    describe '.getSearchUri', ->
      it 'searches using args', ->
        state = { args: 'testing' }


# this allows us to instrument the internal Giphy instance
global.EXPOSE_INSTANCE = true

sampleUri = 'http://giphy.com/example.gif'

sampleCollectionResult = {
  data: [
    {
      images: {
        original: {
          url: sampleUri
        }
      }
    },
  ]
}

testHubot = (spy, input, args) ->
  [callback, other, ...] = spy
