2014-04-08 09:34:03 -04:00
|
|
|
should = require('chai').should()
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
|
|
|
sinon = require('sinon')
|
|
|
|
modulePath = path.join __dirname, "../../../../app/js/Features/Project/ProjectController"
|
|
|
|
expect = require("chai").expect
|
|
|
|
|
|
|
|
describe "ProjectController", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
2014-04-08 09:53:33 -04:00
|
|
|
@project_id = "123213jlkj9kdlsaj"
|
|
|
|
|
2014-04-08 09:34:03 -04:00
|
|
|
@settings = {}
|
|
|
|
@ProjectDeleter =
|
|
|
|
deleteProject: sinon.stub().callsArgWith(1)
|
2014-04-08 09:53:33 -04:00
|
|
|
@ProjectDuplicator =
|
|
|
|
duplicate: sinon.stub().callsArgWith(3, null, {_id:@project_id})
|
2014-04-08 10:25:22 -04:00
|
|
|
@ProjectCreationHandler =
|
|
|
|
createExampleProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
|
|
|
createBasicProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
2014-04-08 11:40:12 -04:00
|
|
|
@SubscriptionLocator =
|
|
|
|
getUsersSubscription: sinon.stub()
|
|
|
|
@TagsHandler =
|
|
|
|
getAllTags: sinon.stub()
|
|
|
|
@ProjectModel =
|
|
|
|
findAllUsersProjects: sinon.stub()
|
2014-04-08 09:34:03 -04:00
|
|
|
@ProjectController = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex":@settings
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
"./ProjectDeleter": @ProjectDeleter
|
2014-04-08 09:53:33 -04:00
|
|
|
"./ProjectDuplicator": @ProjectDuplicator
|
2014-04-08 10:25:22 -04:00
|
|
|
"./ProjectCreationHandler": @ProjectCreationHandler
|
2014-04-08 11:40:12 -04:00
|
|
|
"../Subscription/SubscriptionLocator": @SubscriptionLocator
|
|
|
|
"../Tags/TagsHandler":@TagsHandler
|
|
|
|
'../../models/Project': Project:@ProjectModel
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2014-04-08 09:53:33 -04:00
|
|
|
@user =
|
|
|
|
_id:"!£123213kjljkl"
|
|
|
|
first_name: "bjkdsjfk"
|
|
|
|
@projectName = "£12321jkj9ujkljds"
|
2014-04-08 09:34:03 -04:00
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
Project_id: @project_id
|
2014-04-08 09:53:33 -04:00
|
|
|
session:
|
|
|
|
user: @user
|
|
|
|
body:
|
|
|
|
projectName: @projectName
|
2014-04-08 09:34:03 -04:00
|
|
|
@res = {}
|
|
|
|
|
|
|
|
describe "deleteProject", ->
|
|
|
|
|
|
|
|
it "should tell the project deleter", (done)->
|
|
|
|
|
|
|
|
@res.send = (code)=>
|
|
|
|
@ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true
|
|
|
|
code.should.equal 200
|
|
|
|
done()
|
|
|
|
@ProjectController.deleteProject @req, @res
|
|
|
|
|
2014-04-08 09:53:33 -04:00
|
|
|
|
|
|
|
describe "cloneProject", ->
|
|
|
|
|
|
|
|
it "should call the project duplicator", (done)->
|
|
|
|
@res.send = (json)=>
|
|
|
|
@ProjectDuplicator.duplicate.calledWith(@user, @project_id, @projectName).should.equal true
|
|
|
|
json.project_id.should.equal @project_id
|
|
|
|
done()
|
|
|
|
@ProjectController.cloneProject @req, @res
|
2014-04-08 10:25:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "newProject", ->
|
|
|
|
|
|
|
|
it "should call the projectCreationHandler with createExampleProject", (done)->
|
|
|
|
@req.body.template = "example"
|
|
|
|
@res.send = (json)=>
|
|
|
|
@ProjectCreationHandler.createExampleProject.calledWith(@user._id, @projectName).should.equal true
|
|
|
|
@ProjectCreationHandler.createBasicProject.called.should.equal false
|
|
|
|
done()
|
|
|
|
@ProjectController.newProject @req, @res
|
|
|
|
|
|
|
|
|
|
|
|
it "should call the projectCreationHandler with createBasicProject", (done)->
|
|
|
|
@req.body.template = "basic"
|
|
|
|
@res.send = (json)=>
|
|
|
|
@ProjectCreationHandler.createExampleProject.called.should.equal false
|
|
|
|
@ProjectCreationHandler.createBasicProject.calledWith(@user._id, @projectName).should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.newProject @req, @res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-08 11:40:12 -04:00
|
|
|
describe "projectListPage", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@tags = [{name:1, project_ids:["1","2","3"]}, {name:2, project_ids:["a","1"]}, {name:3, project_ids:["a", "b", "c", "d"]}]
|
|
|
|
@projects = [{lastUpdated:1, _id:1}, {lastUpdated:2, _id:2}]
|
|
|
|
@collabertions = [{lastUpdated:5, _id:5}]
|
|
|
|
@readOnly = [{lastUpdated:3, _id:3}]
|
|
|
|
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
|
|
|
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
|
|
|
@ProjectModel.findAllUsersProjects.callsArgWith(2, @projects, @collabertions, @readOnly)
|
|
|
|
|
|
|
|
it "should render the project/list page", (done)->
|
|
|
|
|
|
|
|
@req.body.template = "example"
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
pageName.should.equal "project/list"
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it "should send the tags", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.tags.length.should.equal @tags.length
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
|
|
|
|
it "should send the projects", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length)
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2014-04-08 10:25:22 -04:00
|
|
|
|