diff --git a/services/track-changes/app.coffee b/services/track-changes/app.coffee index a0b6f3d5b3..7489701712 100644 --- a/services/track-changes/app.coffee +++ b/services/track-changes/app.coffee @@ -10,12 +10,14 @@ app = express() app.use express.logger() -app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushUpdatesWithLock +app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushDoc app.get "/project/:project_id/doc/:doc_id/diff", HttpController.getDiff app.get "/project/:project_id/updates", HttpController.getUpdates +app.post "/project/:project_id/flush", HttpController.flushProject + app.post "/project/:project_id/doc/:doc_id/version/:version/restore", HttpController.restore app.get "/status", (req, res, next) -> diff --git a/services/track-changes/app/coffee/HttpController.coffee b/services/track-changes/app/coffee/HttpController.coffee index abc2226fc5..71df05a8f8 100644 --- a/services/track-changes/app/coffee/HttpController.coffee +++ b/services/track-changes/app/coffee/HttpController.coffee @@ -4,14 +4,21 @@ RestoreManager = require "./RestoreManager" logger = require "logger-sharelatex" module.exports = HttpController = - flushUpdatesWithLock: (req, res, next = (error) ->) -> + flushDoc: (req, res, next = (error) ->) -> doc_id = req.params.doc_id project_id = req.params.project_id - logger.log doc_id: doc_id, "compressing doc history" + logger.log project_id: project_id, doc_id: doc_id, "compressing doc history" UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) -> return next(error) if error? res.send 204 + flushProject: (req, res, next = (error) ->) -> + project_id = req.params.project_id + logger.log project_id: project_id, "compressing project history" + UpdatesManager.processUncompressedUpdatesForProject project_id, (error) -> + return next(error) if error? + res.send 204 + getDiff: (req, res, next = (error) ->) -> doc_id = req.params.doc_id project_id = req.params.project_id diff --git a/services/track-changes/test/acceptance/coffee/helpers/TrackChangesClient.coffee b/services/track-changes/test/acceptance/coffee/helpers/TrackChangesClient.coffee index dea3a885d5..de75cce0b0 100644 --- a/services/track-changes/test/acceptance/coffee/helpers/TrackChangesClient.coffee +++ b/services/track-changes/test/acceptance/coffee/helpers/TrackChangesClient.coffee @@ -4,17 +4,24 @@ rclient = require("redis").createClient() # Only works locally for now module.exports = TrackChangesClient = flushAndGetCompressedUpdates: (project_id, doc_id, callback = (error, updates) ->) -> - TrackChangesClient.flushUpdates project_id, doc_id, (error) -> + TrackChangesClient.flushDoc project_id, doc_id, (error) -> return callback(error) if error? TrackChangesClient.getCompressedUpdates doc_id, callback - flushUpdates: (project_id, doc_id, callback = (error) ->) -> + flushDoc: (project_id, doc_id, callback = (error) ->) -> request.post { url: "http://localhost:3015/project/#{project_id}/doc/#{doc_id}/flush" }, (error, response, body) => response.statusCode.should.equal 204 callback(error) + flushProject: (project_id, callback = (error) ->) -> + request.post { + url: "http://localhost:3015/project/#{project_id}/flush" + }, (error, response, body) => + response.statusCode.should.equal 204 + callback(error) + getCompressedUpdates: (doc_id, callback = (error, updates) ->) -> db.docHistory .find(doc_id: ObjectId(doc_id)) diff --git a/services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee b/services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee index 4caa1b83ef..f756cbb0e6 100644 --- a/services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee +++ b/services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee @@ -18,7 +18,7 @@ describe "HttpController", -> @user_id = "mock-user-123" @now = Date.now() - describe "flushUpdatesWithLock", -> + describe "flushDoc", -> beforeEach -> @req = params: @@ -27,7 +27,7 @@ describe "HttpController", -> @res = send: sinon.stub() @UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2) - @HttpController.flushUpdatesWithLock @req, @res, @next + @HttpController.flushDoc @req, @res, @next it "should process the updates", -> @UpdatesManager.processUncompressedUpdatesWithLock @@ -37,6 +37,25 @@ describe "HttpController", -> it "should return a success code", -> @res.send.calledWith(204).should.equal true + describe "flushProject", -> + beforeEach -> + @req = + params: + project_id: @project_id + @res = + send: sinon.stub() + @UpdatesManager.processUncompressedUpdatesForProject = sinon.stub().callsArg(1) + @HttpController.flushProject @req, @res, @next + + it "should process the updates", -> + @UpdatesManager.processUncompressedUpdatesForProject + .calledWith(@project_id) + .should.equal true + + it "should return a success code", -> + @res.send.calledWith(204).should.equal true + + describe "getDiff", -> beforeEach -> @from = 42