From 50fdfec6e8b5ab5f5cbbed034890a22431af9df9 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Wed, 7 Mar 2018 11:18:40 +0000 Subject: [PATCH] add unit tests for project history resync --- .../History/HistoryControllerTests.coffee | 22 +++++++++ .../ProjectEntityUpdateHandlerTests.coffee | 45 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/services/web/test/unit/coffee/History/HistoryControllerTests.coffee b/services/web/test/unit/coffee/History/HistoryControllerTests.coffee index 7dc3c88169..35c512426e 100644 --- a/services/web/test/unit/coffee/History/HistoryControllerTests.coffee +++ b/services/web/test/unit/coffee/History/HistoryControllerTests.coffee @@ -17,6 +17,7 @@ describe "HistoryController", -> "./HistoryManager": @HistoryManager = {} "../Authentication/AuthenticationController": @AuthenticationController "../Project/ProjectDetailsHandler": @ProjectDetailsHandler = {} + "../Project/ProjectEntityUpdateHandler": @ProjectEntityUpdateHandler = {} @settings.apis = trackchanges: enabled: false @@ -199,3 +200,24 @@ describe "HistoryController", -> it "should not return the data with users to the client", -> @res.json.calledWith(@data_with_users).should.equal false + + describe "resyncProject", -> + beforeEach -> + @project_id = 'mock-project-id' + @req = params: Project_id: @project_id + @res = sendStatus: sinon.stub() + @next = sinon.stub() + + @ProjectEntityUpdateHandler.resyncProject = sinon.stub().yields() + + @HistoryController.resyncProject @req, @res, @next + + it "resyncs the project", -> + @ProjectEntityUpdateHandler.resyncProject + .calledWith(@project_id) + .should.equal true + + it "responds with a 204", -> + @res.sendStatus + .calledWith(204) + .should.equal true diff --git a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee index ba40fa32db..06beca3cb3 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee @@ -745,6 +745,51 @@ describe 'ProjectEntityUpdateHandler', -> .calledWith(project_id, userId, @changes, @callback) .should.equal true + describe "resyncProject", -> + beforeEach -> + @ProjectGetter.getProject = sinon.stub().yields(null, @project) + docs = [ + doc: _id: doc_id + path: 'main.tex' + ] + files = [ + file: _id: file_id + path: 'universe.png' + ] + @ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub().yields(null, docs, files) + @FileStoreHandler._buildUrl = (project_id, file_id) -> + "www.filestore.test/#{project_id}/#{file_id}" + @DocumentUpdaterHandler.resyncProject = sinon.stub().yields() + + @ProjectEntityUpdateHandler.resyncProject project_id, @callback + + it 'gets the project', -> + @ProjectGetter.getProject + .calledWith(project_id) + .should.equal true + + it 'gets the entities for the project', -> + @ProjectEntityHandler.getAllEntitiesFromProject + .calledWith(@project) + .should.equal true + + it 'tells the doc updater to sync the project', -> + docs = [ + doc: doc_id + path: 'main.tex' + ] + files = [ + file: file_id + path: 'universe.png' + url: "www.filestore.test/#{project_id}/#{file_id}" + ] + @DocumentUpdaterHandler.resyncProject + .calledWith(project_id, docs, files) + .should.equal true + + it 'calls the callback', -> + @callback.called.should.equal true + describe "_cleanUpEntity", -> beforeEach -> @entity_id = "4eecaffcbffa66588e000009"