mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
8973969224
Conflicts: app/coffee/DocOpsManager.coffee test/acceptance/coffee/ApplyingUpdatesToADocTests.coffee test/acceptance/coffee/FlushingDocsTests.coffee test/unit/coffee/DocOpsManager/DocOpsManagerTests.coffee test/unit/coffee/RedisManager/prependDocOpsTests.coffee test/unit/coffee/RedisManager/pushDocOpTests.coffee
55 lines
1.8 KiB
CoffeeScript
55 lines
1.8 KiB
CoffeeScript
sinon = require('sinon')
|
|
chai = require('chai')
|
|
should = chai.should()
|
|
modulePath = "../../../../app/js/DocOpsManager.js"
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
describe "DocOpsManager", ->
|
|
beforeEach ->
|
|
@doc_id = "doc-id"
|
|
@project_id = "project-id"
|
|
@callback = sinon.stub()
|
|
@DocOpsManager = SandboxedModule.require modulePath, requires:
|
|
"./RedisManager": @RedisManager = {}
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
|
"./Metrics": @Metrics =
|
|
Timer: class Timer
|
|
done: sinon.stub()
|
|
"./TrackChangesManager": @TrackChangesManager = {}
|
|
|
|
describe "getPreviousDocOps", ->
|
|
beforeEach ->
|
|
@ops = [ "mock-op-1", "mock-op-2" ]
|
|
@start = 30
|
|
@end = 32
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
@DocOpsManager.getPreviousDocOps @project_id, @doc_id, @start, @end, @callback
|
|
|
|
it "should get the previous doc ops", ->
|
|
@RedisManager.getPreviousDocOps
|
|
.calledWith(@doc_id, @start, @end)
|
|
.should.equal true
|
|
|
|
it "should call the callback with the ops", ->
|
|
@callback.calledWith(null, @ops).should.equal true
|
|
|
|
describe "pushDocOp", ->
|
|
beforeEach ->
|
|
@op = "mock-op"
|
|
@RedisManager.pushDocOp = sinon.stub().callsArgWith(2, null, @version = 42)
|
|
@TrackChangesManager.pushUncompressedHistoryOp = sinon.stub().callsArg(3)
|
|
@DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
|
|
|
|
it "should push the op in to the docOps list", ->
|
|
@RedisManager.pushDocOp
|
|
.calledWith(@doc_id, @op)
|
|
.should.equal true
|
|
|
|
it "should push the op into the pushUncompressedHistoryOp", ->
|
|
@TrackChangesManager.pushUncompressedHistoryOp
|
|
.calledWith(@project_id, @doc_id, @op)
|
|
.should.equal true
|
|
|
|
it "should call the callback with the version", ->
|
|
@callback.calledWith(null, @version).should.equal true
|
|
|