Update TrackChangesManagerTests -> HistoryManagerTests

This commit is contained in:
James Allen 2016-12-01 16:50:55 +00:00
parent d878dd5758
commit b6c93c718d

View file

@ -1,11 +1,11 @@
SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
require('chai').should()
modulePath = require('path').join __dirname, '../../../../app/js/TrackChangesManager'
modulePath = require('path').join __dirname, '../../../../app/js/HistoryManager'
describe "TrackChangesManager", ->
describe "HistoryManager", ->
beforeEach ->
@TrackChangesManager = SandboxedModule.require modulePath, requires:
@HistoryManager = SandboxedModule.require modulePath, requires:
"request": @request = {}
"settings-sharelatex": @Settings = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
@ -22,7 +22,7 @@ describe "TrackChangesManager", ->
describe "successfully", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 204)
@TrackChangesManager.flushDocChanges @project_id, @doc_id, @callback
@HistoryManager.flushDocChanges @project_id, @doc_id, @callback
it "should send a request to the track changes api", ->
@request.post
@ -35,7 +35,7 @@ describe "TrackChangesManager", ->
describe "when the track changes api returns an error", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 500)
@TrackChangesManager.flushDocChanges @project_id, @doc_id, @callback
@HistoryManager.flushDocChanges @project_id, @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
@ -43,12 +43,12 @@ describe "TrackChangesManager", ->
describe "pushUncompressedHistoryOps", ->
beforeEach ->
@ops = ["mock-ops"]
@TrackChangesManager.flushDocChanges = sinon.stub().callsArg(2)
@HistoryManager.flushDocChanges = sinon.stub().callsArg(2)
describe "pushing the op", ->
beforeEach ->
@WebRedisManager.pushUncompressedHistoryOps = sinon.stub().callsArgWith(3, null, 1)
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
@HistoryManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
it "should push the ops into redis", ->
@WebRedisManager.pushUncompressedHistoryOps
@ -59,16 +59,16 @@ describe "TrackChangesManager", ->
@callback.called.should.equal true
it "should not try to flush the op", ->
@TrackChangesManager.flushDocChanges.called.should.equal false
@HistoryManager.flushDocChanges.called.should.equal false
describe "when we hit a multiple of FLUSH_EVERY_N_OPS ops", ->
beforeEach ->
@WebRedisManager.pushUncompressedHistoryOps =
sinon.stub().callsArgWith(3, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
sinon.stub().callsArgWith(3, null, 2 * @HistoryManager.FLUSH_EVERY_N_OPS)
@HistoryManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
it "should tell the track changes api to flush", ->
@TrackChangesManager.flushDocChanges
@HistoryManager.flushDocChanges
.calledWith(@project_id, @doc_id)
.should.equal true
@ -76,20 +76,20 @@ describe "TrackChangesManager", ->
beforeEach ->
@ops = ["op1", "op2", "op3"]
@WebRedisManager.pushUncompressedHistoryOps =
sinon.stub().callsArgWith(3, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS + 1)
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
sinon.stub().callsArgWith(3, null, 2 * @HistoryManager.FLUSH_EVERY_N_OPS + 1)
@HistoryManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
it "should tell the track changes api to flush", ->
@TrackChangesManager.flushDocChanges
@HistoryManager.flushDocChanges
.calledWith(@project_id, @doc_id)
.should.equal true
describe "when TrackChangesManager errors", ->
describe "when HistoryManager errors", ->
beforeEach ->
@WebRedisManager.pushUncompressedHistoryOps =
sinon.stub().callsArgWith(3, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
@TrackChangesManager.flushDocChanges = sinon.stub().callsArgWith(2, @error = new Error("oops"))
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
sinon.stub().callsArgWith(3, null, 2 * @HistoryManager.FLUSH_EVERY_N_OPS)
@HistoryManager.flushDocChanges = sinon.stub().callsArgWith(2, @error = new Error("oops"))
@HistoryManager.pushUncompressedHistoryOps @project_id, @doc_id, @ops, @callback
it "should log out the error", ->
@logger.error
@ -104,7 +104,7 @@ describe "TrackChangesManager", ->
describe "with no ops", ->
beforeEach ->
@WebRedisManager.pushUncompressedHistoryOps = sinon.stub().callsArgWith(3, null, 1)
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, [], @callback
@HistoryManager.pushUncompressedHistoryOps @project_id, @doc_id, [], @callback
it "should not call WebRedisManager.pushUncompressedHistoryOps", ->
@WebRedisManager.pushUncompressedHistoryOps.called.should.equal false