From 5b757ac7ab61c256dfe675fb6a147ec9e79485d4 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 8 Apr 2014 14:34:03 +0100 Subject: [PATCH] moved delete project from old proj controller to new one with test --- .../Features/Project/ProjectController.coffee | 16 ++++++++ services/web/app/coffee/router.coffee | 7 ++-- .../Project/ProjectControllerTests.coffee | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 services/web/app/coffee/Features/Project/ProjectController.coffee create mode 100644 services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee new file mode 100644 index 0000000000..2825d8c12c --- /dev/null +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -0,0 +1,16 @@ +logger = require("logger-sharelatex") +projectDeleter = require("./ProjectDeleter") + + + + +module.exports = + + deleteProject: (req, res)-> + project_id = req.params.Project_id + logger.log project_id:project_id, "deleting project" + projectDeleter.deleteProject project_id, (err)-> + if err? + res.send 500 + else + res.send 200 \ No newline at end of file diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 01fd6cc489..ff8f24a304 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -1,7 +1,8 @@ UserController = require('./controllers/UserController') AdminController = require('./Features/ServerAdmin/AdminController') HomeController = require('./Features/StaticPages/HomeController') -ProjectController = require("./controllers/ProjectController") +OldProjectController = require("./controllers/ProjectController") +ProjectController = require("./Features/Project/ProjectController") ProjectApiController = require("./Features/Project/ProjectApiController") InfoController = require('./Features/StaticPages/InfoController') SpellingController = require('./Features/Spelling/SpellingController') @@ -45,7 +46,7 @@ module.exports = class Router constructor: (app, io, socketSessions)-> app.use(app.router) - Project = new ProjectController() + Project = new OldProjectController() app.get '/', HomeController.index @@ -109,7 +110,7 @@ module.exports = class Router ), SecurityManager.requestCanAccessProject, CompileController.getFileFromClsi app.del "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles - app.del '/Project/:Project_id', SecurityManager.requestIsOwner, Project.deleteProject + app.del '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, Project.cloneProject app.post '/Project/:Project_id/snapshot', SecurityManager.requestCanModifyProject, versioningController.takeSnapshot diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee new file mode 100644 index 0000000000..752d95ff6d --- /dev/null +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -0,0 +1,37 @@ +should = require('chai').should() +SandboxedModule = require('sandboxed-module') +assert = require('assert') +path = require('path') +sinon = require('sinon') +modulePath = path.join __dirname, "../../../../app/js/Features/Project/ProjectController" +expect = require("chai").expect + +describe "ProjectController", -> + + beforeEach -> + + @settings = {} + @ProjectDeleter = + deleteProject: sinon.stub().callsArgWith(1) + @ProjectController = SandboxedModule.require modulePath, requires: + "settings-sharelatex":@settings + "logger-sharelatex": log:-> + "./ProjectDeleter": @ProjectDeleter + + + @project_id = "123213jlkj9kdlsaj" + @req = + params: + Project_id: @project_id + @res = {} + + describe "deleteProject", -> + + it "should tell the project deleter", (done)-> + + @res.send = (code)=> + @ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true + code.should.equal 200 + done() + @ProjectController.deleteProject @req, @res +