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
|
2018-06-20 06:19:23 -04:00
|
|
|
Errors = require "../../../../app/js/Features/Errors/Errors"
|
2014-04-08 09:34:03 -04:00
|
|
|
|
|
|
|
describe "ProjectController", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
2014-04-08 09:53:33 -04:00
|
|
|
@project_id = "123213jlkj9kdlsaj"
|
|
|
|
|
2016-09-07 11:40:49 -04:00
|
|
|
@user =
|
2017-03-09 04:13:49 -05:00
|
|
|
_id:"588f3ddae8ebc1bac07c9fa4"
|
2016-09-07 11:40:49 -04:00
|
|
|
first_name: "bjkdsjfk"
|
2018-04-30 12:13:57 -04:00
|
|
|
features: {}
|
2016-09-07 11:40:49 -04:00
|
|
|
@settings =
|
2014-04-08 12:44:31 -04:00
|
|
|
apis:
|
|
|
|
chat:
|
|
|
|
url:"chat.com"
|
|
|
|
siteUrl: "mysite.com"
|
2018-10-17 09:14:17 -04:00
|
|
|
@brandVariationDetails =
|
|
|
|
id: "12"
|
|
|
|
active: true
|
|
|
|
brand_name: "The journal"
|
|
|
|
home_url: "http://www.thejournal.com/"
|
|
|
|
publish_menu_link_html: "Submit your paper to the <em>The Journal</em>"
|
2017-10-13 06:20:57 -04:00
|
|
|
@token = 'some-token'
|
2016-09-07 11:40:49 -04:00
|
|
|
@ProjectDeleter =
|
2014-06-04 07:45:04 -04:00
|
|
|
archiveProject: sinon.stub().callsArg(1)
|
|
|
|
deleteProject: sinon.stub().callsArg(1)
|
|
|
|
restoreProject: sinon.stub().callsArg(1)
|
2014-06-03 12:35:44 -04:00
|
|
|
findArchivedProjects: sinon.stub()
|
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()
|
2016-09-07 11:40:49 -04:00
|
|
|
@LimitationsManager =
|
2018-09-03 10:09:57 -04:00
|
|
|
hasPaidSubscription: sinon.stub()
|
2014-04-08 11:40:12 -04:00
|
|
|
@TagsHandler =
|
|
|
|
getAllTags: sinon.stub()
|
2016-01-22 00:41:22 -05:00
|
|
|
@NotificationsHandler =
|
|
|
|
getUserNotifications: sinon.stub()
|
2014-04-08 12:44:31 -04:00
|
|
|
@UserModel =
|
|
|
|
findById: sinon.stub()
|
2016-03-10 12:17:26 -05:00
|
|
|
@AuthorizationManager =
|
|
|
|
getPrivilegeLevelForProject:sinon.stub()
|
2016-09-07 11:40:49 -04:00
|
|
|
@EditorController =
|
2014-04-28 12:47:47 -04:00
|
|
|
renameProject:sinon.stub()
|
2015-08-13 17:40:28 -04:00
|
|
|
@InactiveProjectManager =
|
|
|
|
reactivateProjectIfRequired:sinon.stub()
|
|
|
|
@ProjectUpdateHandler =
|
2015-08-14 06:27:11 -04:00
|
|
|
markAsOpened: sinon.stub()
|
2016-01-14 09:53:08 -05:00
|
|
|
@ReferencesSearchHandler =
|
|
|
|
indexProjectReferences: sinon.stub()
|
2016-03-03 12:19:03 -05:00
|
|
|
@ProjectGetter =
|
|
|
|
findAllUsersProjects: sinon.stub()
|
2016-03-15 10:12:43 -04:00
|
|
|
getProject: sinon.stub()
|
2016-09-07 11:40:49 -04:00
|
|
|
@AuthenticationController =
|
|
|
|
getLoggedInUser: sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
getLoggedInUserId: sinon.stub().returns(@user._id)
|
|
|
|
getSessionUser: sinon.stub().returns(@user)
|
|
|
|
isUserLoggedIn: sinon.stub().returns(true)
|
2017-02-14 03:34:30 -05:00
|
|
|
@AnalyticsManager =
|
2018-02-07 04:33:28 -05:00
|
|
|
getLastOccurrence: sinon.stub()
|
2017-10-13 06:20:57 -04:00
|
|
|
@TokenAccessHandler =
|
|
|
|
getRequestToken: sinon.stub().returns(@token)
|
2017-10-19 11:26:01 -04:00
|
|
|
protectTokens: sinon.stub()
|
2017-10-25 06:29:05 -04:00
|
|
|
@CollaboratorsHandler =
|
|
|
|
userIsTokenMember: sinon.stub().callsArgWith(2, null, false)
|
2018-05-22 10:56:01 -04:00
|
|
|
@ProjectEntityHandler = {}
|
2018-09-05 10:28:26 -04:00
|
|
|
@NotificationBuilder =
|
|
|
|
ipMatcherAffiliation: sinon.stub().returns({create: sinon.stub()})
|
|
|
|
@UserGetter =
|
|
|
|
getUser: sinon.stub().callsArgWith 2, null, {lastLoginIp: '192.170.18.2'}
|
2017-11-15 10:54:47 -05:00
|
|
|
@Modules =
|
|
|
|
hooks:
|
|
|
|
fire: sinon.stub()
|
2018-07-16 09:21:10 -04:00
|
|
|
@Features =
|
|
|
|
hasFeature: sinon.stub()
|
2018-10-17 09:14:17 -04:00
|
|
|
@BrandVariationsHandler =
|
|
|
|
getBrandVariationById: sinon.stub().callsArgWith 1, null, @brandVariationDetails
|
|
|
|
|
2014-04-08 09:34:03 -04:00
|
|
|
@ProjectController = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex":@settings
|
2016-09-07 11:40:49 -04:00
|
|
|
"logger-sharelatex":
|
2014-04-28 12:47:47 -04:00
|
|
|
log:->
|
|
|
|
err:->
|
2017-04-03 11:18:30 -04:00
|
|
|
"metrics-sharelatex":
|
2016-03-09 07:51:19 -05:00
|
|
|
Timer:->
|
|
|
|
done:->
|
|
|
|
inc:->
|
2014-04-08 09:34:03 -04:00
|
|
|
"./ProjectDeleter": @ProjectDeleter
|
2014-04-08 09:53:33 -04:00
|
|
|
"./ProjectDuplicator": @ProjectDuplicator
|
2014-04-08 10:25:22 -04:00
|
|
|
"./ProjectCreationHandler": @ProjectCreationHandler
|
2014-04-28 12:47:47 -04:00
|
|
|
"../Editor/EditorController": @EditorController
|
2014-04-08 11:40:12 -04:00
|
|
|
"../Subscription/SubscriptionLocator": @SubscriptionLocator
|
2014-08-07 10:29:06 -04:00
|
|
|
"../Subscription/LimitationsManager": @LimitationsManager
|
2014-04-08 11:40:12 -04:00
|
|
|
"../Tags/TagsHandler":@TagsHandler
|
2016-01-22 00:41:22 -05:00
|
|
|
"../Notifications/NotificationsHandler":@NotificationsHandler
|
2014-04-08 12:44:31 -04:00
|
|
|
"../../models/User":User:@UserModel
|
2016-03-10 12:17:26 -05:00
|
|
|
"../Authorization/AuthorizationManager":@AuthorizationManager
|
2015-08-13 17:40:28 -04:00
|
|
|
"../InactiveData/InactiveProjectManager":@InactiveProjectManager
|
|
|
|
"./ProjectUpdateHandler":@ProjectUpdateHandler
|
2016-01-14 09:53:08 -05:00
|
|
|
"../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler
|
2016-03-03 12:19:03 -05:00
|
|
|
"./ProjectGetter": @ProjectGetter
|
2016-09-07 11:40:49 -04:00
|
|
|
'../Authentication/AuthenticationController': @AuthenticationController
|
2017-02-14 03:34:30 -05:00
|
|
|
"../Analytics/AnalyticsManager": @AnalyticsManager
|
2017-10-13 06:20:57 -04:00
|
|
|
"../TokenAccess/TokenAccessHandler": @TokenAccessHandler
|
2017-10-25 06:29:05 -04:00
|
|
|
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler
|
2017-11-15 10:54:47 -05:00
|
|
|
"../../infrastructure/Modules": @Modules
|
2018-05-22 10:56:01 -04:00
|
|
|
"./ProjectEntityHandler": @ProjectEntityHandler
|
2018-06-20 06:19:23 -04:00
|
|
|
"../Errors/Errors": Errors
|
2018-07-16 10:53:28 -04:00
|
|
|
"../../infrastructure/Features": @Features
|
2018-09-05 10:28:26 -04:00
|
|
|
"../Notifications/NotificationsBuilder":@NotificationBuilder
|
|
|
|
"../User/UserGetter": @UserGetter
|
2018-10-17 09:14:17 -04:00
|
|
|
"../BrandVariations/BrandVariationsHandler": @BrandVariationsHandler
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2014-04-08 09:53:33 -04:00
|
|
|
@projectName = "£12321jkj9ujkljds"
|
2016-09-07 11:40:49 -04:00
|
|
|
@req =
|
|
|
|
params:
|
2014-04-08 09:34:03 -04:00
|
|
|
Project_id: @project_id
|
2018-09-05 10:28:26 -04:00
|
|
|
headers: {}
|
|
|
|
connection:
|
|
|
|
remoteAddress: "192.170.18.1"
|
2014-04-08 09:53:33 -04:00
|
|
|
session:
|
|
|
|
user: @user
|
|
|
|
body:
|
2016-09-07 11:40:49 -04:00
|
|
|
projectName: @projectName
|
2016-01-22 15:08:39 -05:00
|
|
|
i18n:
|
|
|
|
translate:->
|
2016-09-07 11:40:49 -04:00
|
|
|
@res =
|
2014-04-08 12:44:31 -04:00
|
|
|
locals:
|
|
|
|
jsPath:"js path here"
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2014-06-25 08:51:02 -04:00
|
|
|
describe "updateProjectSettings", ->
|
|
|
|
it "should update the name", (done) ->
|
|
|
|
@EditorController.renameProject = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
name: @name = "New name"
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code) =>
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorController.renameProject
|
|
|
|
.calledWith(@project_id, @name)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectSettings @req, @res
|
|
|
|
|
|
|
|
it "should update the compiler", (done) ->
|
|
|
|
@EditorController.setCompiler = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
compiler: @compiler = "pdflatex"
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code) =>
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorController.setCompiler
|
|
|
|
.calledWith(@project_id, @compiler)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectSettings @req, @res
|
|
|
|
|
2018-08-13 05:48:11 -04:00
|
|
|
it "should update the imageName", (done) ->
|
|
|
|
@EditorController.setImageName = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
imageName: @imageName = "texlive-1234.5"
|
|
|
|
@res.sendStatus = (code) =>
|
|
|
|
@EditorController.setImageName
|
|
|
|
.calledWith(@project_id, @imageName)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectSettings @req, @res
|
|
|
|
|
2014-06-25 08:51:02 -04:00
|
|
|
it "should update the spell check language", (done) ->
|
|
|
|
@EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
spellCheckLanguage: @languageCode = "fr"
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code) =>
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorController.setSpellCheckLanguage
|
|
|
|
.calledWith(@project_id, @languageCode)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectSettings @req, @res
|
|
|
|
|
|
|
|
it "should update the root doc", (done) ->
|
|
|
|
@EditorController.setRootDoc = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
rootDocId: @rootDocId = "root-doc-id"
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code) =>
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorController.setRootDoc
|
|
|
|
.calledWith(@project_id, @rootDocId)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectSettings @req, @res
|
2016-09-07 11:40:49 -04:00
|
|
|
|
2016-03-10 06:13:57 -05:00
|
|
|
describe "updateProjectAdminSettings", ->
|
|
|
|
it "should update the public access level", (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
|
|
|
@req.body =
|
|
|
|
publicAccessLevel: @publicAccessLevel = "readonly"
|
|
|
|
@res.sendStatus = (code) =>
|
|
|
|
@EditorController.setPublicAccessLevel
|
|
|
|
.calledWith(@project_id, @publicAccessLevel)
|
|
|
|
.should.equal true
|
|
|
|
code.should.equal 204
|
|
|
|
done()
|
|
|
|
@ProjectController.updateProjectAdminSettings @req, @res
|
2014-06-25 08:51:02 -04:00
|
|
|
|
2014-04-08 09:34:03 -04:00
|
|
|
describe "deleteProject", ->
|
2014-06-04 07:45:04 -04:00
|
|
|
it "should tell the project deleter to archive when forever=false", (done)->
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code)=>
|
2014-06-03 12:35:44 -04:00
|
|
|
@ProjectDeleter.archiveProject.calledWith(@project_id).should.equal true
|
2014-04-08 09:34:03 -04:00
|
|
|
code.should.equal 200
|
|
|
|
done()
|
|
|
|
@ProjectController.deleteProject @req, @res
|
2014-06-04 07:45:04 -04:00
|
|
|
|
|
|
|
it "should tell the project deleter to delete when forever=true", (done)->
|
|
|
|
@req.query = forever: "true"
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code)=>
|
2014-06-04 07:45:04 -04:00
|
|
|
@ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true
|
|
|
|
code.should.equal 200
|
|
|
|
done()
|
|
|
|
@ProjectController.deleteProject @req, @res
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2014-06-03 12:35:44 -04:00
|
|
|
describe "restoreProject", ->
|
|
|
|
it "should tell the project deleter", (done)->
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code)=>
|
2014-06-03 12:35:44 -04:00
|
|
|
@ProjectDeleter.restoreProject.calledWith(@project_id).should.equal true
|
|
|
|
code.should.equal 200
|
|
|
|
done()
|
|
|
|
@ProjectController.restoreProject @req, @res
|
2014-04-08 09:53:33 -04:00
|
|
|
|
|
|
|
describe "cloneProject", ->
|
2016-09-07 11:40:49 -04:00
|
|
|
it "should call the project duplicator", (done)->
|
2014-04-08 09:53:33 -04:00
|
|
|
@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"]}]
|
2016-01-22 00:41:22 -05:00
|
|
|
@notifications = [{_id:'1',user_id:'2',templateKey:'3',messageOpts:'4',key:'5'}]
|
2017-10-17 06:10:31 -04:00
|
|
|
@projects = [
|
|
|
|
{_id:1, lastUpdated:1, owner_ref: "user-1"},
|
|
|
|
{_id:2, lastUpdated:2, owner_ref: "user-2"}
|
|
|
|
]
|
|
|
|
@collabertions = [
|
|
|
|
{_id:5, lastUpdated:5, owner_ref: "user-1"}
|
|
|
|
]
|
|
|
|
@readOnly = [
|
|
|
|
{_id:3, lastUpdated:3, owner_ref: "user-1"}
|
|
|
|
]
|
|
|
|
@tokenReadAndWrite = [
|
|
|
|
{_id:6, lastUpdated:5, owner_ref: "user-4"}
|
|
|
|
]
|
|
|
|
@tokenReadOnly = [
|
|
|
|
{_id:7, lastUpdated:4, owner_ref: "user-5"}
|
|
|
|
]
|
2017-10-20 06:49:20 -04:00
|
|
|
@allProjects = {
|
|
|
|
owned: @projects,
|
|
|
|
readAndWrite: @collabertions,
|
|
|
|
readOnly: @readOnly,
|
|
|
|
tokenReadAndWrite: @tokenReadAndWrite,
|
|
|
|
tokenReadOnly: @tokenReadOnly
|
|
|
|
}
|
2014-06-16 08:34:38 -04:00
|
|
|
|
|
|
|
@users =
|
2016-09-07 11:40:49 -04:00
|
|
|
'user-1':
|
2014-06-16 08:34:38 -04:00
|
|
|
first_name: 'James'
|
|
|
|
'user-2':
|
|
|
|
first_name: 'Henry'
|
2014-10-07 08:31:13 -04:00
|
|
|
@users[@user._id] = @user # Owner
|
2014-06-16 08:34:38 -04:00
|
|
|
@UserModel.findById = (id, fields, callback) =>
|
|
|
|
callback null, @users[id]
|
|
|
|
|
2018-09-03 10:09:57 -04:00
|
|
|
@LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
|
2014-04-08 11:40:12 -04:00
|
|
|
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
2016-01-22 00:41:22 -05:00
|
|
|
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
|
2017-10-20 06:49:20 -04:00
|
|
|
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @allProjects)
|
2017-11-15 11:28:41 -05:00
|
|
|
@Modules.hooks.fire.withArgs('findAllV1Projects', @user._id).yields(undefined) # Without integration module hook, cb returns undefined
|
2014-04-08 11:40:12 -04:00
|
|
|
|
|
|
|
it "should render the project/list page", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
pageName.should.equal "project/list"
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it "should send the tags", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
2014-06-16 08:34:38 -04:00
|
|
|
opts.tags.length.should.equal @tags.length
|
2014-04-08 11:40:12 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2018-09-05 10:28:26 -04:00
|
|
|
it "should create trigger ip matcher notifications", (done)->
|
|
|
|
@settings.overleaf = true
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
@NotificationBuilder.ipMatcherAffiliation.called.should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2014-04-08 11:40:12 -04:00
|
|
|
it "should send the projects", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
2017-11-14 06:38:06 -05:00
|
|
|
opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length + @tokenReadAndWrite.length + @tokenReadOnly.length)
|
2014-06-16 08:34:38 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2014-10-07 08:31:13 -04:00
|
|
|
it "should send the user", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.user.should.deep.equal @user
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2014-06-16 08:34:38 -04:00
|
|
|
it "should inject the users", (done) ->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.projects[0].owner.should.equal (@users[@projects[0].owner_ref])
|
|
|
|
opts.projects[1].owner.should.equal (@users[@projects[1].owner_ref])
|
2014-04-08 11:40:12 -04:00
|
|
|
done()
|
2014-04-08 12:44:31 -04:00
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2018-06-22 09:05:48 -04:00
|
|
|
it 'should send hasSubscription == false when no subscription', (done) ->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.hasSubscription.should.equal false
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it 'should send hasSubscription == true when there is a subscription', (done) ->
|
2018-09-03 10:09:57 -04:00
|
|
|
@LimitationsManager.hasPaidSubscription = sinon.stub().callsArgWith(1, null, true)
|
2018-06-22 09:05:48 -04:00
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.hasSubscription.should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
|
2018-04-30 12:13:57 -04:00
|
|
|
describe 'front widget', (done) ->
|
|
|
|
beforeEach ->
|
|
|
|
@settings.overleaf =
|
|
|
|
front_chat_widget_room_id: 'chat-room-id'
|
|
|
|
|
|
|
|
it 'should show for paid users', (done) ->
|
|
|
|
@user.features.github = true
|
2018-05-24 05:27:36 -04:00
|
|
|
@user.features.dropbox = true
|
2018-04-30 12:13:57 -04:00
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.frontChatWidgetRoomId.should.equal @settings.overleaf.front_chat_widget_room_id
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it 'should show for sample users', (done) ->
|
2018-05-01 04:02:43 -04:00
|
|
|
@user._id = '588f3ddae8ebc1bac07c9f00' # last two digits
|
2018-04-30 12:13:57 -04:00
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.frontChatWidgetRoomId.should.equal @settings.overleaf.front_chat_widget_room_id
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it 'should not show for non sample users', (done) ->
|
|
|
|
@user._id = '588f3ddae8ebc1bac07c9fff' # last two digits
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
expect(opts.frontChatWidgetRoomId).to.equal undefined
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2017-11-15 10:54:47 -05:00
|
|
|
describe 'with overleaf-integration-web-module hook', ->
|
2017-11-02 06:18:01 -04:00
|
|
|
beforeEach ->
|
|
|
|
@V1Response =
|
|
|
|
projects: [
|
|
|
|
{ id: '123mockV1Id', title: 'mock title', updated_at: 1509616411, removed: false, archived: false }
|
|
|
|
{ id: '456mockV1Id', title: 'mock title 2', updated_at: 1509616411, removed: true, archived: false }
|
|
|
|
],
|
|
|
|
tags: [
|
|
|
|
{ name: 'mock tag', project_ids: ['123mockV1Id'] }
|
|
|
|
]
|
2017-11-15 11:28:41 -05:00
|
|
|
@Modules.hooks.fire.withArgs('findAllV1Projects', @user._id).yields(null, [@V1Response]) # Need to wrap response in array, as multiple hooks could fire
|
2017-11-02 06:18:01 -04:00
|
|
|
|
|
|
|
it 'should include V1 projects', (done) ->
|
|
|
|
@res.render = (pageName, opts) =>
|
2017-11-14 06:38:06 -05:00
|
|
|
opts.projects.length.should.equal (
|
|
|
|
@projects.length +
|
|
|
|
@collabertions.length +
|
|
|
|
@readOnly.length +
|
|
|
|
@tokenReadAndWrite.length +
|
|
|
|
@tokenReadOnly.length +
|
|
|
|
@V1Response.projects.length
|
|
|
|
)
|
2017-11-02 08:09:47 -04:00
|
|
|
opts.projects.forEach (p) ->
|
|
|
|
# Check properties correctly mapped from V1
|
|
|
|
expect(p).to.have.property 'id'
|
|
|
|
expect(p).to.have.property 'name'
|
|
|
|
expect(p).to.have.property 'lastUpdated'
|
|
|
|
expect(p).to.have.property 'accessLevel'
|
|
|
|
expect(p).to.have.property 'archived'
|
2017-11-02 06:18:01 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it 'should include V1 tags', (done) ->
|
|
|
|
@res.render = (pageName, opts) =>
|
|
|
|
opts.tags.length.should.equal (@tags.length + @V1Response.tags.length)
|
2017-11-02 08:16:11 -04:00
|
|
|
opts.tags.forEach (t) ->
|
|
|
|
expect(t).to.have.property 'name'
|
|
|
|
expect(t).to.have.property 'project_ids'
|
2017-11-02 06:18:01 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it 'should have isShowingV1Projects flag', (done) ->
|
|
|
|
@res.render = (pageName, opts) =>
|
|
|
|
opts.isShowingV1Projects.should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2017-10-17 06:10:31 -04:00
|
|
|
describe "projectListPage with duplicate projects", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@tags = [{name:1, project_ids:["1","2","3"]}, {name:2, project_ids:["a","1"]}, {name:3, project_ids:["a", "b", "c", "d"]}]
|
|
|
|
@notifications = [{_id:'1',user_id:'2',templateKey:'3',messageOpts:'4',key:'5'}]
|
|
|
|
@projects = [
|
|
|
|
{_id:1, lastUpdated:1, owner_ref: "user-1"},
|
|
|
|
{_id:2, lastUpdated:2, owner_ref: "user-2"}
|
|
|
|
]
|
|
|
|
@collabertions = [
|
|
|
|
{_id:5, lastUpdated:5, owner_ref: "user-1"}
|
|
|
|
]
|
|
|
|
@readOnly = [
|
|
|
|
{_id:3, lastUpdated:3, owner_ref: "user-1"}
|
|
|
|
]
|
|
|
|
@tokenReadAndWrite = [
|
|
|
|
{_id:6, lastUpdated:5, owner_ref: "user-4"}
|
|
|
|
]
|
|
|
|
@tokenReadOnly = [
|
|
|
|
{_id:6, lastUpdated:5, owner_ref: "user-4"} # Also in tokenReadAndWrite
|
|
|
|
{_id:7, lastUpdated:4, owner_ref: "user-5"}
|
|
|
|
]
|
2017-10-20 06:49:20 -04:00
|
|
|
@allProjects = {
|
|
|
|
owned: @projects,
|
|
|
|
readAndWrite: @collabertions,
|
|
|
|
readOnly: @readOnly,
|
|
|
|
tokenReadAndWrite: @tokenReadAndWrite,
|
|
|
|
tokenReadOnly: @tokenReadOnly
|
|
|
|
}
|
2017-10-17 06:10:31 -04:00
|
|
|
|
|
|
|
@users =
|
|
|
|
'user-1':
|
|
|
|
first_name: 'James'
|
|
|
|
'user-2':
|
|
|
|
first_name: 'Henry'
|
|
|
|
@users[@user._id] = @user # Owner
|
|
|
|
@UserModel.findById = (id, fields, callback) =>
|
|
|
|
callback null, @users[id]
|
|
|
|
|
2018-09-03 10:09:57 -04:00
|
|
|
@LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
|
2017-10-17 06:10:31 -04:00
|
|
|
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
|
|
|
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
|
2017-10-20 06:49:20 -04:00
|
|
|
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @allProjects)
|
2017-11-15 11:28:41 -05:00
|
|
|
@Modules.hooks.fire.withArgs('findAllV1Projects', @user._id).yields(undefined) # Without integration module hook, cb returns undefined
|
2017-10-17 06:10:31 -04:00
|
|
|
|
|
|
|
it "should render the project/list page", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
pageName.should.equal "project/list"
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
|
|
|
it "should omit one of the projects", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.projects.length.should.equal (
|
|
|
|
@projects.length + @collabertions.length + @readOnly.length + @tokenReadAndWrite.length + @tokenReadOnly.length - 1
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
@ProjectController.projectListPage @req, @res
|
|
|
|
|
2014-04-28 12:47:47 -04:00
|
|
|
describe "renameProject", ->
|
|
|
|
beforeEach ->
|
|
|
|
@newProjectName = "my supper great new project"
|
|
|
|
@req.body.newProjectName = @newProjectName
|
|
|
|
|
|
|
|
it "should call the editor controller", (done)->
|
|
|
|
@EditorController.renameProject.callsArgWith(2)
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (code)=>
|
2014-04-28 12:47:47 -04:00
|
|
|
code.should.equal 200
|
|
|
|
@EditorController.renameProject.calledWith(@project_id, @newProjectName).should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.renameProject @req, @res
|
|
|
|
|
2017-05-19 11:21:02 -04:00
|
|
|
it "should send an error to next() if there is a problem", (done)->
|
|
|
|
@EditorController.renameProject.callsArgWith(2, error = new Error("problem"))
|
|
|
|
next = (e)=>
|
|
|
|
e.should.equal error
|
2014-04-28 12:47:47 -04:00
|
|
|
done()
|
2017-05-19 11:21:02 -04:00
|
|
|
@ProjectController.renameProject @req, @res, next
|
2014-10-07 06:14:02 -04:00
|
|
|
|
2014-04-08 12:44:31 -04:00
|
|
|
describe "loadEditor", ->
|
|
|
|
beforeEach ->
|
|
|
|
@settings.editorIsOpen = true
|
2016-09-07 11:40:49 -04:00
|
|
|
@project =
|
2014-04-08 12:44:31 -04:00
|
|
|
name:"my proj"
|
|
|
|
_id:"213123kjlkj"
|
2017-11-03 11:08:21 -04:00
|
|
|
owner_ref: '59fc84d5fbea77482d436e1b'
|
2018-10-17 09:14:17 -04:00
|
|
|
@brandedProject =
|
|
|
|
name:"my branded proj"
|
|
|
|
_id:"3252332"
|
|
|
|
owner_ref: '59fc84d5fbea77482d436e1b'
|
|
|
|
brandVariationId:"12"
|
2016-09-07 11:40:49 -04:00
|
|
|
@user =
|
2017-03-09 04:13:49 -05:00
|
|
|
_id: "588f3ddae8ebc1bac07c9fa4"
|
2014-04-08 12:44:31 -04:00
|
|
|
ace:
|
|
|
|
fontSize:"massive"
|
|
|
|
theme:"sexy"
|
|
|
|
email: "bob@bob.com"
|
2016-03-15 10:12:43 -04:00
|
|
|
@ProjectGetter.getProject.callsArgWith 2, null, @project
|
2014-04-08 12:44:31 -04:00
|
|
|
@UserModel.findById.callsArgWith(1, null, @user)
|
|
|
|
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
2017-09-27 09:01:52 -04:00
|
|
|
@AuthorizationManager.getPrivilegeLevelForProject.callsArgWith 3, null, "owner"
|
2014-10-09 04:13:38 -04:00
|
|
|
@ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
|
2015-08-13 17:40:28 -04:00
|
|
|
@InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1)
|
2018-02-07 04:33:28 -05:00
|
|
|
@AnalyticsManager.getLastOccurrence.yields(null, {"mock": "event"})
|
2015-08-14 06:27:11 -04:00
|
|
|
@ProjectUpdateHandler.markAsOpened.callsArgWith(1)
|
2015-08-13 17:40:28 -04:00
|
|
|
|
2014-04-08 12:44:31 -04:00
|
|
|
it "should render the project/editor page", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
pageName.should.equal "project/editor"
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
2014-04-08 10:25:22 -04:00
|
|
|
|
2014-07-09 06:05:00 -04:00
|
|
|
it "should add user", (done)->
|
2014-04-08 12:44:31 -04:00
|
|
|
@res.render = (pageName, opts)=>
|
2014-07-09 06:05:00 -04:00
|
|
|
opts.user.email.should.equal @user.email
|
2014-04-08 12:44:31 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
2014-07-09 06:05:00 -04:00
|
|
|
it "should add on userSettings", (done)->
|
2014-04-08 12:44:31 -04:00
|
|
|
@res.render = (pageName, opts)=>
|
2014-07-09 06:05:00 -04:00
|
|
|
opts.userSettings.fontSize.should.equal @user.ace.fontSize
|
2018-08-27 10:25:00 -04:00
|
|
|
opts.userSettings.editorTheme.should.equal @user.ace.theme
|
2014-04-08 12:44:31 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
|
|
|
it "should render the closed page if the editor is closed", (done)->
|
|
|
|
@settings.editorIsOpen = false
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
pageName.should.equal "general/closed"
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
|
|
|
it "should not render the page if the project can not be accessed", (done)->
|
2017-09-27 09:01:52 -04:00
|
|
|
@AuthorizationManager.getPrivilegeLevelForProject = sinon.stub().callsArgWith 3, null, null
|
2015-07-08 11:56:38 -04:00
|
|
|
@res.sendStatus = (resCode, opts)=>
|
2014-04-08 12:44:31 -04:00
|
|
|
resCode.should.equal 401
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
2015-08-13 17:40:28 -04:00
|
|
|
|
|
|
|
it "should reactivateProjectIfRequired", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
@InactiveProjectManager.reactivateProjectIfRequired.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
|
|
|
it "should mark project as opened", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
2015-08-14 06:27:11 -04:00
|
|
|
@ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true
|
2015-08-13 17:40:28 -04:00
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
2018-05-22 11:17:59 -04:00
|
|
|
|
2018-10-17 09:14:17 -04:00
|
|
|
it "should call the brand variations handler for branded projects", (done)->
|
|
|
|
@ProjectGetter.getProject.callsArgWith 2, null, @brandedProject
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
@BrandVariationsHandler.getBrandVariationById.calledWith().should.equal true
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
|
|
|
it "should not call the brand variations handler for unbranded projects", (done)->
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
@BrandVariationsHandler.getBrandVariationById.called.should.equal false
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
|
|
|
it "should expose the brand variation details as locals for branded projects", (done)->
|
|
|
|
@ProjectGetter.getProject.callsArgWith 2, null, @brandedProject
|
|
|
|
@res.render = (pageName, opts)=>
|
|
|
|
opts.brandVariation.should.deep.equal @brandVariationDetails
|
|
|
|
done()
|
|
|
|
@ProjectController.loadEditor @req, @res
|
|
|
|
|
2018-05-22 11:17:59 -04:00
|
|
|
describe 'userProjectsJson', ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
projects = [
|
|
|
|
{archived: true, id: 'a', name: 'A', accessLevel: 'a', somethingElse: 1}
|
|
|
|
{archived: false, id: 'b', name: 'B', accessLevel: 'b', somethingElse: 1}
|
|
|
|
{archived: false, id: 'c', name: 'C', accessLevel: 'c', somethingElse: 1}
|
|
|
|
{archived: false, id: 'd', name: 'D', accessLevel: 'd', somethingElse: 1}
|
|
|
|
]
|
|
|
|
@ProjectGetter.findAllUsersProjects = sinon.stub().callsArgWith(2, null, [])
|
|
|
|
@ProjectController._buildProjectList = sinon.stub().returns(projects)
|
|
|
|
@AuthenticationController.getLoggedInUserId = sinon.stub().returns 'abc'
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should produce a list of projects', (done) ->
|
|
|
|
@res.json = (data) =>
|
|
|
|
expect(data).to.deep.equal {
|
|
|
|
projects: [
|
|
|
|
{_id: 'b', name: 'B', accessLevel: 'b'},
|
|
|
|
{_id: 'c', name: 'C', accessLevel: 'c'},
|
|
|
|
{_id: 'd', name: 'D', accessLevel: 'd'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
done()
|
|
|
|
@ProjectController.userProjectsJson @req, @res, @next
|
|
|
|
|
2018-05-22 11:40:39 -04:00
|
|
|
describe 'projectEntitiesJson', ->
|
|
|
|
beforeEach () ->
|
|
|
|
@AuthenticationController.getLoggedInUserId = sinon.stub().returns 'abc'
|
|
|
|
@req.params = {Project_id: 'abcd'}
|
|
|
|
@project = { _id: 'abcd' }
|
|
|
|
@docs = [
|
|
|
|
{path: '/things/b.txt', doc: true},
|
|
|
|
{path: '/main.tex', doc: true}
|
|
|
|
]
|
|
|
|
@files = [
|
|
|
|
{path: '/things/a.txt'}
|
|
|
|
]
|
|
|
|
@ProjectGetter.getProject = sinon.stub().callsArgWith(1, null, @project)
|
|
|
|
@ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub().callsArgWith(1, null, @docs, @files)
|
|
|
|
|
2018-05-24 05:22:17 -04:00
|
|
|
it 'should produce a list of entities', (done) ->
|
|
|
|
@res.json = (data) =>
|
|
|
|
expect(data).to.deep.equal {
|
|
|
|
project_id: 'abcd',
|
|
|
|
entities: [
|
|
|
|
{path: '/main.tex', type: 'doc'},
|
|
|
|
{path: '/things/a.txt', type: 'file'},
|
|
|
|
{path: '/things/b.txt', type: 'doc'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
expect(@ProjectGetter.getProject.callCount).to.equal 1
|
|
|
|
expect(@ProjectEntityHandler.getAllEntitiesFromProject.callCount).to.equal 1
|
|
|
|
done()
|
|
|
|
@ProjectController.projectEntitiesJson @req, @res, @next
|
2018-05-22 11:40:39 -04:00
|
|
|
|
2017-11-10 11:13:27 -05:00
|
|
|
describe '_isInPercentageRollout', ->
|
|
|
|
before ->
|
|
|
|
@ids = [
|
|
|
|
'5a05cd7621f9fe22be131740',
|
|
|
|
'5a05cd7821f9fe22be131741',
|
|
|
|
'5a05cd7921f9fe22be131742',
|
|
|
|
'5a05cd7a21f9fe22be131743',
|
|
|
|
'5a05cd7b21f9fe22be131744',
|
|
|
|
'5a05cd7c21f9fe22be131745',
|
|
|
|
'5a05cd7d21f9fe22be131746',
|
|
|
|
'5a05cd7e21f9fe22be131747',
|
|
|
|
'5a05cd7f21f9fe22be131748',
|
|
|
|
'5a05cd8021f9fe22be131749',
|
|
|
|
'5a05cd8021f9fe22be13174a',
|
|
|
|
'5a05cd8121f9fe22be13174b',
|
|
|
|
'5a05cd8221f9fe22be13174c',
|
|
|
|
'5a05cd8221f9fe22be13174d',
|
|
|
|
'5a05cd8321f9fe22be13174e',
|
|
|
|
'5a05cd8321f9fe22be13174f',
|
|
|
|
'5a05cd8421f9fe22be131750',
|
|
|
|
'5a05cd8421f9fe22be131751',
|
|
|
|
'5a05cd8421f9fe22be131752',
|
|
|
|
'5a05cd8521f9fe22be131753'
|
|
|
|
]
|
|
|
|
|
|
|
|
it 'should produce the expected results', ->
|
2017-11-10 11:19:43 -05:00
|
|
|
expect(
|
|
|
|
@ids.map (i) =>
|
|
|
|
@ProjectController._isInPercentageRollout('abcd', i, 50)
|
|
|
|
).to.deep.equal [
|
2017-11-10 11:13:27 -05:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true
|
2017-11-10 11:19:43 -05:00
|
|
|
]
|
|
|
|
expect(
|
|
|
|
@ids.map (i) =>
|
|
|
|
@ProjectController._isInPercentageRollout('efgh', i, 50)
|
|
|
|
).to.deep.equal [
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
2017-11-10 11:13:27 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|