mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
fix getDocVersion and add tests
This commit is contained in:
parent
68e12f4d2d
commit
4f6583bbf2
3 changed files with 78 additions and 2 deletions
|
@ -156,8 +156,9 @@ module.exports = RedisManager =
|
|||
callback null, docLines, version, ranges, pathname, projectHistoryId, unflushedTime, lastUpdatedAt, lastUpdatedBy
|
||||
|
||||
getDocVersion: (doc_id, callback = (error, version, projectHistoryType) ->) ->
|
||||
rclient.mget keys.docVersion(doc_id: doc_id), keys.projectHistoryType(doc_id:doc_id), (error, version, projectHistoryType) ->
|
||||
rclient.mget keys.docVersion(doc_id: doc_id), keys.projectHistoryType(doc_id:doc_id), (error, result) ->
|
||||
return callback(error) if error?
|
||||
[version, projectHistoryType] = result || []
|
||||
version = parseInt(version, 10)
|
||||
callback null, version, projectHistoryType
|
||||
|
||||
|
|
|
@ -135,6 +135,39 @@ describe "Applying updates to a doc", ->
|
|||
done()
|
||||
return null
|
||||
|
||||
describe "when the document is loaded and is using project-history only", ->
|
||||
before (done) ->
|
||||
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
||||
|
||||
MockWebApi.insertDoc @project_id, @doc_id, {lines: @lines, version: @version, projectHistoryType: 'project-history'}
|
||||
DocUpdaterClient.preloadDoc @project_id, @doc_id, (error) =>
|
||||
throw error if error?
|
||||
sinon.spy MockWebApi, "getDocument"
|
||||
DocUpdaterClient.sendUpdate @project_id, @doc_id, @update, (error) ->
|
||||
throw error if error?
|
||||
setTimeout done, 200
|
||||
return null
|
||||
|
||||
after ->
|
||||
MockWebApi.getDocument.restore()
|
||||
|
||||
it "should update the doc", (done) ->
|
||||
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
|
||||
doc.lines.should.deep.equal @result
|
||||
done()
|
||||
return null
|
||||
|
||||
it "should not push any applied updates to the track changes api", (done) ->
|
||||
rclient_history.lrange HistoryKeys.uncompressedHistoryOps({@doc_id}), 0, -1, (error, updates) =>
|
||||
updates.length.should.equal 0
|
||||
done()
|
||||
return null
|
||||
|
||||
it "should push the applied updates to the project history changes api", (done) ->
|
||||
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
|
||||
JSON.parse(updates[0]).op.should.deep.equal @update.op
|
||||
done()
|
||||
return null
|
||||
|
||||
describe "when the document has been deleted", ->
|
||||
describe "when the ops come in a single linear order", ->
|
||||
|
|
|
@ -361,11 +361,12 @@ describe "RedisManager", ->
|
|||
|
||||
describe "with a consistent version", ->
|
||||
beforeEach ->
|
||||
@RedisManager.getDocVersion.withArgs(@doc_id).yields(null, @version - @ops.length)
|
||||
|
||||
|
||||
describe "with project history enabled", ->
|
||||
beforeEach ->
|
||||
@settings.apis.project_history.enabled = true
|
||||
@RedisManager.getDocVersion.withArgs(@doc_id).yields(null, @version - @ops.length)
|
||||
@RedisManager.updateDocument @project_id, @doc_id, @lines, @version, @ops, @ranges, @updateMeta, @callback
|
||||
|
||||
it "should get the current doc version to check for consistency", ->
|
||||
|
@ -446,6 +447,7 @@ describe "RedisManager", ->
|
|||
beforeEach ->
|
||||
@rclient.rpush = sinon.stub()
|
||||
@settings.apis.project_history.enabled = false
|
||||
@RedisManager.getDocVersion.withArgs(@doc_id).yields(null, @version - @ops.length)
|
||||
@RedisManager.updateDocument @project_id, @doc_id, @lines, @version, @ops, @ranges, @updateMeta, @callback
|
||||
|
||||
it "should not push the updates into the project history ops list", ->
|
||||
|
@ -456,6 +458,26 @@ describe "RedisManager", ->
|
|||
.calledWith(null, @doc_update_list_length)
|
||||
.should.equal true
|
||||
|
||||
describe "with a doc using project history only", ->
|
||||
beforeEach ->
|
||||
@RedisManager.getDocVersion.withArgs(@doc_id).yields(null, @version - @ops.length, 'project-history')
|
||||
@RedisManager.updateDocument @project_id, @doc_id, @lines, @version, @ops, @ranges, @updateMeta, @callback
|
||||
|
||||
it "should not push the updates to the track-changes ops list", ->
|
||||
@multi.rpush
|
||||
.calledWith("UncompressedHistoryOps:#{@doc_id}")
|
||||
.should.equal false
|
||||
|
||||
it "should push the updates into the project history ops list", ->
|
||||
@ProjectHistoryRedisManager.queueOps
|
||||
.calledWith(@project_id, JSON.stringify(@ops[0]))
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the project update count only", ->
|
||||
@callback
|
||||
.calledWith(null, undefined, @project_update_list_length)
|
||||
.should.equal true
|
||||
|
||||
describe "with an inconsistent version", ->
|
||||
beforeEach ->
|
||||
@RedisManager.getDocVersion.withArgs(@doc_id).yields(null, @version - @ops.length - 1)
|
||||
|
@ -754,3 +776,23 @@ describe "RedisManager", ->
|
|||
@ProjectHistoryRedisManager.queueRenameEntity
|
||||
.calledWithExactly(@project_id, @projectHistoryId, 'doc', @doc_id, @userId, @update, @callback)
|
||||
.should.equal true
|
||||
|
||||
describe "getDocVersion", ->
|
||||
beforeEach ->
|
||||
@version = 12345
|
||||
|
||||
describe "when the document does not have a project history type set", ->
|
||||
beforeEach ->
|
||||
@rclient.mget = sinon.stub().withArgs("DocVersion:#{@doc_id}", "ProjectHistoryType:#{@doc_id}").callsArgWith(2, null, ["#{@version}"])
|
||||
@RedisManager.getDocVersion @doc_id, @callback
|
||||
|
||||
it "should return the document version and an undefined history type", ->
|
||||
@callback.calledWithExactly(null, @version, undefined).should.equal true
|
||||
|
||||
describe "when the document has a project history type set", ->
|
||||
beforeEach ->
|
||||
@rclient.mget = sinon.stub().withArgs("DocVersion:#{@doc_id}", "ProjectHistoryType:#{@doc_id}").callsArgWith(2, null, ["#{@version}", 'project-history'])
|
||||
@RedisManager.getDocVersion @doc_id, @callback
|
||||
|
||||
it "should return the document version and history type", ->
|
||||
@callback.calledWithExactly(null, @version, 'project-history').should.equal true
|
||||
|
|
Loading…
Reference in a new issue