mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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"
|
||||
|
||||
|
@ -20,9 +21,11 @@ describe "Deleting a document", ->
|
|||
@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) ->
|
||||
|
@ -64,6 +67,9 @@ describe "Deleting a document", ->
|
|||
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()]
|
||||
|
@ -97,5 +103,5 @@ describe "Deleting a document", ->
|
|||
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"
|
||||
|
||||
|
@ -40,9 +41,11 @@ describe "Deleting a project", ->
|
|||
}
|
||||
|
||||
sinon.spy MockTrackChangesApi, "flushDoc"
|
||||
sinon.spy MockProjectHistoryApi, "flushProject"
|
||||
|
||||
after ->
|
||||
MockTrackChangesApi.flushDoc.restore()
|
||||
MockProjectHistoryApi.flushProject.restore()
|
||||
|
||||
describe "with documents which have been updated", ->
|
||||
before (done) ->
|
||||
|
@ -89,4 +92,5 @@ describe "Deleting a project", ->
|
|||
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"
|
||||
|
||||
|
@ -27,11 +28,13 @@ describe "Setting a document", ->
|
|||
@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) ->
|
||||
|
@ -90,6 +93,9 @@ describe "Setting a document", ->
|
|||
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?
|
||||
|
|
|
@ -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