TrackChangesManagerTests.coffee 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../../app/js/TrackChangesManager'
  5. describe "TrackChangesManager", ->
  6. beforeEach ->
  7. @TrackChangesManager = SandboxedModule.require modulePath, requires:
  8. "request": @request = {}
  9. "settings-sharelatex": @Settings = {}
  10. @doc_id = "mock-doc-id"
  11. @callback = sinon.stub()
  12. describe "flushDocChanges", ->
  13. beforeEach ->
  14. @Settings.apis =
  15. trackchanges: url: "http://trackchanges.example.com"
  16. describe "successfully", ->
  17. beforeEach ->
  18. @request.post = sinon.stub().callsArgWith(1, null, statusCode: 204)
  19. @TrackChangesManager.flushDocChanges @doc_id, @callback
  20. it "should send a request to the track changes api", ->
  21. @request.post
  22. .calledWith("#{@Settings.apis.trackchanges.url}/doc/#{@doc_id}/flush")
  23. .should.equal true
  24. it "should return the callback", ->
  25. @callback.calledWith(null).should.equal true
  26. describe "when the track changes api returns an error", ->
  27. beforeEach ->
  28. @request.post = sinon.stub().callsArgWith(1, null, statusCode: 500)
  29. @TrackChangesManager.flushDocChanges @doc_id, @callback
  30. it "should return the callback with an error", ->
  31. @callback.calledWith(new Error("track changes api return non-success code: 500")).should.equal true