From d79d6b4ede8594d8d8e6a9c0d01b254e47195be8 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 22 Jan 2018 16:25:11 +0000 Subject: [PATCH] Fix call of UpdateMerger.deleteUpdate in TpdsController.deleteProjectContents --- .../ThirdPartyDataStore/TpdsController.coffee | 2 +- .../acceptance/coffee/TpdsUpdateTests.coffee | 37 +++++++++++++++++++ .../TpdsControllerTests.coffee | 4 +- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 services/web/test/acceptance/coffee/TpdsUpdateTests.coffee diff --git a/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee b/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee index eed57ec3f7..9dcce6e9c8 100644 --- a/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee +++ b/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee @@ -54,7 +54,7 @@ module.exports = path = "/" + req.params[0] # UpdateMerger expects leading slash source = req.headers["x-sl-update-source"] or "unknown" logger.log project_id: project_id, path: path, source: source, "received project contents delete request" - UpdateMerger.deleteUpdate project_id, path, source, (error) -> + UpdateMerger.deleteUpdate null, project_id, path, source, (error) -> return next(error) if error? res.sendStatus(200) diff --git a/services/web/test/acceptance/coffee/TpdsUpdateTests.coffee b/services/web/test/acceptance/coffee/TpdsUpdateTests.coffee new file mode 100644 index 0000000000..201d2fc3f5 --- /dev/null +++ b/services/web/test/acceptance/coffee/TpdsUpdateTests.coffee @@ -0,0 +1,37 @@ +expect = require("chai").expect +ProjectGetter = require "../../../app/js/Features/Project/ProjectGetter.js" +request = require "./helpers/request" +User = require "./helpers/User" + +describe "TpdsUpdateTests", -> + before (done) -> + @owner = new User() + @owner.login (error) => + throw error if error? + @owner.createProject "test-project", {template: "example"}, (error, project_id) => + throw error if error? + @project_id = project_id + done() + + describe "deleting a file", -> + before (done) -> + request { + method: "DELETE" + url: "/project/#{@project_id}/contents/main.tex" + auth: + username: "sharelatex" + password: "password" + sendImmediately: true + }, (error, response, body) -> + throw error if error? + expect(response.statusCode).to.equal 200 + done() + + it "should have deleted the file", (done) -> + ProjectGetter.getProject @project_id, (error, [project]) -> + throw error if error? + projectFolder = project.rootFolder[0] + for doc in projectFolder.docs + if doc.name == "main.tex" + throw new Error("expected main.tex to have been deleted") + done() \ No newline at end of file diff --git a/services/web/test/unit/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee b/services/web/test/unit/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee index 974b2e9329..ba5c507cfb 100644 --- a/services/web/test/unit/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee +++ b/services/web/test/unit/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee @@ -103,7 +103,7 @@ describe 'TpdsController', -> describe 'deleteProjectContents', -> beforeEach -> - @UpdateMerger.deleteUpdate = sinon.stub().callsArg(3) + @UpdateMerger.deleteUpdate = sinon.stub().callsArg(4) @req = params: 0: @path = "chapters/main.tex" @@ -119,7 +119,7 @@ describe 'TpdsController', -> it "should delete the file", -> @UpdateMerger.deleteUpdate - .calledWith(@project_id, "/" + @path, @source) + .calledWith(null, @project_id, "/" + @path, @source) .should.equal true it "should return a success", ->