get template details now includes the markdown description of the project

This commit is contained in:
Henry Oswald 2014-07-16 11:27:47 +01:00
parent c8c0030b7c
commit 91ca726e66
4 changed files with 41 additions and 1 deletions

View file

@ -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

View file

@ -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)->

View file

@ -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)

View file

@ -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()