From ffa2e231fdec7e104bf58ca8eaf4a4e720eb7d2b Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 15 Dec 2017 16:11:16 +0000 Subject: [PATCH] Fix up tests --- services/web/config/settings.defaults.coffee | 3 +- .../DocumentUpdaterHandlerTests.coffee | 4 +- .../History/HistoryControllerTests.coffee | 124 ++++++------------ 3 files changed, 47 insertions(+), 84 deletions(-) diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 65a8bf1e91..844bffae3c 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -111,7 +111,8 @@ module.exports = settings = trackchanges: url : "http://localhost:3015" project_history: - enabled: process.env.PROJECT_HISTORY_ENABLED == 'true' or false + sendProjectStructureOps: process.env.PROJECT_HISTORY_ENABLED == 'true' or false + initializeHistoryForNewProjects: process.env.PROJECT_HISTORY_ENABLED == 'true' or false url : "http://localhost:3054" docstore: url : "http://#{process.env['DOCSTORE_HOST'] or 'localhost'}:3016" diff --git a/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee b/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee index 14ccaa3a33..5eb3c057ab 100644 --- a/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee +++ b/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee @@ -393,7 +393,7 @@ describe 'DocumentUpdaterHandler', -> describe "with project history disabled", -> beforeEach -> - @settings.apis.project_history.enabled = false + @settings.apis.project_history.sendProjectStructureOps = false @request.post = sinon.stub() @handler.updateProjectStructure @project_id, @user_id, {}, @callback @@ -406,7 +406,7 @@ describe 'DocumentUpdaterHandler', -> describe "with project history enabled", -> beforeEach -> - @settings.apis.project_history.enabled = true + @settings.apis.project_history.sendProjectStructureOps = true @url = "#{@settings.apis.documentupdater.url}/project/#{@project_id}" @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "") diff --git a/services/web/test/unit/coffee/History/HistoryControllerTests.coffee b/services/web/test/unit/coffee/History/HistoryControllerTests.coffee index e03189526a..3e0464254e 100644 --- a/services/web/test/unit/coffee/History/HistoryControllerTests.coffee +++ b/services/web/test/unit/coffee/History/HistoryControllerTests.coffee @@ -31,7 +31,7 @@ describe "HistoryController", -> describe "for a project with project history", -> beforeEach -> - @ProjectDetailsHandler.getDetails = sinon.stub().callsArgWith(1, null, {overleaf:{history:{display:true}}}) + @ProjectDetailsHandler.getDetails = sinon.stub().callsArgWith(1, null, {overleaf:{history:{id: 42, display:true}}}) @HistoryController.selectHistoryApi @req, @res, @next it "should set the flag for project history to true", -> @@ -57,93 +57,55 @@ describe "HistoryController", -> on: (event, handler) -> @events[event] = handler @request.returns @proxy - describe "with project history enabled", -> + describe "for a project with the project history flag", -> beforeEach -> - @settings.apis.project_history.enabled = true + @req.useProjectHistory = true + @HistoryController.proxyToHistoryApi @req, @res, @next - describe "for a project with the project history flag", -> - beforeEach -> - @req.useProjectHistory = true - @HistoryController.proxyToHistoryApi @req, @res, @next + it "should get the user id", -> + @AuthenticationController.getLoggedInUserId + .calledWith(@req) + .should.equal true - it "should get the user id", -> - @AuthenticationController.getLoggedInUserId - .calledWith(@req) - .should.equal true + it "should call the project history api", -> + @request + .calledWith({ + url: "#{@settings.apis.project_history.url}#{@req.url}" + method: @req.method + headers: + "X-User-Id": @user_id + }) + .should.equal true - it "should call the project history api", -> - @request - .calledWith({ - url: "#{@settings.apis.project_history.url}#{@req.url}" - method: @req.method - headers: - "X-User-Id": @user_id - }) - .should.equal true + it "should pipe the response to the client", -> + @proxy.pipe + .calledWith(@res) + .should.equal true - it "should pipe the response to the client", -> - @proxy.pipe - .calledWith(@res) - .should.equal true - - describe "for a project without the project history flag", -> - beforeEach -> - @req.useProjectHistory = false - @HistoryController.proxyToHistoryApi @req, @res, @next - - it "should get the user id", -> - @AuthenticationController.getLoggedInUserId - .calledWith(@req) - .should.equal true - - it "should call the track changes api", -> - @request - .calledWith({ - url: "#{@settings.apis.trackchanges.url}#{@req.url}" - method: @req.method - headers: - "X-User-Id": @user_id - }) - .should.equal true - - it "should pipe the response to the client", -> - @proxy.pipe - .calledWith(@res) - .should.equal true - - describe "with project history disabled", -> + describe "for a project without the project history flag", -> beforeEach -> - @settings.apis.project_history.enabled = false + @req.useProjectHistory = false + @HistoryController.proxyToHistoryApi @req, @res, @next - describe "for a project with the project history flag", -> - beforeEach -> - @req.useProjectHistory = true - @HistoryController.proxyToHistoryApi @req, @res, @next + it "should get the user id", -> + @AuthenticationController.getLoggedInUserId + .calledWith(@req) + .should.equal true - it "should call the track changes api", -> - @request - .calledWith({ - url: "#{@settings.apis.trackchanges.url}#{@req.url}" - method: @req.method - headers: - "X-User-Id": @user_id - }) - .should.equal true + it "should call the track changes api", -> + @request + .calledWith({ + url: "#{@settings.apis.trackchanges.url}#{@req.url}" + method: @req.method + headers: + "X-User-Id": @user_id + }) + .should.equal true - describe "for a project without the project history flag", -> - beforeEach -> - @req.useProjectHistory = false - @HistoryController.proxyToHistoryApi @req, @res, @next - - it "should call the track changes api", -> - @request - .calledWith({ - url: "#{@settings.apis.trackchanges.url}#{@req.url}" - method: @req.method - headers: - "X-User-Id": @user_id - }) - .should.equal true + it "should pipe the response to the client", -> + @proxy.pipe + .calledWith(@res) + .should.equal true describe "with an error", -> beforeEach -> @@ -156,7 +118,7 @@ describe "HistoryController", -> describe "initializeProject", -> describe "with project history enabled", -> beforeEach -> - @settings.apis.project_history.enabled = true + @settings.apis.project_history.initializeHistoryForNewProjects = true describe "project history returns a successful response", -> beforeEach -> @@ -212,7 +174,7 @@ describe "HistoryController", -> describe "with project history disabled", -> beforeEach -> - @settings.apis.project_history.enabled = false + @settings.apis.project_history.initializeHistoryForNewProjects = false @HistoryController.initializeProject @callback it "should return the callback", ->