mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
39 lines
1.3 KiB
CoffeeScript
39 lines
1.3 KiB
CoffeeScript
|
SandboxedModule = require('sandboxed-module')
|
||
|
sinon = require('sinon')
|
||
|
require('chai').should()
|
||
|
modulePath = require('path').join __dirname, '../../../../app/js/TrackChangesManager'
|
||
|
|
||
|
describe "TrackChangesManager", ->
|
||
|
beforeEach ->
|
||
|
@TrackChangesManager = SandboxedModule.require modulePath, requires:
|
||
|
"request": @request = {}
|
||
|
"settings-sharelatex": @Settings = {}
|
||
|
@doc_id = "mock-doc-id"
|
||
|
@callback = sinon.stub()
|
||
|
|
||
|
describe "flushDocChanges", ->
|
||
|
beforeEach ->
|
||
|
@Settings.apis =
|
||
|
trackchanges: url: "http://trackchanges.example.com"
|
||
|
|
||
|
describe "successfully", ->
|
||
|
beforeEach ->
|
||
|
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 204)
|
||
|
@TrackChangesManager.flushDocChanges @doc_id, @callback
|
||
|
|
||
|
it "should send a request to the track changes api", ->
|
||
|
@request.post
|
||
|
.calledWith("#{@Settings.apis.trackchanges.url}/doc/#{@doc_id}/flush")
|
||
|
.should.equal true
|
||
|
|
||
|
it "should return the callback", ->
|
||
|
@callback.calledWith(null).should.equal true
|
||
|
|
||
|
describe "when the track changes api returns an error", ->
|
||
|
beforeEach ->
|
||
|
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 500)
|
||
|
@TrackChangesManager.flushDocChanges @doc_id, @callback
|
||
|
|
||
|
it "should return the callback with an error", ->
|
||
|
@callback.calledWith(new Error("track changes api return non-success code: 500")).should.equal true
|