mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add tests for fetching and flushing track changes entries to persistence layer
This commit is contained in:
parent
418405e8b9
commit
3ea2e07993
4 changed files with 63 additions and 20 deletions
|
@ -8,5 +8,14 @@ module.exports = TrackChangesManager =
|
|||
changesTracker.track_changes = !!update.meta.tc
|
||||
for op in update.op
|
||||
changesTracker.applyOp(op, { user_id: update.meta?.user_id })
|
||||
{changes, comments} = changesTracker
|
||||
callback null, {changes, comments}
|
||||
|
||||
# Return the minimal data structure needed, since most documents won't have any
|
||||
# changes or comments
|
||||
response = null
|
||||
if changesTracker.changes?.length > 0
|
||||
response ?= {}
|
||||
response.changes = changesTracker.changes
|
||||
if changesTracker.comments?.length > 0
|
||||
response ?= {}
|
||||
response.comments = changesTracker.comments
|
||||
callback null, response
|
|
@ -46,7 +46,7 @@ describe "Track changes", ->
|
|||
throw error if error?
|
||||
setTimeout done, 200
|
||||
|
||||
it "should set the updated track changes entries in redis", (done) ->
|
||||
it "should update the tracked entries", (done) ->
|
||||
DocUpdaterClient.getDoc @project_id, @doc.id, (error, res, data) =>
|
||||
throw error if error?
|
||||
entries = data.track_changes_entries
|
||||
|
@ -55,3 +55,51 @@ describe "Track changes", ->
|
|||
change.metadata.user_id.should.equal @user_id
|
||||
done()
|
||||
|
||||
describe "Loading changes from persistence layer", ->
|
||||
before (done) ->
|
||||
@project_id = DocUpdaterClient.randomId()
|
||||
@user_id = DocUpdaterClient.randomId()
|
||||
@doc = {
|
||||
id: DocUpdaterClient.randomId()
|
||||
lines: ["a123aa"]
|
||||
}
|
||||
@update = {
|
||||
doc: @doc.id
|
||||
op: [{ i: "456", p: 5 }]
|
||||
v: 0
|
||||
meta: { user_id: @user_id, tc: 1 }
|
||||
}
|
||||
MockWebApi.insertDoc @project_id, @doc.id, {
|
||||
lines: @doc.lines
|
||||
version: 0
|
||||
track_changes_entries: {
|
||||
changes: [{
|
||||
op: { i: "123", p: 1 }
|
||||
metadata:
|
||||
user_id: @user_id
|
||||
ts: new Date()
|
||||
}]
|
||||
}
|
||||
}
|
||||
DocUpdaterClient.preloadDoc @project_id, @doc.id, (error) =>
|
||||
throw error if error?
|
||||
DocUpdaterClient.sendUpdate @project_id, @doc.id, @update, (error) ->
|
||||
throw error if error?
|
||||
setTimeout done, 200
|
||||
|
||||
it "should have preloaded the existing changes", (done) ->
|
||||
DocUpdaterClient.getDoc @project_id, @doc.id, (error, res, data) =>
|
||||
throw error if error?
|
||||
{changes} = data.track_changes_entries
|
||||
changes[0].op.should.deep.equal { i: "123", p: 1 }
|
||||
changes[1].op.should.deep.equal { i: "456", p: 5 }
|
||||
done()
|
||||
|
||||
it "should flush the changes to the persistence layer again", (done) ->
|
||||
DocUpdaterClient.flushDoc @project_id, @doc.id, (error) =>
|
||||
throw error if error?
|
||||
MockWebApi.getDocument @project_id, @doc.id, (error, doc) =>
|
||||
{changes} = doc.track_changes_entries
|
||||
changes[0].op.should.deep.equal { i: "123", p: 1 }
|
||||
changes[1].op.should.deep.equal { i: "456", p: 5 }
|
||||
done()
|
||||
|
|
|
@ -72,18 +72,3 @@ module.exports = DocUpdaterClient =
|
|||
|
||||
deleteProject: (project_id, callback = () ->) ->
|
||||
request.del "http://localhost:3003/project/#{project_id}", callback
|
||||
|
||||
setTrackChangesOn: (project_id, callback = () ->) ->
|
||||
request.post {
|
||||
url: "http://localhost:3003/project/#{project_id}/track_changes"
|
||||
json:
|
||||
on: true
|
||||
}, callback
|
||||
|
||||
setTrackChangesOff: (project_id, callback = () ->) ->
|
||||
request.post {
|
||||
url: "http://localhost:3003/project/#{project_id}/track_changes"
|
||||
json:
|
||||
on: false
|
||||
}, callback
|
||||
|
||||
|
|
|
@ -11,10 +11,11 @@ module.exports = MockWebApi =
|
|||
doc.lines ?= []
|
||||
@docs["#{project_id}:#{doc_id}"] = doc
|
||||
|
||||
setDocument: (project_id, doc_id, lines, version, callback = (error) ->) ->
|
||||
setDocument: (project_id, doc_id, lines, version, track_changes_entries, callback = (error) ->) ->
|
||||
doc = @docs["#{project_id}:#{doc_id}"] ||= {}
|
||||
doc.lines = lines
|
||||
doc.version = version
|
||||
doc.track_changes_entries = track_changes_entries
|
||||
callback null
|
||||
|
||||
getDocument: (project_id, doc_id, callback = (error, doc) ->) ->
|
||||
|
@ -31,7 +32,7 @@ module.exports = MockWebApi =
|
|||
res.send 404
|
||||
|
||||
app.post "/project/:project_id/doc/:doc_id", express.bodyParser(), (req, res, next) =>
|
||||
MockWebApi.setDocument req.params.project_id, req.params.doc_id, req.body.lines, req.body.version, (error) ->
|
||||
MockWebApi.setDocument req.params.project_id, req.params.doc_id, req.body.lines, req.body.version, req.body.track_changes_entries, (error) ->
|
||||
if error?
|
||||
res.send 500
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue