Return features along with project details

This commit is contained in:
James Allen 2014-03-28 12:47:15 +00:00
parent 31f39dada1
commit 6318d9ace1
2 changed files with 30 additions and 21 deletions

View file

@ -1,4 +1,5 @@
ProjectGetter = require("./ProjectGetter") ProjectGetter = require("./ProjectGetter")
UserGetter = require("../User/UserGetter")
Project = require('../../models/Project').Project Project = require('../../models/Project').Project
logger = require("logger-sharelatex") logger = require("logger-sharelatex")
@ -9,10 +10,13 @@ module.exports =
if err? if err?
logger.err err:err, project_id:project_id, "error getting project" logger.err err:err, project_id:project_id, "error getting project"
return callback(err) return callback(err)
UserGetter.getUser project.owner_ref, (err, user) ->
return callback(err) if err?
details = details =
name : project.name name : project.name
description: project.description description: project.description
compiler: project.compiler compiler: project.compiler
features: user.features
logger.log project_id:project_id, details:details, "getting project details" logger.log project_id:project_id, details:details, "getting project details"
callback(err, details) callback(err, details)

View file

@ -8,36 +8,41 @@ require('chai').should()
describe 'Project details handler', -> describe 'Project details handler', ->
beforeEach -> beforeEach ->
@ProjectGetter =
getProjectWithoutDocLines: sinon.stub()
@ProjectModel =
update: sinon.stub()
@handler = SandboxedModule.require modulePath, requires:
"./ProjectGetter":@ProjectGetter
'../../models/Project': Project:@ProjectModel
'logger-sharelatex':
log:->
err:->
@project_id = "321l3j1kjkjl" @project_id = "321l3j1kjkjl"
@user_id = "user-id-123"
@project = @project =
name: "project" name: "project"
description: "this is a great project" description: "this is a great project"
something:"should not exist" something:"should not exist"
compiler: "latexxxxxx" compiler: "latexxxxxx"
owner_ref: @user_id
@user =
features: "mock-features"
@ProjectGetter =
getProjectWithoutDocLines: sinon.stub().callsArgWith(1, null, @project)
@ProjectModel =
update: sinon.stub()
@UserGetter =
getUser: sinon.stub().callsArgWith(1, null, @user)
@handler = SandboxedModule.require modulePath, requires:
"./ProjectGetter":@ProjectGetter
'../../models/Project': Project:@ProjectModel
"../User/UserGetter": @UserGetter
'logger-sharelatex':
log:->
err:->
describe "getDetails", -> describe "getDetails", ->
it "should find the project", (done)-> it "should find the project and owner", (done)->
@ProjectGetter.getProjectWithoutDocLines.callsArgWith(1, null, @project)
@handler.getDetails @project_id, (err, details)=> @handler.getDetails @project_id, (err, details)=>
details.name.should.equal @project.name details.name.should.equal @project.name
details.description.should.equal @project.description details.description.should.equal @project.description
details.compiler.should.equal @project.compiler details.compiler.should.equal @project.compiler
details.features.should.equal @user.features
assert.equal(details.something, undefined) assert.equal(details.something, undefined)
done() done()
it "should return the error", (done)-> it "should return the error", (done)->
error = "some error" error = "some error"
@ProjectGetter.getProjectWithoutDocLines.callsArgWith(1, error) @ProjectGetter.getProjectWithoutDocLines.callsArgWith(1, error)