|
@@ -9,20 +9,20 @@ describe "HistoryManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@HistoryManager = SandboxedModule.require modulePath, requires:
|
|
@HistoryManager = SandboxedModule.require modulePath, requires:
|
|
|
"./UpdateCompressor": @UpdateCompressor = {}
|
|
"./UpdateCompressor": @UpdateCompressor = {}
|
|
|
- "./mongojs" : {}
|
|
|
|
|
|
|
+ "./MongoManager" : @MongoManager = {}
|
|
|
"logger-sharelatex": { log: sinon.stub() }
|
|
"logger-sharelatex": { log: sinon.stub() }
|
|
|
@doc_id = "doc-id-123"
|
|
@doc_id = "doc-id-123"
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
|
|
|
|
|
|
describe "when there are no raw ops", ->
|
|
describe "when there are no raw ops", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @HistoryManager.popLastCompressedUpdate = sinon.stub()
|
|
|
|
|
- @HistoryManager.insertCompressedUpdates = sinon.stub()
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate = sinon.stub()
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates = sinon.stub()
|
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, [], @callback
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, [], @callback
|
|
|
|
|
|
|
|
it "should not need to access the database", ->
|
|
it "should not need to access the database", ->
|
|
|
- @HistoryManager.popLastCompressedUpdate.called.should.equal false
|
|
|
|
|
- @HistoryManager.insertCompressedUpdates.called.should.equal false
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate.called.should.equal false
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates.called.should.equal false
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
it "should call the callback", ->
|
|
|
@callback.called.should.equal true
|
|
@callback.called.should.equal true
|
|
@@ -32,13 +32,13 @@ describe "HistoryManager", ->
|
|
|
@rawUpdates = ["mock-raw-op-1", "mock-raw-op-2"]
|
|
@rawUpdates = ["mock-raw-op-1", "mock-raw-op-2"]
|
|
|
@compressedUpdates = ["mock-compressed-op"]
|
|
@compressedUpdates = ["mock-compressed-op"]
|
|
|
|
|
|
|
|
- @HistoryManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
|
|
|
|
|
- @HistoryManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
|
|
|
|
|
|
|
it "should try to pop the last compressed op", ->
|
|
it "should try to pop the last compressed op", ->
|
|
|
- @HistoryManager.popLastCompressedUpdate
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate
|
|
|
.calledWith(@doc_id)
|
|
.calledWith(@doc_id)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
@@ -48,7 +48,7 @@ describe "HistoryManager", ->
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should save the compressed ops", ->
|
|
it "should save the compressed ops", ->
|
|
|
- @HistoryManager.insertCompressedUpdates
|
|
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates
|
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
@@ -61,13 +61,13 @@ describe "HistoryManager", ->
|
|
|
@lastCompressedUpdate = "mock-last-compressed-op-0"
|
|
@lastCompressedUpdate = "mock-last-compressed-op-0"
|
|
|
@compressedUpdates = ["mock-compressed-op-1"]
|
|
@compressedUpdates = ["mock-compressed-op-1"]
|
|
|
|
|
|
|
|
- @HistoryManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate)
|
|
|
|
|
- @HistoryManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate)
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
|
@HistoryManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
|
|
|
|
|
|
|
it "should try to pop the last compressed op", ->
|
|
it "should try to pop the last compressed op", ->
|
|
|
- @HistoryManager.popLastCompressedUpdate
|
|
|
|
|
|
|
+ @MongoManager.popLastCompressedUpdate
|
|
|
.calledWith(@doc_id)
|
|
.calledWith(@doc_id)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
@@ -77,7 +77,7 @@ describe "HistoryManager", ->
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should save the compressed ops", ->
|
|
it "should save the compressed ops", ->
|
|
|
- @HistoryManager.insertCompressedUpdates
|
|
|
|
|
|
|
+ @MongoManager.insertCompressedUpdates
|
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|