TrackChangesControllerTests.coffee 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. chai = require('chai')
  2. chai.should()
  3. sinon = require("sinon")
  4. modulePath = "../../../../app/js/Features/TrackChanges/TrackChangesController"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "TrackChangesController", ->
  7. beforeEach ->
  8. @TrackChangesController = SandboxedModule.require modulePath, requires:
  9. "request" : @request = sinon.stub()
  10. "settings-sharelatex": @settings = {}
  11. "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
  12. describe "proxyToTrackChangesApi", ->
  13. beforeEach ->
  14. @req = { url: "/mock/url", method: "POST" }
  15. @res = "mock-res"
  16. @next = sinon.stub()
  17. @settings.apis =
  18. trackchanges:
  19. url: "http://trackchanges.example.com"
  20. @proxy =
  21. events: {}
  22. pipe: sinon.stub()
  23. on: (event, handler) -> @events[event] = handler
  24. @request.returns @proxy
  25. @TrackChangesController.proxyToTrackChangesApi @req, @res, @next
  26. describe "successfully", ->
  27. it "should call the track changes api", ->
  28. @request
  29. .calledWith({
  30. url: "#{@settings.apis.trackchanges.url}#{@req.url}"
  31. method: @req.method
  32. })
  33. .should.equal true
  34. it "should pipe the response to the client", ->
  35. @proxy.pipe
  36. .calledWith(@res)
  37. .should.equal true
  38. describe "with an error", ->
  39. beforeEach ->
  40. @proxy.events["error"].call(@proxy, @error = new Error("oops"))
  41. it "should pass the error up the call chain", ->
  42. @next.calledWith(@error).should.equal true