TrackChangesManagerTests.coffee 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. chai = require('chai')
  2. chai.should()
  3. sinon = require("sinon")
  4. modulePath = "../../../../app/js/Features/TrackChanges/TrackChangesManager"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "TrackChangesManager", ->
  7. beforeEach ->
  8. @TrackChangesManager = SandboxedModule.require modulePath, requires:
  9. "request" : @request = sinon.stub()
  10. "settings-sharelatex": @settings =
  11. apis:
  12. trackchanges:
  13. url: "trackchanges.sharelatex.com"
  14. "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
  15. @project_id = "project-id-123"
  16. @callback = sinon.stub()
  17. describe "flushProject", ->
  18. describe "with a successful response code", ->
  19. beforeEach ->
  20. @request.post = sinon.stub().callsArgWith(1, null, statusCode: 204, "")
  21. @TrackChangesManager.flushProject @project_id, @callback
  22. it "should flush the project in the track changes api", ->
  23. @request.post
  24. .calledWith("#{@settings.apis.trackchanges.url}/project/#{@project_id}/flush")
  25. .should.equal true
  26. it "should call the callback without an error", ->
  27. @callback.calledWith(null).should.equal true
  28. describe "with a failed response code", ->
  29. beforeEach ->
  30. @request.post = sinon.stub().callsArgWith(1, null, statusCode: 500, "")
  31. @TrackChangesManager.flushProject @project_id, @callback
  32. it "should call the callback with an error", ->
  33. @callback.calledWith(new Error("track-changes api responded with a non-success code: 500")).should.equal true
  34. it "should log the error", ->
  35. @logger.error
  36. .calledWith({
  37. err: new Error("track-changes api responded with a non-success code: 500")
  38. project_id: @project_id
  39. }, "error flushing project in track-changes api")
  40. .should.equal true