From 91ca726e66ae0de308af56b58b500da9a6a49743 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 16 Jul 2014 11:27:47 +0100 Subject: [PATCH] get template details now includes the markdown description of the project --- .../Project/ProjectDetailsHandler.coffee | 3 +++ .../Templates/TemplatesController.coffee | 6 +++++- .../Project/ProjectDetailsHandlerTests.coffee | 20 +++++++++++++++++++ .../Templates/TemplatesControllerTests.coffee | 13 ++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee b/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee index 500823cd03..7c7cd8ada3 100644 --- a/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee @@ -22,6 +22,9 @@ module.exports = logger.log project_id:project_id, details:details, "getting project details" callback(err, details) + getProjectDescription: (project_id, callback)-> + Project.find _id:project_id, "description", callback + setProjectDescription: (project_id, description, callback)-> conditions = _id:project_id update = description:description diff --git a/services/web/app/coffee/Features/Templates/TemplatesController.coffee b/services/web/app/coffee/Features/Templates/TemplatesController.coffee index d71b93d74e..11a78cdb12 100644 --- a/services/web/app/coffee/Features/Templates/TemplatesController.coffee +++ b/services/web/app/coffee/Features/Templates/TemplatesController.coffee @@ -1,6 +1,7 @@ path = require('path') ProjectUploadManager = require('../Uploads/ProjectUploadManager') ProjectOptionsHandler = require("../Project/ProjectOptionsHandler") +ProjectDetailsHandler = require('../Project/ProjectDetailsHandler') TemplatesPublisher = require("./TemplatesPublisher") settings = require('settings-sharelatex') fs = require('fs') @@ -46,7 +47,10 @@ module.exports = TemplatesPublisher.getTemplateDetails user_id, project_id, (err, details)-> if err? logger.err err:err, user_id:user_id, project_id:project_id, "something went wrong getting template details" - callback(err, details) + return callback(err) + ProjectDetailsHandler.getProjectDescription project_id, (err, description)-> + details.description = description + callback(err, details) setCompiler = (project_id, compiler, callback)-> diff --git a/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee index 986be9d629..22e61b32e6 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee @@ -23,6 +23,7 @@ describe 'Project details handler', -> getProject: sinon.stub().callsArgWith(2, null, @project) @ProjectModel = update: sinon.stub() + find: sinon.stub() @UserGetter = getUser: sinon.stub().callsArgWith(1, null, @user) @tpdsUpdateSender = @@ -54,6 +55,23 @@ describe 'Project details handler', -> err.should.equal error done() + describe "getProjectDescription", -> + + it "should make a call to mongo just for the description", (done)-> + @ProjectModel.find.callsArgWith(2) + @handler.getProjectDescription @project_id, (err, description)=> + @ProjectModel.find.calledWith({_id:@project_id}, "description").should.equal true + done() + + it "should return what the mongo call returns", (done)-> + err = "error" + description = "cool project" + @ProjectModel.find.callsArgWith(2, err, description) + @handler.getProjectDescription @project_id, (returnedErr, returnedDescription)=> + err.should.equal returnedErr + description.should.equal returnedDescription + done() + describe "setProjectDescription", -> beforeEach -> @@ -65,6 +83,8 @@ describe 'Project details handler', -> @ProjectModel.update.calledWith({_id:@project_id}, {description:@description}).should.equal true done() + + describe "renameProject", -> beforeEach -> @ProjectModel.update.callsArgWith(2) diff --git a/services/web/test/UnitTests/coffee/Templates/TemplatesControllerTests.coffee b/services/web/test/UnitTests/coffee/Templates/TemplatesControllerTests.coffee index a3c8233382..f147f6a824 100644 --- a/services/web/test/UnitTests/coffee/Templates/TemplatesControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Templates/TemplatesControllerTests.coffee @@ -25,9 +25,12 @@ describe 'TemplatesController', -> publish: sinon.stub() unpublish:sinon.stub() getTemplateDetails: sinon.stub() + @ProjectDetailsHandler = + getProjectDescription:sinon.stub() @controller = SandboxedModule.require modulePath, requires: '../Uploads/ProjectUploadManager':@ProjectUploadManager '../Project/ProjectOptionsHandler':@ProjectOptionsHandler + '../Project/ProjectDetailsHandler':@ProjectDetailsHandler './TemplatesPublisher':@TemplatesPublisher "logger-sharelatex": log:-> @@ -138,6 +141,9 @@ describe 'TemplatesController', -> describe 'getTemplateDetails', -> + beforeEach -> + @description = "this project is nice" + @ProjectDetailsHandler.getProjectDescription.callsArgWith(1, null, @description) it "should return an error the templatePublisher", (done)-> error = "error" @@ -152,3 +158,10 @@ describe 'TemplatesController', -> @controller.getTemplateDetails @user_id, @project_id, (err, passedDetails)=> details.should.equal passedDetails done() + + it "should get the template description", (done)-> + @TemplatesPublisher.getTemplateDetails.callsArgWith(2, null, {}) + @controller.getTemplateDetails @user_id, @project_id, (err, passedDetails)=> + passedDetails.description.should.equal @description + done() +