mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
add acceptance tests for project history API
This commit is contained in:
parent
04ecd1e7ee
commit
d1f0c4ceae
7 changed files with 73 additions and 26 deletions
2
services/document-updater/Jenkinsfile
vendored
2
services/document-updater/Jenkinsfile
vendored
|
@ -41,7 +41,7 @@ pipeline {
|
|||
stage('Acceptance Tests') {
|
||||
steps {
|
||||
sh 'docker pull sharelatex/acceptance-test-runner'
|
||||
sh 'docker run --rm -v $(pwd):/app sharelatex/acceptance-test-runner'
|
||||
sh 'docker run --rm -e SHARELATEX_ENABLE_PROJECT_HISTORY=true -v $(pwd):/app sharelatex/acceptance-test-runner'
|
||||
}
|
||||
}
|
||||
stage('Package') {
|
||||
|
|
|
@ -15,8 +15,8 @@ module.exports =
|
|||
trackchanges:
|
||||
url: "http://localhost:3015"
|
||||
project_history:
|
||||
enabled: process.env.SHARELATEX_ENABLE_PROJECT_HISTORY == 'true'
|
||||
url: "http://localhost:3054"
|
||||
enabled: true
|
||||
|
||||
redis:
|
||||
realtime:
|
||||
|
|
|
@ -8,6 +8,7 @@ rclient_history = require("redis-sharelatex").createClient(Settings.redis.histor
|
|||
rclient_du = require("redis-sharelatex").createClient(Settings.redis.documentupdater)
|
||||
Keys = Settings.redis.documentupdater.key_schema
|
||||
HistoryKeys = Settings.redis.history.key_schema
|
||||
ProjectHistoryKeys = Settings.redis.project_history.key_schema
|
||||
|
||||
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
||||
MockWebApi = require "./helpers/MockWebApi"
|
||||
|
@ -58,6 +59,11 @@ describe "Applying updates to a doc", ->
|
|||
result.should.equal 1
|
||||
done()
|
||||
|
||||
it "should push the applied updates to the project history changes api", (done) ->
|
||||
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
|
||||
throw error if error?
|
||||
JSON.parse(updates[0]).op.should.deep.equal @update.op
|
||||
done()
|
||||
|
||||
describe "when the document is loaded", ->
|
||||
before (done) ->
|
||||
|
@ -89,6 +95,12 @@ describe "Applying updates to a doc", ->
|
|||
result.should.equal 1
|
||||
done()
|
||||
|
||||
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()
|
||||
|
||||
|
||||
describe "when the document has been deleted", ->
|
||||
describe "when the ops come in a single linear order", ->
|
||||
before (done) ->
|
||||
|
|
|
@ -3,6 +3,7 @@ chai = require("chai")
|
|||
chai.should()
|
||||
|
||||
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
||||
MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
||||
MockWebApi = require "./helpers/MockWebApi"
|
||||
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
||||
|
||||
|
@ -18,11 +19,13 @@ describe "Deleting a document", ->
|
|||
}]
|
||||
v: @version
|
||||
@result = ["one", "one and a half", "two", "three"]
|
||||
|
||||
|
||||
sinon.spy MockTrackChangesApi, "flushDoc"
|
||||
|
||||
sinon.spy MockProjectHistoryApi, "flushProject"
|
||||
|
||||
after ->
|
||||
MockTrackChangesApi.flushDoc.restore()
|
||||
MockProjectHistoryApi.flushProject.restore()
|
||||
|
||||
describe "when the updated doc exists in the doc updater", ->
|
||||
before (done) ->
|
||||
|
@ -60,10 +63,13 @@ describe "Deleting a document", ->
|
|||
.calledWith(@project_id, @doc_id)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
|
||||
it "should flush track changes", ->
|
||||
MockTrackChangesApi.flushDoc.calledWith(@doc_id).should.equal true
|
||||
|
||||
it "should flush project history", ->
|
||||
MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|
||||
|
||||
describe "when the doc is not in the doc updater", ->
|
||||
before (done) ->
|
||||
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
||||
|
@ -93,9 +99,9 @@ describe "Deleting a document", ->
|
|||
.calledWith(@project_id, @doc_id)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
|
||||
it "should flush track changes", ->
|
||||
MockTrackChangesApi.flushDoc.calledWith(@doc_id).should.equal true
|
||||
|
||||
|
||||
|
||||
it "should flush project history", ->
|
||||
MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|
||||
|
|
|
@ -4,6 +4,7 @@ chai.should()
|
|||
async = require "async"
|
||||
|
||||
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
||||
MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
||||
MockWebApi = require "./helpers/MockWebApi"
|
||||
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
||||
|
||||
|
@ -38,11 +39,13 @@ describe "Deleting a project", ->
|
|||
lines: doc.lines
|
||||
version: doc.update.v
|
||||
}
|
||||
|
||||
|
||||
sinon.spy MockTrackChangesApi, "flushDoc"
|
||||
|
||||
sinon.spy MockProjectHistoryApi, "flushProject"
|
||||
|
||||
after ->
|
||||
MockTrackChangesApi.flushDoc.restore()
|
||||
MockProjectHistoryApi.flushProject.restore()
|
||||
|
||||
describe "with documents which have been updated", ->
|
||||
before (done) ->
|
||||
|
@ -84,9 +87,10 @@ describe "Deleting a project", ->
|
|||
), () ->
|
||||
MockWebApi.getDocument.restore()
|
||||
done()
|
||||
|
||||
|
||||
it "should flush each doc in track changes", ->
|
||||
for doc in @docs
|
||||
MockTrackChangesApi.flushDoc.calledWith(doc.id).should.equal true
|
||||
|
||||
|
||||
it "should flush each doc in project history", ->
|
||||
MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|
||||
|
|
|
@ -7,6 +7,7 @@ rclient_du = require("redis-sharelatex").createClient(Settings.redis.documentupd
|
|||
Keys = Settings.redis.documentupdater.key_schema
|
||||
|
||||
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
||||
MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
||||
MockWebApi = require "./helpers/MockWebApi"
|
||||
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
||||
|
||||
|
@ -25,14 +26,16 @@ describe "Setting a document", ->
|
|||
@newLines = ["these", "are", "the", "new", "lines"]
|
||||
@source = "dropbox"
|
||||
@user_id = "user-id-123"
|
||||
|
||||
|
||||
sinon.spy MockTrackChangesApi, "flushDoc"
|
||||
sinon.spy MockProjectHistoryApi, "flushProject"
|
||||
sinon.spy MockWebApi, "setDocument"
|
||||
|
||||
|
||||
after ->
|
||||
MockWebApi.setDocument.restore()
|
||||
MockTrackChangesApi.flushDoc.restore()
|
||||
|
||||
MockProjectHistoryApi.flushProject.restore()
|
||||
MockWebApi.setDocument.restore()
|
||||
|
||||
describe "when the updated doc exists in the doc updater", ->
|
||||
before (done) ->
|
||||
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
||||
|
@ -64,13 +67,13 @@ describe "Setting a document", ->
|
|||
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
|
||||
doc.version.should.equal @version + 2
|
||||
done()
|
||||
|
||||
|
||||
it "should leave the document in redis", (done) ->
|
||||
rclient_du.get Keys.docLines({doc_id: @doc_id}), (error, lines) =>
|
||||
throw error if error?
|
||||
expect(JSON.parse(lines)).to.deep.equal @newLines
|
||||
done()
|
||||
|
||||
|
||||
describe "when the updated doc does not exist in the doc updater", ->
|
||||
before (done) ->
|
||||
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
||||
|
@ -78,7 +81,7 @@ describe "Setting a document", ->
|
|||
DocUpdaterClient.setDocLines @project_id, @doc_id, @newLines, @source, @user_id, false, (error, res, body) =>
|
||||
@statusCode = res.statusCode
|
||||
setTimeout done, 200
|
||||
|
||||
|
||||
it "should return a 204 status code", ->
|
||||
@statusCode.should.equal 204
|
||||
|
||||
|
@ -86,16 +89,19 @@ describe "Setting a document", ->
|
|||
MockWebApi.setDocument
|
||||
.calledWith(@project_id, @doc_id, @newLines)
|
||||
.should.equal true
|
||||
|
||||
|
||||
it "should flush track changes", ->
|
||||
MockTrackChangesApi.flushDoc.calledWith(@doc_id).should.equal true
|
||||
|
||||
|
||||
it "should flush project history", ->
|
||||
MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|
||||
|
||||
it "should remove the document from redis", (done) ->
|
||||
rclient_du.get Keys.docLines({doc_id: @doc_id}), (error, lines) =>
|
||||
throw error if error?
|
||||
expect(lines).to.not.exist
|
||||
done()
|
||||
|
||||
|
||||
describe "with track changes", ->
|
||||
before ->
|
||||
@lines = ["one", "one and a half", "two", "three"]
|
||||
|
@ -123,14 +129,14 @@ describe "Setting a document", ->
|
|||
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, true, (error, res, body) =>
|
||||
@statusCode = res.statusCode
|
||||
setTimeout done, 200
|
||||
|
||||
|
||||
it "should undo the tracked changes", (done) ->
|
||||
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
||||
throw error if error?
|
||||
ranges = data.ranges
|
||||
expect(ranges.changes).to.be.undefined
|
||||
done()
|
||||
|
||||
|
||||
describe "without the undo flag", ->
|
||||
before (done) ->
|
||||
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
||||
|
@ -143,7 +149,7 @@ describe "Setting a document", ->
|
|||
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, false, (error, res, body) =>
|
||||
@statusCode = res.statusCode
|
||||
setTimeout done, 200
|
||||
|
||||
|
||||
it "should not undo the tracked changes", (done) ->
|
||||
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
||||
throw error if error?
|
||||
|
@ -151,4 +157,4 @@ describe "Setting a document", ->
|
|||
expect(ranges.changes.length).to.equal 1
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
express = require("express")
|
||||
app = express()
|
||||
|
||||
module.exports = MockProjectHistoryApi =
|
||||
flushProject: (doc_id, callback = (error) ->) ->
|
||||
callback()
|
||||
|
||||
run: () ->
|
||||
app.post "/project/:project_id/flush", (req, res, next) =>
|
||||
@flushProject req.params.project_id, (error) ->
|
||||
if error?
|
||||
res.send 500
|
||||
else
|
||||
res.send 204
|
||||
|
||||
app.listen 3054, (error) ->
|
||||
throw error if error?
|
||||
|
||||
MockProjectHistoryApi.run()
|
Loading…
Reference in a new issue