mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
88 lines
2.5 KiB
CoffeeScript
88 lines
2.5 KiB
CoffeeScript
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 ->
|
|
|
|
@project_id = "123213jlkj9kdlsaj"
|
|
|
|
@settings = {}
|
|
@ProjectDeleter =
|
|
deleteProject: sinon.stub().callsArgWith(1)
|
|
@ProjectDuplicator =
|
|
duplicate: sinon.stub().callsArgWith(3, null, {_id:@project_id})
|
|
@ProjectCreationHandler =
|
|
createExampleProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
|
createBasicProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
|
@ProjectController = SandboxedModule.require modulePath, requires:
|
|
"settings-sharelatex":@settings
|
|
"logger-sharelatex": log:->
|
|
"./ProjectDeleter": @ProjectDeleter
|
|
"./ProjectDuplicator": @ProjectDuplicator
|
|
"./ProjectCreationHandler": @ProjectCreationHandler
|
|
|
|
|
|
@user =
|
|
_id:"!£123213kjljkl"
|
|
first_name: "bjkdsjfk"
|
|
@projectName = "£12321jkj9ujkljds"
|
|
@req =
|
|
params:
|
|
Project_id: @project_id
|
|
session:
|
|
user: @user
|
|
body:
|
|
projectName: @projectName
|
|
@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
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|