|
@@ -25,6 +25,7 @@ describe "DocumentManager", ->
|
|
|
"./UpdateManager": @UpdateManager = {}
|
|
"./UpdateManager": @UpdateManager = {}
|
|
|
"./RangesManager": @RangesManager = {}
|
|
"./RangesManager": @RangesManager = {}
|
|
|
@project_id = "project-id-123"
|
|
@project_id = "project-id-123"
|
|
|
|
|
+ @projectHistoryId = "history-id-123"
|
|
|
@doc_id = "doc-id-123"
|
|
@doc_id = "doc-id-123"
|
|
|
@user_id = 1234
|
|
@user_id = 1234
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
@@ -111,7 +112,7 @@ describe "DocumentManager", ->
|
|
|
describe "getDocAndRecentOps", ->
|
|
describe "getDocAndRecentOps", ->
|
|
|
describe "with a previous version specified", ->
|
|
describe "with a previous version specified", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
|
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, @fromVersion, @callback
|
|
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, @fromVersion, @callback
|
|
|
|
|
|
|
@@ -126,14 +127,14 @@ describe "DocumentManager", ->
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the doc info", ->
|
|
it "should call the callback with the doc info", ->
|
|
|
- @callback.calledWith(null, @lines, @version, @ops, @ranges, @pathname).should.equal true
|
|
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version, @ops, @ranges, @pathname, @projectHistoryId).should.equal true
|
|
|
|
|
|
|
|
it "should time the execution", ->
|
|
it "should time the execution", ->
|
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@Metrics.Timer::done.called.should.equal true
|
|
|
|
|
|
|
|
describe "with no previous version specified", ->
|
|
describe "with no previous version specified", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
|
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, -1, @callback
|
|
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, -1, @callback
|
|
|
|
|
|
|
@@ -146,7 +147,7 @@ describe "DocumentManager", ->
|
|
|
@RedisManager.getPreviousDocOps.called.should.equal false
|
|
@RedisManager.getPreviousDocOps.called.should.equal false
|
|
|
|
|
|
|
|
it "should call the callback with the doc info", ->
|
|
it "should call the callback with the doc info", ->
|
|
|
- @callback.calledWith(null, @lines, @version, [], @ranges, @pathname).should.equal true
|
|
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version, [], @ranges, @pathname, @projectHistoryId).should.equal true
|
|
|
|
|
|
|
|
it "should time the execution", ->
|
|
it "should time the execution", ->
|
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@@ -154,7 +155,7 @@ describe "DocumentManager", ->
|
|
|
describe "getDoc", ->
|
|
describe "getDoc", ->
|
|
|
describe "when the doc exists in Redis", ->
|
|
describe "when the doc exists in Redis", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @unflushedTime)
|
|
|
|
|
|
|
+ @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime)
|
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should get the doc from Redis", ->
|
|
it "should get the doc from Redis", ->
|
|
@@ -163,7 +164,7 @@ describe "DocumentManager", ->
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the doc info", ->
|
|
it "should call the callback with the doc info", ->
|
|
|
- @callback.calledWith(null, @lines, @version, @ranges, @pathname, @unflushedTime, true).should.equal true
|
|
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime, true).should.equal true
|
|
|
|
|
|
|
|
it "should time the execution", ->
|
|
it "should time the execution", ->
|
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@@ -171,7 +172,7 @@ describe "DocumentManager", ->
|
|
|
describe "when the doc does not exist in Redis", ->
|
|
describe "when the doc does not exist in Redis", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null, null, null, null)
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null, null, null, null)
|
|
|
- @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
@RedisManager.putDocInMemory = sinon.stub().yields()
|
|
@RedisManager.putDocInMemory = sinon.stub().yields()
|
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
|
|
@@ -187,11 +188,11 @@ describe "DocumentManager", ->
|
|
|
|
|
|
|
|
it "should set the doc in Redis", ->
|
|
it "should set the doc in Redis", ->
|
|
|
@RedisManager.putDocInMemory
|
|
@RedisManager.putDocInMemory
|
|
|
- .calledWith(@project_id, @doc_id, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the doc info", ->
|
|
it "should call the callback with the doc info", ->
|
|
|
- @callback.calledWith(null, @lines, @version, @ranges, @pathname, null, false).should.equal true
|
|
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version, @ranges, @pathname, @projectHistoryId, null, false).should.equal true
|
|
|
|
|
|
|
|
it "should time the execution", ->
|
|
it "should time the execution", ->
|
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@Metrics.Timer::done.called.should.equal true
|
|
@@ -202,7 +203,7 @@ describe "DocumentManager", ->
|
|
|
@beforeLines = ["before", "lines"]
|
|
@beforeLines = ["before", "lines"]
|
|
|
@afterLines = ["after", "lines"]
|
|
@afterLines = ["after", "lines"]
|
|
|
@ops = [{ i: "foo", p: 4 }, { d: "bar", p: 42 }]
|
|
@ops = [{ i: "foo", p: 4 }, { d: "bar", p: 42 }]
|
|
|
- @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, @pathname, @unflushedTime, true)
|
|
|
|
|
|
|
+ @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime, true)
|
|
|
@DiffCodec.diffAsShareJsOp = sinon.stub().callsArgWith(2, null, @ops)
|
|
@DiffCodec.diffAsShareJsOp = sinon.stub().callsArgWith(2, null, @ops)
|
|
|
@UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null)
|
|
@UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null)
|
|
|
@DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
|
|
@DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
|
|
@@ -402,7 +403,7 @@ describe "DocumentManager", ->
|
|
|
describe "when the doc is in Redis", ->
|
|
describe "when the doc is in Redis", ->
|
|
|
describe "and has changes to be flushed", ->
|
|
describe "and has changes to be flushed", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, Date.now() - 1e9, true)
|
|
|
|
|
|
|
+ @DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @projectHistoryId, @pathname, Date.now() - 1e9, true)
|
|
|
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
|
|
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should get the doc", ->
|
|
it "should get the doc", ->
|
|
@@ -459,11 +460,11 @@ describe "DocumentManager", ->
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
describe "successfully", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @callback
|
|
|
|
|
|
|
+ @DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @projectHistoryId, @callback
|
|
|
|
|
|
|
|
it "should rename the document", ->
|
|
it "should rename the document", ->
|
|
|
@RedisManager.renameDoc
|
|
@RedisManager.renameDoc
|
|
|
- .calledWith(@project_id, @doc_id, @user_id, @update)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @doc_id, @user_id, @update, @projectHistoryId)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
it "should call the callback", ->
|
|
@@ -472,7 +473,7 @@ describe "DocumentManager", ->
|
|
|
describe "resyncDocContents", ->
|
|
describe "resyncDocContents", ->
|
|
|
describe "when doc is loaded in redis", ->
|
|
describe "when doc is loaded in redis", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
|
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
|
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
|
|
|
|
|
|
@@ -483,13 +484,13 @@ describe "DocumentManager", ->
|
|
|
|
|
|
|
|
it "queues a resync doc content update", ->
|
|
it "queues a resync doc content update", ->
|
|
|
@ProjectHistoryRedisManager.queueResyncDocContent
|
|
@ProjectHistoryRedisManager.queueResyncDocContent
|
|
|
- .calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when doc is not loaded in redis", ->
|
|
describe "when doc is not loaded in redis", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
|
|
|
- @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
|
|
|
|
|
|
+ @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
|
|
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
|
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
|
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
|
|
|
|
|
|
@@ -505,5 +506,5 @@ describe "DocumentManager", ->
|
|
|
|
|
|
|
|
it "queues a resync doc content update", ->
|
|
it "queues a resync doc content update", ->
|
|
|
@ProjectHistoryRedisManager.queueResyncDocContent
|
|
@ProjectHistoryRedisManager.queueResyncDocContent
|
|
|
- .calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback)
|
|
|
.should.equal true
|
|
.should.equal true
|