require('../../src/util/log').logtoConsole = false;

checkBackend = ()->
  ProxyDispatcher = require '../../src/lib/dispatcher/proxy_dispatcher'
  tryExec = ()->
    theDispatcher = new ProxyDispatcher;

  tryExec.should.throw();

  tryExec = ()->
    theDispatcher = new ProxyDispatcher backend: "backend";

  tryExec.should.not.throw();
  
pipeRequest = ()->
  backendMock = mock ['pipe']
  backendMock.modify 'pipe', takes: [{}, "res"]
  ProxyDispatcher = require '../../src/lib/dispatcher/proxy_dispatcher'
  theDispatcher = new ProxyDispatcher backend: backendMock

  theDispatcher.dispatch {method:'get',url:'/something'}, "res", ->

  backendMock.isCalled("pipe").should.be.ok

describe 'Proxy dispatcher', ->
  it 'should check for backend', checkBackend
  it 'should pipe requests to backend', pipeRequest