From 61d22f027a2a08209ef222d0ddf3253b247a95d0 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 18 Jan 2016 15:17:48 +0000 Subject: [PATCH] added test for inserting as pack --- .../UpdatesManager/UpdatesManagerTests.coffee | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee b/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee index 299c4ba068..f742499d1b 100644 --- a/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee @@ -51,12 +51,11 @@ describe "UpdatesManager", -> .calledWith(@doc_id) .should.equal true - it "should save the compressed ops", -> + it "should save the compressed ops as a pack", -> @PackManager.insertCompressedUpdates .calledWith(@project_id, @doc_id, null, @compressedUpdates, @temporary) .should.equal true - it "should call the callback", -> @callback.called.should.equal true @@ -98,6 +97,30 @@ describe "UpdatesManager", -> it "should call the callback", -> @callback.called.should.equal true + describe "when the raw ops start where the existing history ends and the history is in a pack", -> + beforeEach -> + @lastCompressedUpdate = {pack: [{ v: 11, op: "compressed-op-11" }], v:11} + @rawUpdates = [{ v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }] + @MongoManager.peekLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate, @lastCompressedUpdate.v) + @UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @temporary, @callback + + it "should look at the last compressed op", -> + @MongoManager.peekLastCompressedUpdate + .calledWith(@doc_id) + .should.equal true + + it "should defer the compression of raw ops to PackManager", -> + @UpdateCompressor.compressRawUpdates + .should.not.be.called + + it "should save the new compressed ops into a pack", -> + @PackManager.insertCompressedUpdates + .calledWith(@project_id, @doc_id, @lastCompressedUpdate, @compressedUpdates, @temporary) + .should.equal true + + it "should call the callback", -> + @callback.called.should.equal true + describe "when some raw ops are passed that have already been compressed", -> beforeEach -> @rawUpdates = [{ v: 10, op: "mock-op-10" }, { v: 11, op: "mock-op-11"}, { v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]