From 2c0e9bb89af261f0ae0e49027079a86ce0aefcb9 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Tue, 26 Sep 2017 10:19:30 +0100 Subject: [PATCH] return overleaf details from ProejctsDetailsHandler.getdetails --- .../Project/ProjectDetailsHandler.coffee | 10 +++++++--- .../Project/ProjectDetailsHandlerTests.coffee | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee b/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee index 8234907ff4..5819e03472 100644 --- a/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee @@ -9,7 +9,7 @@ Errors = require("../Errors/Errors") module.exports = ProjectDetailsHandler = getDetails: (project_id, callback)-> - ProjectGetter.getProject project_id, {name:true, description:true, compiler:true, features:true, owner_ref:true}, (err, project)-> + ProjectGetter.getProject project_id, {name:true, description:true, compiler:true, features:true, owner_ref:true, overleaf:true}, (err, project)-> if err? logger.err err:err, project_id:project_id, "error getting project" return callback(err) @@ -21,7 +21,11 @@ module.exports = ProjectDetailsHandler = description: project.description compiler: project.compiler features: user.features - logger.log project_id:project_id, details:details, "getting project details" + + if project.overleaf? + details.overleaf = project.overleaf + + logger.log project_id:project_id, details: details, "getting project details" callback(err, details) getProjectDescription: (project_id, callback)-> @@ -66,4 +70,4 @@ module.exports = ProjectDetailsHandler = logger.log project_id: project_id, level: newAccessLevel, "set public access level" if project_id? && newAccessLevel? and _.include [PublicAccessLevels.READ_ONLY, PublicAccessLevels.READ_AND_WRITE, PublicAccessLevels.PRIVATE], newAccessLevel Project.update {_id:project_id},{publicAccesLevel:newAccessLevel}, (err)-> - callback() \ No newline at end of file + callback() diff --git a/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee index c4c3b3ef07..abb0b505d0 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee @@ -12,7 +12,7 @@ describe 'ProjectDetailsHandler', -> beforeEach -> @project_id = "321l3j1kjkjl" @user_id = "user-id-123" - @project = + @project = name: "project" description: "this is a great project" something:"should not exist" @@ -20,7 +20,7 @@ describe 'ProjectDetailsHandler', -> owner_ref: @user_id @user = features: "mock-features" - @ProjectGetter = + @ProjectGetter = getProjectWithoutDocLines: sinon.stub().callsArgWith(1, null, @project) getProject: sinon.stub().callsArgWith(2, null, @project) @ProjectModel = @@ -42,7 +42,7 @@ describe 'ProjectDetailsHandler', -> describe "getDetails", -> it "should find the project and owner", (done)-> - @handler.getDetails @project_id, (err, details)=> + @handler.getDetails @project_id, (err, details)=> details.name.should.equal @project.name details.description.should.equal @project.description details.compiler.should.equal @project.compiler @@ -50,6 +50,13 @@ describe 'ProjectDetailsHandler', -> assert.equal(details.something, undefined) done() + it "should find overleaf metadata if it exists", (done)-> + @project.overleaf = { id: 'id' } + @handler.getDetails @project_id, (err, details)=> + details.overleaf.should.equal @project.overleaf + assert.equal(details.something, undefined) + done() + it "should return an error for a non-existent project", (done)-> @ProjectGetter.getProject.callsArg(2, null, null) err = new Errors.NotFoundError("project not found") @@ -79,7 +86,7 @@ describe 'ProjectDetailsHandler', -> @handler.getProjectDescription @project_id, (returnedErr, returnedDescription)=> err.should.equal returnedErr description.should.equal returnedDescription - done() + done() describe "setProjectDescription", -> @@ -110,7 +117,7 @@ describe 'ProjectDetailsHandler', -> @handler.renameProject @project_id, @newName, => @tpdsUpdateSender.moveEntity.calledWith({project_id:@project_id, project_name:@project.name, newProjectName:@newName}).should.equal true done() - + it "should not do anything with an invalid name", (done) -> @handler.validateProjectName = sinon.stub().yields(new Error("invalid name")) @handler.renameProject @project_id, @newName, =>