2014-02-12 05:23:40 -05:00
|
|
|
should = require('chai').should()
|
|
|
|
modulePath = "../../../../app/js/Features/Project/ProjectApiController"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
|
|
|
|
describe 'Project api controller', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectDetailsHandler =
|
|
|
|
getDetails : sinon.stub()
|
|
|
|
@controller = SandboxedModule.require modulePath, requires:
|
|
|
|
"./ProjectDetailsHandler":@ProjectDetailsHandler
|
|
|
|
'logger-sharelatex':
|
|
|
|
log:->
|
|
|
|
@project_id = "321l3j1kjkjl"
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
project_id:@project_id
|
2014-05-19 07:01:05 -04:00
|
|
|
session:
|
|
|
|
destroy:sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@res = {}
|
2014-05-19 07:01:05 -04:00
|
|
|
@projDetails = {name:"something"}
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
describe "getProjectDetails", ->
|
|
|
|
|
|
|
|
it "should ask the project details handler for proj details", (done)->
|
2014-05-19 07:01:05 -04:00
|
|
|
@ProjectDetailsHandler.getDetails.callsArgWith(1, null, @projDetails)
|
2014-02-12 05:23:40 -05:00
|
|
|
@res.json = (data)=>
|
|
|
|
@ProjectDetailsHandler.getDetails.calledWith(@project_id).should.equal true
|
2014-05-19 07:01:05 -04:00
|
|
|
data.should.deep.equal @projDetails
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
@controller.getProjectDetails @req, @res
|
|
|
|
|
|
|
|
|
|
|
|
it "should send a 500 if there is an error", (done)->
|
|
|
|
@ProjectDetailsHandler.getDetails.callsArgWith(1, "error")
|
|
|
|
@res.send = (resCode)=>
|
|
|
|
resCode.should.equal 500
|
|
|
|
done()
|
2014-05-19 07:01:05 -04:00
|
|
|
@controller.getProjectDetails @req, @res
|