TrackChangesManagerTests.coffee 2.2 KB

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