mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
fix unit tests
This commit is contained in:
parent
8e0103a1bc
commit
438ac45854
20 changed files with 237 additions and 183 deletions
|
@ -100,7 +100,7 @@ module.exports = AuthorizationMiddlewear =
|
||||||
res.redirect "/restricted"
|
res.redirect "/restricted"
|
||||||
|
|
||||||
restricted : (req, res, next)->
|
restricted : (req, res, next)->
|
||||||
if AuthenticationController.isUserLoggedIn()?
|
if AuthenticationController.isUserLoggedIn(req)
|
||||||
res.render 'user/restricted',
|
res.render 'user/restricted',
|
||||||
title:'restricted'
|
title:'restricted'
|
||||||
else
|
else
|
||||||
|
|
|
@ -89,7 +89,7 @@ module.exports = ProjectController =
|
||||||
project_id = req.params.Project_id
|
project_id = req.params.Project_id
|
||||||
projectName = req.body.projectName
|
projectName = req.body.projectName
|
||||||
logger.log project_id:project_id, projectName:projectName, "cloning project"
|
logger.log project_id:project_id, projectName:projectName, "cloning project"
|
||||||
if !AuthenticationController.isUserLoggedIn()?
|
if !AuthenticationController.isUserLoggedIn()
|
||||||
return res.send redir:"/register"
|
return res.send redir:"/register"
|
||||||
currentUser = AuthenticationController.getSessionUser(req)
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
projectDuplicator.duplicate currentUser, project_id, projectName, (err, project)->
|
projectDuplicator.duplicate currentUser, project_id, projectName, (err, project)->
|
||||||
|
@ -186,7 +186,7 @@ module.exports = ProjectController =
|
||||||
if !Settings.editorIsOpen
|
if !Settings.editorIsOpen
|
||||||
return res.render("general/closed", {title:"updating_site"})
|
return res.render("general/closed", {title:"updating_site"})
|
||||||
|
|
||||||
if AuthenticationController.isUserLoggedIn(req)?
|
if AuthenticationController.isUserLoggedIn(req)
|
||||||
user_id = AuthenticationController.getLoggedInUserId(req)
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
||||||
anonymous = false
|
anonymous = false
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,7 +3,7 @@ AuthenticationController = require('../Authentication/AuthenticationController')
|
||||||
|
|
||||||
module.exports = RefererMiddleware =
|
module.exports = RefererMiddleware =
|
||||||
getUserReferalId: (req, res, next) ->
|
getUserReferalId: (req, res, next) ->
|
||||||
if AuthenticationController.isUserLoggedIn()?
|
if AuthenticationController.isUserLoggedIn()
|
||||||
user = AuthenticationController.getSessionUser(req)
|
user = AuthenticationController.getSessionUser(req)
|
||||||
req.user.referal_id = user.referal_id
|
req.user.referal_id = user.referal_id
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -11,7 +11,7 @@ homepageExists = fs.existsSync Path.resolve(__dirname + "/../../../views/externa
|
||||||
|
|
||||||
module.exports = HomeController =
|
module.exports = HomeController =
|
||||||
index : (req,res)->
|
index : (req,res)->
|
||||||
if AuthenticationController.isUserLoggedIn(req)?
|
if AuthenticationController.isUserLoggedIn(req)
|
||||||
if req.query.scribtex_path?
|
if req.query.scribtex_path?
|
||||||
res.redirect "/project?scribtex_path=#{req.query.scribtex_path}"
|
res.redirect "/project?scribtex_path=#{req.query.scribtex_path}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,7 +13,7 @@ module.exports = SubscriptionController =
|
||||||
|
|
||||||
plansPage: (req, res, next) ->
|
plansPage: (req, res, next) ->
|
||||||
plans = SubscriptionViewModelBuilder.buildViewModel()
|
plans = SubscriptionViewModelBuilder.buildViewModel()
|
||||||
if AuthenticationController.isUserLoggedIn(req)?
|
if AuthenticationController.isUserLoggedIn(req)
|
||||||
baseUrl = "/register?redir="
|
baseUrl = "/register?redir="
|
||||||
else
|
else
|
||||||
baseUrl = ""
|
baseUrl = ""
|
||||||
|
|
|
@ -8,19 +8,23 @@ Errors = require "../../../../app/js/Features/Errors/Errors.js"
|
||||||
|
|
||||||
describe "AuthorizationMiddlewear", ->
|
describe "AuthorizationMiddlewear", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@user_id = "user-id-123"
|
||||||
|
@project_id = "project-id-123"
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||||
|
isUserLoggedIn: sinon.stub().returns(true)
|
||||||
@AuthorizationMiddlewear = SandboxedModule.require modulePath, requires:
|
@AuthorizationMiddlewear = SandboxedModule.require modulePath, requires:
|
||||||
"./AuthorizationManager": @AuthorizationManager = {}
|
"./AuthorizationManager": @AuthorizationManager = {}
|
||||||
"logger-sharelatex": {log: () ->}
|
"logger-sharelatex": {log: () ->}
|
||||||
"mongojs": ObjectId: @ObjectId = {}
|
"mongojs": ObjectId: @ObjectId = {}
|
||||||
"../Errors/Errors": Errors
|
"../Errors/Errors": Errors
|
||||||
@user_id = "user-id-123"
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
@project_id = "project-id-123"
|
|
||||||
@req = {}
|
@req = {}
|
||||||
@res = {}
|
@res = {}
|
||||||
@ObjectId.isValid = sinon.stub()
|
@ObjectId.isValid = sinon.stub()
|
||||||
@ObjectId.isValid.withArgs(@project_id).returns true
|
@ObjectId.isValid.withArgs(@project_id).returns true
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
|
|
||||||
METHODS_TO_TEST = {
|
METHODS_TO_TEST = {
|
||||||
"ensureUserCanReadProject": "canUserReadProject"
|
"ensureUserCanReadProject": "canUserReadProject"
|
||||||
"ensureUserCanWriteProjectSettings": "canUserWriteProjectSettings"
|
"ensureUserCanWriteProjectSettings": "canUserWriteProjectSettings"
|
||||||
|
@ -35,26 +39,25 @@ describe "AuthorizationMiddlewear", ->
|
||||||
project_id: @project_id
|
project_id: @project_id
|
||||||
@AuthorizationManager[managerMethod] = sinon.stub()
|
@AuthorizationManager[managerMethod] = sinon.stub()
|
||||||
@AuthorizationMiddlewear.redirectToRestricted = sinon.stub()
|
@AuthorizationMiddlewear.redirectToRestricted = sinon.stub()
|
||||||
|
|
||||||
describe "with missing project_id", ->
|
describe "with missing project_id", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params = {}
|
@req.params = {}
|
||||||
|
|
||||||
it "should return an error to next", ->
|
it "should return an error to next", ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
||||||
@next.calledWith(new Error()).should.equal true
|
@next.calledWith(new Error()).should.equal true
|
||||||
|
|
||||||
describe "with logged in user", ->
|
describe "with logged in user", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.session =
|
@AuthenticationController.getLoggedInUserId.returns(@user_id)
|
||||||
user: _id: @user_id
|
|
||||||
|
|
||||||
describe "when user has permission", ->
|
describe "when user has permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@AuthorizationManager[managerMethod]
|
@AuthorizationManager[managerMethod]
|
||||||
.withArgs(@user_id, @project_id)
|
.withArgs(@user_id, @project_id)
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
@ -64,49 +67,51 @@ describe "AuthorizationMiddlewear", ->
|
||||||
@AuthorizationManager[managerMethod]
|
@AuthorizationManager[managerMethod]
|
||||||
.withArgs(@user_id, @project_id)
|
.withArgs(@user_id, @project_id)
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
@AuthorizationMiddlewear.redirectToRestricted
|
@AuthorizationMiddlewear.redirectToRestricted
|
||||||
.calledWith(@req, @res, @next)
|
.calledWith(@req, @res, @next)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with anonymous user", ->
|
describe "with anonymous user", ->
|
||||||
describe "when user has permission", ->
|
describe "when user has permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager[managerMethod]
|
@AuthorizationManager[managerMethod]
|
||||||
.withArgs(null, @project_id)
|
.withArgs(null, @project_id)
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
|
||||||
describe "when user doesn't have permission", ->
|
describe "when user doesn't have permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager[managerMethod]
|
@AuthorizationManager[managerMethod]
|
||||||
.withArgs(null, @project_id)
|
.withArgs(null, @project_id)
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
@AuthorizationMiddlewear.redirectToRestricted
|
@AuthorizationMiddlewear.redirectToRestricted
|
||||||
.calledWith(@req, @res, @next)
|
.calledWith(@req, @res, @next)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with malformed project id", ->
|
describe "with malformed project id", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params =
|
@req.params =
|
||||||
project_id: "blah"
|
project_id: "blah"
|
||||||
@ObjectId.isValid = sinon.stub().returns false
|
@ObjectId.isValid = sinon.stub().returns false
|
||||||
|
|
||||||
it "should return a not found error", (done) ->
|
it "should return a not found error", (done) ->
|
||||||
@AuthorizationMiddlewear[middlewearMethod] @req, @res, (error) ->
|
@AuthorizationMiddlewear[middlewearMethod] @req, @res, (error) ->
|
||||||
error.should.be.instanceof Errors.NotFoundError
|
error.should.be.instanceof Errors.NotFoundError
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "ensureUserIsSiteAdmin", ->
|
describe "ensureUserIsSiteAdmin", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@AuthorizationManager.isUserSiteAdmin = sinon.stub()
|
@AuthorizationManager.isUserSiteAdmin = sinon.stub()
|
||||||
|
@ -114,15 +119,14 @@ describe "AuthorizationMiddlewear", ->
|
||||||
|
|
||||||
describe "with logged in user", ->
|
describe "with logged in user", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.session =
|
@AuthenticationController.getLoggedInUserId.returns(@user_id)
|
||||||
user: _id: @user_id
|
|
||||||
|
|
||||||
describe "when user has permission", ->
|
describe "when user has permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@AuthorizationManager.isUserSiteAdmin
|
@AuthorizationManager.isUserSiteAdmin
|
||||||
.withArgs(@user_id)
|
.withArgs(@user_id)
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
@ -132,49 +136,50 @@ describe "AuthorizationMiddlewear", ->
|
||||||
@AuthorizationManager.isUserSiteAdmin
|
@AuthorizationManager.isUserSiteAdmin
|
||||||
.withArgs(@user_id)
|
.withArgs(@user_id)
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
@AuthorizationMiddlewear.redirectToRestricted
|
@AuthorizationMiddlewear.redirectToRestricted
|
||||||
.calledWith(@req, @res, @next)
|
.calledWith(@req, @res, @next)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with anonymous user", ->
|
describe "with anonymous user", ->
|
||||||
describe "when user has permission", ->
|
describe "when user has permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager.isUserSiteAdmin
|
@AuthorizationManager.isUserSiteAdmin
|
||||||
.withArgs(null)
|
.withArgs(null)
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
|
||||||
describe "when user doesn't have permission", ->
|
describe "when user doesn't have permission", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager.isUserSiteAdmin
|
@AuthorizationManager.isUserSiteAdmin
|
||||||
.withArgs(null)
|
.withArgs(null)
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserIsSiteAdmin @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
@AuthorizationMiddlewear.redirectToRestricted
|
@AuthorizationMiddlewear.redirectToRestricted
|
||||||
.calledWith(@req, @res, @next)
|
.calledWith(@req, @res, @next)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "ensureUserCanReadMultipleProjects", ->
|
describe "ensureUserCanReadMultipleProjects", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@AuthorizationManager.canUserReadProject = sinon.stub()
|
@AuthorizationManager.canUserReadProject = sinon.stub()
|
||||||
@AuthorizationMiddlewear.redirectToRestricted = sinon.stub()
|
@AuthorizationMiddlewear.redirectToRestricted = sinon.stub()
|
||||||
@req.query =
|
@req.query =
|
||||||
project_ids: "project1,project2"
|
project_ids: "project1,project2"
|
||||||
|
|
||||||
describe "with logged in user", ->
|
describe "with logged in user", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.session =
|
@AuthenticationController.getLoggedInUserId.returns(@user_id)
|
||||||
user: _id: @user_id
|
|
||||||
|
|
||||||
describe "when user has permission to access all projects", ->
|
describe "when user has permission to access all projects", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -184,7 +189,7 @@ describe "AuthorizationMiddlewear", ->
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(@user_id, "project2")
|
.withArgs(@user_id, "project2")
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
@ -197,38 +202,40 @@ describe "AuthorizationMiddlewear", ->
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(@user_id, "project2")
|
.withArgs(@user_id, "project2")
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
@AuthorizationMiddlewear.redirectToRestricted
|
@AuthorizationMiddlewear.redirectToRestricted
|
||||||
.calledWith(@req, @res, @next)
|
.calledWith(@req, @res, @next)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with anonymous user", ->
|
describe "with anonymous user", ->
|
||||||
describe "when user has permission", ->
|
describe "when user has permission", ->
|
||||||
describe "when user has permission to access all projects", ->
|
describe "when user has permission to access all projects", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(null, "project1")
|
.withArgs(null, "project1")
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(null, "project2")
|
.withArgs(null, "project2")
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
|
|
||||||
it "should return next", ->
|
it "should return next", ->
|
||||||
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
|
||||||
describe "when user doesn't have permission to access one of the projects", ->
|
describe "when user doesn't have permission to access one of the projects", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController.getLoggedInUserId.returns(null)
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(null, "project1")
|
.withArgs(null, "project1")
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
@AuthorizationManager.canUserReadProject
|
@AuthorizationManager.canUserReadProject
|
||||||
.withArgs(null, "project2")
|
.withArgs(null, "project2")
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
|
|
||||||
it "should redirect to redirectToRestricted", ->
|
it "should redirect to redirectToRestricted", ->
|
||||||
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
@AuthorizationMiddlewear.ensureUserCanReadMultipleProjects @req, @res, @next
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
|
|
|
@ -10,19 +10,24 @@ describe "ChatController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
|
@user_id = 'ier_'
|
||||||
@settings = {}
|
@settings = {}
|
||||||
@ChatHandler =
|
@ChatHandler =
|
||||||
sendMessage:sinon.stub()
|
sendMessage:sinon.stub()
|
||||||
getMessages:sinon.stub()
|
getMessages:sinon.stub()
|
||||||
|
|
||||||
@EditorRealTimeController =
|
@EditorRealTimeController =
|
||||||
emitToRoom:sinon.stub().callsArgWith(3)
|
emitToRoom:sinon.stub().callsArgWith(3)
|
||||||
|
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||||
@ChatController = SandboxedModule.require modulePath, requires:
|
@ChatController = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex": log:->
|
"logger-sharelatex": log:->
|
||||||
"./ChatHandler":@ChatHandler
|
"./ChatHandler":@ChatHandler
|
||||||
"../Editor/EditorRealTimeController":@EditorRealTimeController
|
"../Editor/EditorRealTimeController":@EditorRealTimeController
|
||||||
@query =
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
@query =
|
||||||
before:"some time"
|
before:"some time"
|
||||||
|
|
||||||
@req =
|
@req =
|
||||||
|
@ -74,4 +79,3 @@ describe "ChatController", ->
|
||||||
sentMessages.should.deep.equal messages
|
sentMessages.should.deep.equal messages
|
||||||
done()
|
done()
|
||||||
@ChatController.getMessages @req, @res
|
@ChatController.getMessages @req, @res
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,11 @@ ObjectId = require("mongojs").ObjectId
|
||||||
|
|
||||||
describe "CollaboratorsInviteController", ->
|
describe "CollaboratorsInviteController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@user =
|
||||||
|
_id: 'id'
|
||||||
@AnalyticsManger = recordEvent: sinon.stub()
|
@AnalyticsManger = recordEvent: sinon.stub()
|
||||||
|
@AuthenticationController =
|
||||||
|
getSessionUser: (req) => req.session.user
|
||||||
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
||||||
"../Project/ProjectGetter": @ProjectGetter = {}
|
"../Project/ProjectGetter": @ProjectGetter = {}
|
||||||
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
||||||
|
@ -22,6 +26,7 @@ describe "CollaboratorsInviteController", ->
|
||||||
"../Editor/EditorRealTimeController": @EditorRealTimeController = {emitToRoom: sinon.stub()}
|
"../Editor/EditorRealTimeController": @EditorRealTimeController = {emitToRoom: sinon.stub()}
|
||||||
"../Notifications/NotificationsBuilder": @NotificationsBuilder = {}
|
"../Notifications/NotificationsBuilder": @NotificationsBuilder = {}
|
||||||
"../Analytics/AnalyticsManager": @AnalyticsManger
|
"../Analytics/AnalyticsManager": @AnalyticsManger
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
@res = new MockResponse()
|
@res = new MockResponse()
|
||||||
@req = new MockRequest()
|
@req = new MockRequest()
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,17 @@ MockResponse = require "../helpers/MockResponse"
|
||||||
|
|
||||||
describe "CompileController", ->
|
describe "CompileController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@CompileManager =
|
@user_id = 'wat'
|
||||||
|
@user =
|
||||||
|
_id: @user_id
|
||||||
|
email: 'user@example.com'
|
||||||
|
features:
|
||||||
|
compileGroup: "premium"
|
||||||
|
compileTimeout: 100
|
||||||
|
@CompileManager =
|
||||||
compile: sinon.stub()
|
compile: sinon.stub()
|
||||||
@ClsiManager = {}
|
@ClsiManager = {}
|
||||||
@UserGetter =
|
@UserGetter =
|
||||||
getUser:sinon.stub()
|
getUser:sinon.stub()
|
||||||
@RateLimiter = {addCount:sinon.stub()}
|
@RateLimiter = {addCount:sinon.stub()}
|
||||||
@settings =
|
@settings =
|
||||||
|
@ -23,8 +30,13 @@ describe "CompileController", ->
|
||||||
clsi_priority:
|
clsi_priority:
|
||||||
url: "clsi-priority.example.com"
|
url: "clsi-priority.example.com"
|
||||||
@jar = {cookie:"stuff"}
|
@jar = {cookie:"stuff"}
|
||||||
@ClsiCookieManager =
|
@ClsiCookieManager =
|
||||||
getCookieJar:sinon.stub().callsArgWith(1, null, @jar)
|
getCookieJar:sinon.stub().callsArgWith(1, null, @jar)
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUser: sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||||
|
getSessionUser: sinon.stub().returns(@user)
|
||||||
|
isUserLoggedIn: sinon.stub().returns(true)
|
||||||
@CompileController = SandboxedModule.require modulePath, requires:
|
@CompileController = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
"request": @request = sinon.stub()
|
"request": @request = sinon.stub()
|
||||||
|
@ -34,18 +46,13 @@ describe "CompileController", ->
|
||||||
"./CompileManager":@CompileManager
|
"./CompileManager":@CompileManager
|
||||||
"../User/UserGetter":@UserGetter
|
"../User/UserGetter":@UserGetter
|
||||||
"./ClsiManager": @ClsiManager
|
"./ClsiManager": @ClsiManager
|
||||||
"../Authentication/AuthenticationController": @AuthenticationController = {}
|
"../Authentication/AuthenticationController": @AuthenticationController
|
||||||
"../../infrastructure/RateLimiter":@RateLimiter
|
"../../infrastructure/RateLimiter":@RateLimiter
|
||||||
"./ClsiCookieManager":@ClsiCookieManager
|
"./ClsiCookieManager":@ClsiCookieManager
|
||||||
@project_id = "project-id"
|
@project_id = "project-id"
|
||||||
@user =
|
|
||||||
features:
|
|
||||||
compileGroup: "premium"
|
|
||||||
compileTimeout: 100
|
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
@req = new MockRequest()
|
@req = new MockRequest()
|
||||||
@res = new MockResponse()
|
@res = new MockResponse()
|
||||||
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id")
|
|
||||||
|
|
||||||
describe "compile", ->
|
describe "compile", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -90,7 +97,7 @@ describe "CompileController", ->
|
||||||
@CompileManager.compile
|
@CompileManager.compile
|
||||||
.calledWith(@project_id, @user_id, { isAutoCompile: true })
|
.calledWith(@project_id, @user_id, { isAutoCompile: true })
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with the draft attribute", ->
|
describe "with the draft attribute", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.body =
|
@req.body =
|
||||||
|
@ -108,7 +115,7 @@ describe "CompileController", ->
|
||||||
Project_id: @project_id
|
Project_id: @project_id
|
||||||
@project =
|
@project =
|
||||||
getSafeProjectName: () => @safe_name = "safe-name"
|
getSafeProjectName: () => @safe_name = "safe-name"
|
||||||
|
|
||||||
@req.query = {pdfng:true}
|
@req.query = {pdfng:true}
|
||||||
@Project.findById = sinon.stub().callsArgWith(2, null, @project)
|
@Project.findById = sinon.stub().callsArgWith(2, null, @project)
|
||||||
|
|
||||||
|
@ -340,9 +347,9 @@ describe "CompileController", ->
|
||||||
project_id:@project_id
|
project_id:@project_id
|
||||||
@CompileManager.compile.callsArgWith(3)
|
@CompileManager.compile.callsArgWith(3)
|
||||||
@CompileController.proxyToClsi = sinon.stub()
|
@CompileController.proxyToClsi = sinon.stub()
|
||||||
@res =
|
@res =
|
||||||
send:=>
|
send:=>
|
||||||
|
|
||||||
it "should call compile in the compile manager", (done)->
|
it "should call compile in the compile manager", (done)->
|
||||||
@CompileController.compileAndDownloadPdf @req, @res
|
@CompileController.compileAndDownloadPdf @req, @res
|
||||||
@CompileManager.compile.calledWith(@project_id).should.equal true
|
@CompileManager.compile.calledWith(@project_id).should.equal true
|
||||||
|
|
|
@ -8,12 +8,15 @@ SandboxedModule = require('sandboxed-module')
|
||||||
|
|
||||||
describe "ContactController", ->
|
describe "ContactController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub()
|
||||||
@ContactController = SandboxedModule.require modulePath, requires:
|
@ContactController = SandboxedModule.require modulePath, requires:
|
||||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||||
"../User/UserGetter": @UserGetter = {}
|
"../User/UserGetter": @UserGetter = {}
|
||||||
"./ContactManager": @ContactManager = {}
|
"./ContactManager": @ContactManager = {}
|
||||||
"../Authentication/AuthenticationController": @AuthenticationController = {}
|
"../Authentication/AuthenticationController": @AuthenticationController = {}
|
||||||
"../../infrastructure/Modules": @Modules = { hooks: {} }
|
"../../infrastructure/Modules": @Modules = { hooks: {} }
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
@req = {}
|
@req = {}
|
||||||
|
@ -30,33 +33,33 @@ describe "ContactController", ->
|
||||||
{ _id: "contact-2", email: "jane@example.com", first_name: "Jane", last_name: "Example", unsued: "foo", holdingAccount: true }
|
{ _id: "contact-2", email: "jane@example.com", first_name: "Jane", last_name: "Example", unsued: "foo", holdingAccount: true }
|
||||||
{ _id: "contact-3", email: "jim@example.com", first_name: "Jim", last_name: "Example", unsued: "foo" }
|
{ _id: "contact-3", email: "jim@example.com", first_name: "Jim", last_name: "Example", unsued: "foo" }
|
||||||
]
|
]
|
||||||
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id)
|
@AuthenticationController.getLoggedInUserId = sinon.stub().returns(@user_id)
|
||||||
@ContactManager.getContactIds = sinon.stub().callsArgWith(2, null, @contact_ids)
|
@ContactManager.getContactIds = sinon.stub().callsArgWith(2, null, @contact_ids)
|
||||||
@UserGetter.getUsers = sinon.stub().callsArgWith(2, null, @contacts)
|
@UserGetter.getUsers = sinon.stub().callsArgWith(2, null, @contacts)
|
||||||
@Modules.hooks.fire = sinon.stub().callsArg(3)
|
@Modules.hooks.fire = sinon.stub().callsArg(3)
|
||||||
|
|
||||||
@ContactController.getContacts @req, @res, @next
|
@ContactController.getContacts @req, @res, @next
|
||||||
|
|
||||||
it "should look up the logged in user id", ->
|
it "should look up the logged in user id", ->
|
||||||
@AuthenticationController.getLoggedInUserId
|
@AuthenticationController.getLoggedInUserId
|
||||||
.calledWith(@req)
|
.calledWith(@req)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should get the users contact ids", ->
|
it "should get the users contact ids", ->
|
||||||
@ContactManager.getContactIds
|
@ContactManager.getContactIds
|
||||||
.calledWith(@user_id, { limit: 50 })
|
.calledWith(@user_id, { limit: 50 })
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should populate the users contacts ids", ->
|
it "should populate the users contacts ids", ->
|
||||||
@UserGetter.getUsers
|
@UserGetter.getUsers
|
||||||
.calledWith(@contact_ids, { email: 1, first_name: 1, last_name: 1, holdingAccount: 1 })
|
.calledWith(@contact_ids, { email: 1, first_name: 1, last_name: 1, holdingAccount: 1 })
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should fire the getContact module hook", ->
|
it "should fire the getContact module hook", ->
|
||||||
@Modules.hooks.fire
|
@Modules.hooks.fire
|
||||||
.calledWith("getContacts", @user_id)
|
.calledWith("getContacts", @user_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return a formatted list of contacts in contact list order, without holding accounts", ->
|
it "should return a formatted list of contacts in contact list order, without holding accounts", ->
|
||||||
@res.send.args[0][0].contacts.should.deep.equal [
|
@res.send.args[0][0].contacts.should.deep.equal [
|
||||||
{ id: "contact-1", email: "joe@example.com", first_name: "Joe", last_name: "Example", type: "user" }
|
{ id: "contact-1", email: "joe@example.com", first_name: "Joe", last_name: "Example", type: "user" }
|
||||||
|
|
|
@ -10,16 +10,9 @@ describe 'NotificationsController', ->
|
||||||
notification_id = "123njdskj9jlk"
|
notification_id = "123njdskj9jlk"
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@handler =
|
@handler =
|
||||||
getUserNotifications: sinon.stub().callsArgWith(1)
|
getUserNotifications: sinon.stub().callsArgWith(1)
|
||||||
markAsRead: sinon.stub().callsArgWith(2)
|
markAsRead: sinon.stub().callsArgWith(2)
|
||||||
@controller = SandboxedModule.require modulePath, requires:
|
|
||||||
"./NotificationsHandler":@handler
|
|
||||||
"underscore":@underscore =
|
|
||||||
map:(arr)-> return arr
|
|
||||||
'logger-sharelatex':
|
|
||||||
log:->
|
|
||||||
err:->
|
|
||||||
@req =
|
@req =
|
||||||
params:
|
params:
|
||||||
notification_id:notification_id
|
notification_id:notification_id
|
||||||
|
@ -28,6 +21,16 @@ describe 'NotificationsController', ->
|
||||||
_id:user_id
|
_id:user_id
|
||||||
i18n:
|
i18n:
|
||||||
translate:->
|
translate:->
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
|
||||||
|
@controller = SandboxedModule.require modulePath, requires:
|
||||||
|
"./NotificationsHandler":@handler
|
||||||
|
"underscore":@underscore =
|
||||||
|
map:(arr)-> return arr
|
||||||
|
'logger-sharelatex':
|
||||||
|
log:->
|
||||||
|
err:->
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
|
||||||
it 'should ask the handler for all unread notifications', (done)->
|
it 'should ask the handler for all unread notifications', (done)->
|
||||||
allNotifications = [{_id: notification_id, user_id: user_id}]
|
allNotifications = [{_id: notification_id, user_id: user_id}]
|
||||||
|
|
|
@ -12,12 +12,15 @@ describe "ProjectController", ->
|
||||||
|
|
||||||
@project_id = "123213jlkj9kdlsaj"
|
@project_id = "123213jlkj9kdlsaj"
|
||||||
|
|
||||||
@settings =
|
@user =
|
||||||
|
_id:"!£123213kjljkl"
|
||||||
|
first_name: "bjkdsjfk"
|
||||||
|
@settings =
|
||||||
apis:
|
apis:
|
||||||
chat:
|
chat:
|
||||||
url:"chat.com"
|
url:"chat.com"
|
||||||
siteUrl: "mysite.com"
|
siteUrl: "mysite.com"
|
||||||
@ProjectDeleter =
|
@ProjectDeleter =
|
||||||
archiveProject: sinon.stub().callsArg(1)
|
archiveProject: sinon.stub().callsArg(1)
|
||||||
deleteProject: sinon.stub().callsArg(1)
|
deleteProject: sinon.stub().callsArg(1)
|
||||||
restoreProject: sinon.stub().callsArg(1)
|
restoreProject: sinon.stub().callsArg(1)
|
||||||
|
@ -29,7 +32,7 @@ describe "ProjectController", ->
|
||||||
createBasicProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
createBasicProject: sinon.stub().callsArgWith(2, null, {_id:@project_id})
|
||||||
@SubscriptionLocator =
|
@SubscriptionLocator =
|
||||||
getUsersSubscription: sinon.stub()
|
getUsersSubscription: sinon.stub()
|
||||||
@LimitationsManager =
|
@LimitationsManager =
|
||||||
userHasSubscriptionOrIsGroupMember: sinon.stub()
|
userHasSubscriptionOrIsGroupMember: sinon.stub()
|
||||||
@TagsHandler =
|
@TagsHandler =
|
||||||
getAllTags: sinon.stub()
|
getAllTags: sinon.stub()
|
||||||
|
@ -39,7 +42,7 @@ describe "ProjectController", ->
|
||||||
findById: sinon.stub()
|
findById: sinon.stub()
|
||||||
@AuthorizationManager =
|
@AuthorizationManager =
|
||||||
getPrivilegeLevelForProject:sinon.stub()
|
getPrivilegeLevelForProject:sinon.stub()
|
||||||
@EditorController =
|
@EditorController =
|
||||||
renameProject:sinon.stub()
|
renameProject:sinon.stub()
|
||||||
@InactiveProjectManager =
|
@InactiveProjectManager =
|
||||||
reactivateProjectIfRequired:sinon.stub()
|
reactivateProjectIfRequired:sinon.stub()
|
||||||
|
@ -50,12 +53,17 @@ describe "ProjectController", ->
|
||||||
@ProjectGetter =
|
@ProjectGetter =
|
||||||
findAllUsersProjects: sinon.stub()
|
findAllUsersProjects: sinon.stub()
|
||||||
getProject: sinon.stub()
|
getProject: sinon.stub()
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUser: sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user._id)
|
||||||
|
getSessionUser: sinon.stub().returns(@user)
|
||||||
|
isUserLoggedIn: sinon.stub().returns(true)
|
||||||
@ProjectController = SandboxedModule.require modulePath, requires:
|
@ProjectController = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
"../../infrastructure/Metrics":
|
"../../infrastructure/Metrics":
|
||||||
Timer:->
|
Timer:->
|
||||||
done:->
|
done:->
|
||||||
inc:->
|
inc:->
|
||||||
|
@ -73,21 +81,19 @@ describe "ProjectController", ->
|
||||||
"./ProjectUpdateHandler":@ProjectUpdateHandler
|
"./ProjectUpdateHandler":@ProjectUpdateHandler
|
||||||
"../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler
|
"../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler
|
||||||
"./ProjectGetter": @ProjectGetter
|
"./ProjectGetter": @ProjectGetter
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
|
||||||
@user =
|
|
||||||
_id:"!£123213kjljkl"
|
|
||||||
first_name: "bjkdsjfk"
|
|
||||||
@projectName = "£12321jkj9ujkljds"
|
@projectName = "£12321jkj9ujkljds"
|
||||||
@req =
|
@req =
|
||||||
params:
|
params:
|
||||||
Project_id: @project_id
|
Project_id: @project_id
|
||||||
session:
|
session:
|
||||||
user: @user
|
user: @user
|
||||||
body:
|
body:
|
||||||
projectName: @projectName
|
projectName: @projectName
|
||||||
i18n:
|
i18n:
|
||||||
translate:->
|
translate:->
|
||||||
@res =
|
@res =
|
||||||
locals:
|
locals:
|
||||||
jsPath:"js path here"
|
jsPath:"js path here"
|
||||||
|
|
||||||
|
@ -139,7 +145,7 @@ describe "ProjectController", ->
|
||||||
code.should.equal 204
|
code.should.equal 204
|
||||||
done()
|
done()
|
||||||
@ProjectController.updateProjectSettings @req, @res
|
@ProjectController.updateProjectSettings @req, @res
|
||||||
|
|
||||||
describe "updateProjectAdminSettings", ->
|
describe "updateProjectAdminSettings", ->
|
||||||
it "should update the public access level", (done) ->
|
it "should update the public access level", (done) ->
|
||||||
@EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
@EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
||||||
|
@ -178,7 +184,7 @@ describe "ProjectController", ->
|
||||||
@ProjectController.restoreProject @req, @res
|
@ProjectController.restoreProject @req, @res
|
||||||
|
|
||||||
describe "cloneProject", ->
|
describe "cloneProject", ->
|
||||||
it "should call the project duplicator", (done)->
|
it "should call the project duplicator", (done)->
|
||||||
@res.send = (json)=>
|
@res.send = (json)=>
|
||||||
@ProjectDuplicator.duplicate.calledWith(@user, @project_id, @projectName).should.equal true
|
@ProjectDuplicator.duplicate.calledWith(@user, @project_id, @projectName).should.equal true
|
||||||
json.project_id.should.equal @project_id
|
json.project_id.should.equal @project_id
|
||||||
|
@ -214,7 +220,7 @@ describe "ProjectController", ->
|
||||||
@readOnly = [{lastUpdated:3, _id:3, owner_ref: "user-1"}]
|
@readOnly = [{lastUpdated:3, _id:3, owner_ref: "user-1"}]
|
||||||
|
|
||||||
@users =
|
@users =
|
||||||
'user-1':
|
'user-1':
|
||||||
first_name: 'James'
|
first_name: 'James'
|
||||||
'user-2':
|
'user-2':
|
||||||
first_name: 'Henry'
|
first_name: 'Henry'
|
||||||
|
@ -289,10 +295,10 @@ describe "ProjectController", ->
|
||||||
describe "loadEditor", ->
|
describe "loadEditor", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@settings.editorIsOpen = true
|
@settings.editorIsOpen = true
|
||||||
@project =
|
@project =
|
||||||
name:"my proj"
|
name:"my proj"
|
||||||
_id:"213123kjlkj"
|
_id:"213123kjlkj"
|
||||||
@user =
|
@user =
|
||||||
_id:"123kj21k3lj"
|
_id:"123kj21k3lj"
|
||||||
ace:
|
ace:
|
||||||
fontSize:"massive"
|
fontSize:"massive"
|
||||||
|
@ -351,4 +357,3 @@ describe "ProjectController", ->
|
||||||
@ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true
|
@ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true
|
||||||
done()
|
done()
|
||||||
@ProjectController.loadEditor @req, @res
|
@ProjectController.loadEditor @req, @res
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,13 @@ modulePath = require('path').join __dirname, '../../../../app/js/Features/Securi
|
||||||
|
|
||||||
describe "RateLimiterMiddlewear", ->
|
describe "RateLimiterMiddlewear", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: () =>
|
||||||
|
@req?.session?.user?._id
|
||||||
@RateLimiterMiddlewear = SandboxedModule.require modulePath, requires:
|
@RateLimiterMiddlewear = SandboxedModule.require modulePath, requires:
|
||||||
'../../infrastructure/RateLimiter' : @RateLimiter = {}
|
'../../infrastructure/RateLimiter' : @RateLimiter = {}
|
||||||
"logger-sharelatex": @logger = {warn: sinon.stub()}
|
"logger-sharelatex": @logger = {warn: sinon.stub()}
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
@req =
|
@req =
|
||||||
params: {}
|
params: {}
|
||||||
@res =
|
@res =
|
||||||
|
@ -15,7 +19,7 @@ describe "RateLimiterMiddlewear", ->
|
||||||
write: sinon.stub()
|
write: sinon.stub()
|
||||||
end: sinon.stub()
|
end: sinon.stub()
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
|
|
||||||
describe "rateLimit", ->
|
describe "rateLimit", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@rateLimiter = @RateLimiterMiddlewear.rateLimit({
|
@rateLimiter = @RateLimiterMiddlewear.rateLimit({
|
||||||
|
@ -28,7 +32,7 @@ describe "RateLimiterMiddlewear", ->
|
||||||
project_id: @project_id = "project-id"
|
project_id: @project_id = "project-id"
|
||||||
doc_id: @doc_id = "doc-id"
|
doc_id: @doc_id = "doc-id"
|
||||||
}
|
}
|
||||||
|
|
||||||
describe "when there is no session", ->
|
describe "when there is no session", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
||||||
|
@ -44,18 +48,18 @@ describe "RateLimiterMiddlewear", ->
|
||||||
subjectName: "#{@project_id}:#{@doc_id}:#{@ip}"
|
subjectName: "#{@project_id}:#{@doc_id}:#{@ip}"
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should pass on to next()", ->
|
it "should pass on to next()", ->
|
||||||
|
|
||||||
|
|
||||||
describe "when under the rate limit with logged in user", ->
|
describe "when under the rate limit with logged in user", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.session =
|
@req.session =
|
||||||
user :
|
user :
|
||||||
_id: @user_id = "user-id"
|
_id: @user_id = "user-id"
|
||||||
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
||||||
@rateLimiter(@req, @res, @next)
|
@rateLimiter(@req, @res, @next)
|
||||||
|
|
||||||
it "should call the rate limiter backend with the user_id", ->
|
it "should call the rate limiter backend with the user_id", ->
|
||||||
@RateLimiter.addCount
|
@RateLimiter.addCount
|
||||||
.calledWith({
|
.calledWith({
|
||||||
|
@ -65,16 +69,16 @@ describe "RateLimiterMiddlewear", ->
|
||||||
subjectName: "#{@project_id}:#{@doc_id}:#{@user_id}"
|
subjectName: "#{@project_id}:#{@doc_id}:#{@user_id}"
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should pass on to next()", ->
|
it "should pass on to next()", ->
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
|
||||||
describe "when under the rate limit with anonymous user", ->
|
describe "when under the rate limit with anonymous user", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.ip = @ip = "1.2.3.4"
|
@req.ip = @ip = "1.2.3.4"
|
||||||
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
|
||||||
@rateLimiter(@req, @res, @next)
|
@rateLimiter(@req, @res, @next)
|
||||||
|
|
||||||
it "should call the rate limiter backend with the ip address", ->
|
it "should call the rate limiter backend with the ip address", ->
|
||||||
@RateLimiter.addCount
|
@RateLimiter.addCount
|
||||||
.calledWith({
|
.calledWith({
|
||||||
|
@ -84,25 +88,25 @@ describe "RateLimiterMiddlewear", ->
|
||||||
subjectName: "#{@project_id}:#{@doc_id}:#{@ip}"
|
subjectName: "#{@project_id}:#{@doc_id}:#{@ip}"
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should pass on to next()", ->
|
it "should pass on to next()", ->
|
||||||
@next.called.should.equal true
|
@next.called.should.equal true
|
||||||
|
|
||||||
describe "when over the rate limit", ->
|
describe "when over the rate limit", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.session =
|
@req.session =
|
||||||
user :
|
user :
|
||||||
_id: @user_id = "user-id"
|
_id: @user_id = "user-id"
|
||||||
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, false)
|
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, false)
|
||||||
@rateLimiter(@req, @res, @next)
|
@rateLimiter(@req, @res, @next)
|
||||||
|
|
||||||
it "should return a 429", ->
|
it "should return a 429", ->
|
||||||
@res.status.calledWith(429).should.equal true
|
@res.status.calledWith(429).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
it "should not continue", ->
|
it "should not continue", ->
|
||||||
@next.called.should.equal false
|
@next.called.should.equal false
|
||||||
|
|
||||||
it "should log a warning", ->
|
it "should log a warning", ->
|
||||||
@logger.warn
|
@logger.warn
|
||||||
.calledWith({
|
.calledWith({
|
||||||
|
@ -112,4 +116,3 @@ describe "RateLimiterMiddlewear", ->
|
||||||
subjectName: "#{@project_id}:#{@doc_id}:#{@user_id}"
|
subjectName: "#{@project_id}:#{@doc_id}:#{@user_id}"
|
||||||
}, "rate limit exceeded")
|
}, "rate limit exceeded")
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
|
@ -20,12 +20,15 @@ mockSubscriptions =
|
||||||
describe "SubscriptionController sanboxed", ->
|
describe "SubscriptionController sanboxed", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = {email:"tom@yahoo.com"}
|
@user = {email:"tom@yahoo.com", _id: 'one'}
|
||||||
@activeRecurlySubscription = mockSubscriptions["subscription-123-active"]
|
@activeRecurlySubscription = mockSubscriptions["subscription-123-active"]
|
||||||
|
|
||||||
@AuthenticationController =
|
@AuthenticationController =
|
||||||
getLoggedInUser: sinon.stub().callsArgWith(1, null, @user)
|
getLoggedInUser: sinon.stub().callsArgWith(1, null, @user)
|
||||||
@SubscriptionHandler =
|
getLoggedInUserId: sinon.stub().returns(@user._id)
|
||||||
|
getSessionUser: sinon.stub().returns(@user)
|
||||||
|
isUserLoggedIn: sinon.stub().returns(true)
|
||||||
|
@SubscriptionHandler =
|
||||||
createSubscription: sinon.stub().callsArgWith(3)
|
createSubscription: sinon.stub().callsArgWith(3)
|
||||||
updateSubscription: sinon.stub().callsArgWith(3)
|
updateSubscription: sinon.stub().callsArgWith(3)
|
||||||
reactivateSubscription: sinon.stub().callsArgWith(1)
|
reactivateSubscription: sinon.stub().callsArgWith(1)
|
||||||
|
@ -36,19 +39,19 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@PlansLocator =
|
@PlansLocator =
|
||||||
findLocalPlanInSettings: sinon.stub()
|
findLocalPlanInSettings: sinon.stub()
|
||||||
|
|
||||||
@LimitationsManager =
|
@LimitationsManager =
|
||||||
userHasSubscriptionOrIsGroupMember: sinon.stub()
|
userHasSubscriptionOrIsGroupMember: sinon.stub()
|
||||||
userHasSubscription : sinon.stub()
|
userHasSubscription : sinon.stub()
|
||||||
|
|
||||||
@RecurlyWrapper =
|
@RecurlyWrapper =
|
||||||
sign: sinon.stub().callsArgWith(1, null, "somthing")
|
sign: sinon.stub().callsArgWith(1, null, "somthing")
|
||||||
|
|
||||||
@SubscriptionViewModelBuilder =
|
@SubscriptionViewModelBuilder =
|
||||||
buildUsersSubscriptionViewModel:sinon.stub().callsArgWith(1, null, @activeRecurlySubscription)
|
buildUsersSubscriptionViewModel:sinon.stub().callsArgWith(1, null, @activeRecurlySubscription)
|
||||||
buildViewModel: sinon.stub()
|
buildViewModel: sinon.stub()
|
||||||
@settings =
|
@settings =
|
||||||
coupon_codes:
|
coupon_codes:
|
||||||
upgradeToAnnualPromo:
|
upgradeToAnnualPromo:
|
||||||
student:"STUDENTCODEHERE"
|
student:"STUDENTCODEHERE"
|
||||||
collaborator:"COLLABORATORCODEHERE"
|
collaborator:"COLLABORATORCODEHERE"
|
||||||
apis:
|
apis:
|
||||||
|
@ -58,8 +61,8 @@ describe "SubscriptionController sanboxed", ->
|
||||||
gaExperiments:{}
|
gaExperiments:{}
|
||||||
@GeoIpLookup =
|
@GeoIpLookup =
|
||||||
getCurrencyCode:sinon.stub()
|
getCurrencyCode:sinon.stub()
|
||||||
@SubscriptionDomainHandler =
|
@SubscriptionDomainHandler =
|
||||||
getDomainLicencePage:sinon.stub()
|
getDomainLicencePage:sinon.stub()
|
||||||
@SubscriptionController = SandboxedModule.require modulePath, requires:
|
@SubscriptionController = SandboxedModule.require modulePath, requires:
|
||||||
'../Authentication/AuthenticationController': @AuthenticationController
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
'./SubscriptionHandler': @SubscriptionHandler
|
'./SubscriptionHandler': @SubscriptionHandler
|
||||||
|
@ -68,7 +71,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
"./LimitationsManager": @LimitationsManager
|
"./LimitationsManager": @LimitationsManager
|
||||||
"../../infrastructure/GeoIpLookup":@GeoIpLookup
|
"../../infrastructure/GeoIpLookup":@GeoIpLookup
|
||||||
'./RecurlyWrapper': @RecurlyWrapper
|
'./RecurlyWrapper': @RecurlyWrapper
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
warn:->
|
warn:->
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
|
@ -78,7 +81,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@res = new MockResponse()
|
@res = new MockResponse()
|
||||||
@req = new MockRequest()
|
@req = new MockRequest()
|
||||||
@req.body = {}
|
@req.body = {}
|
||||||
@req.query =
|
@req.query =
|
||||||
planCode:"123123"
|
planCode:"123123"
|
||||||
|
|
||||||
@stubbedCurrencyCode = "GBP"
|
@stubbedCurrencyCode = "GBP"
|
||||||
|
@ -175,7 +178,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@res.render = (page, opts)=>
|
@res.render = (page, opts)=>
|
||||||
opts.currency.should.equal "EUR"
|
opts.currency.should.equal "EUR"
|
||||||
done()
|
done()
|
||||||
@SubscriptionController.paymentPage @req, @res
|
@SubscriptionController.paymentPage @req, @res
|
||||||
|
|
||||||
|
|
||||||
it "should use the geo ip currency if non is provided", (done)->
|
it "should use the geo ip currency if non is provided", (done)->
|
||||||
|
@ -183,8 +186,8 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@res.render = (page, opts)=>
|
@res.render = (page, opts)=>
|
||||||
opts.currency.should.equal @stubbedCurrencyCode
|
opts.currency.should.equal @stubbedCurrencyCode
|
||||||
done()
|
done()
|
||||||
@SubscriptionController.paymentPage @req, @res
|
@SubscriptionController.paymentPage @req, @res
|
||||||
|
|
||||||
describe "successful_subscription", ->
|
describe "successful_subscription", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, {})
|
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, {})
|
||||||
|
@ -226,7 +229,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
|
|
||||||
it "should render the dashboard", ->
|
it "should render the dashboard", ->
|
||||||
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
||||||
|
|
||||||
describe "with a user with a paid subscription", ->
|
describe "with a user with a paid subscription", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@res.callback = done
|
@res.callback = done
|
||||||
|
@ -238,7 +241,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@res.rendered.should.equal true
|
@res.rendered.should.equal true
|
||||||
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should set the correct subscription details", ->
|
it "should set the correct subscription details", ->
|
||||||
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
|
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
|
||||||
|
|
||||||
|
@ -251,7 +254,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
|
|
||||||
it "should render the dashboard", ->
|
it "should render the dashboard", ->
|
||||||
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
@res.renderedTemplate.should.equal "subscriptions/dashboard"
|
||||||
|
|
||||||
it "should set the correct subscription details", ->
|
it "should set the correct subscription details", ->
|
||||||
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
|
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
|
||||||
|
|
||||||
|
@ -431,7 +434,7 @@ describe "SubscriptionController sanboxed", ->
|
||||||
describe "processUpgradeToAnnualPlan", ->
|
describe "processUpgradeToAnnualPlan", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
it "should tell the subscription handler to update the subscription with the annual plan and apply a coupon code", (done)->
|
it "should tell the subscription handler to update the subscription with the annual plan and apply a coupon code", (done)->
|
||||||
@req.body =
|
@req.body =
|
||||||
planName:"student"
|
planName:"student"
|
||||||
|
@ -452,6 +455,3 @@ describe "SubscriptionController sanboxed", ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
@SubscriptionController.processUpgradeToAnnualPlan @req, @res
|
@SubscriptionController.processUpgradeToAnnualPlan @req, @res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,19 @@ describe "SubscriptionGroupController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = {_id:"!@312431",email:"user@email.com"}
|
@user = {_id:"!@312431",email:"user@email.com"}
|
||||||
|
@adminUserId = "123jlkj"
|
||||||
|
@subscription_id = "123434325412"
|
||||||
|
@user_email = "bob@gmail.com"
|
||||||
|
@req =
|
||||||
|
session:
|
||||||
|
user:
|
||||||
|
_id: @adminUserId
|
||||||
|
email:@user_email
|
||||||
|
params:
|
||||||
|
subscription_id:@subscription_id
|
||||||
|
query:{}
|
||||||
@subscription = {}
|
@subscription = {}
|
||||||
@GroupHandler =
|
@GroupHandler =
|
||||||
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
||||||
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
||||||
isUserPartOfGroup: sinon.stub()
|
isUserPartOfGroup: sinon.stub()
|
||||||
|
@ -18,15 +29,18 @@ describe "SubscriptionGroupController", ->
|
||||||
processGroupVerification:sinon.stub()
|
processGroupVerification:sinon.stub()
|
||||||
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
|
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
|
||||||
@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: (req) -> req.session.user._id
|
||||||
|
getSessionUser: (req) -> req.session.user
|
||||||
|
|
||||||
@SubscriptionDomainHandler =
|
@SubscriptionDomainHandler =
|
||||||
findDomainLicenceBySubscriptionId:sinon.stub()
|
findDomainLicenceBySubscriptionId:sinon.stub()
|
||||||
|
|
||||||
@OneTimeTokenHandler =
|
@OneTimeTokenHandler =
|
||||||
getValueFromTokenAndExpire:sinon.stub()
|
getValueFromTokenAndExpire:sinon.stub()
|
||||||
|
|
||||||
|
|
||||||
@ErrorsController =
|
@ErrorsController =
|
||||||
notFound:sinon.stub()
|
notFound:sinon.stub()
|
||||||
|
|
||||||
@Controller = SandboxedModule.require modulePath, requires:
|
@Controller = SandboxedModule.require modulePath, requires:
|
||||||
|
@ -35,18 +49,8 @@ describe "SubscriptionGroupController", ->
|
||||||
"./SubscriptionLocator": @SubscriptionLocator
|
"./SubscriptionLocator": @SubscriptionLocator
|
||||||
"./SubscriptionDomainHandler":@SubscriptionDomainHandler
|
"./SubscriptionDomainHandler":@SubscriptionDomainHandler
|
||||||
"../Errors/ErrorController":@ErrorsController
|
"../Errors/ErrorController":@ErrorsController
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
|
||||||
@adminUserId = "123jlkj"
|
|
||||||
@subscription_id = "123434325412"
|
|
||||||
@user_email = "bob@gmail.com"
|
|
||||||
@req =
|
|
||||||
session:
|
|
||||||
user:
|
|
||||||
_id: @adminUserId
|
|
||||||
email:@user_email
|
|
||||||
params:
|
|
||||||
subscription_id:@subscription_id
|
|
||||||
query:{}
|
|
||||||
|
|
||||||
@token = "super-secret-token"
|
@token = "super-secret-token"
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ describe "SubscriptionGroupController", ->
|
||||||
@Controller.removeUserFromGroup @req, res
|
@Controller.removeUserFromGroup @req, res
|
||||||
|
|
||||||
|
|
||||||
describe "renderSubscriptionGroupAdminPage", ->
|
describe "renderSubscriptionGroupAdminPage", ->
|
||||||
it "should redirect you if you don't have a group account", (done)->
|
it "should redirect you if you don't have a group account", (done)->
|
||||||
@subscription.groupPlan = false
|
@subscription.groupPlan = false
|
||||||
|
|
||||||
|
@ -177,7 +181,7 @@ describe "SubscriptionGroupController", ->
|
||||||
@Controller.completeJoin @req, res
|
@Controller.completeJoin @req, res
|
||||||
|
|
||||||
|
|
||||||
describe "exportGroupCsv", ->
|
describe "exportGroupCsv", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@subscription.groupPlan = true
|
@subscription.groupPlan = true
|
||||||
|
|
|
@ -11,24 +11,28 @@ describe 'TagsController', ->
|
||||||
tag = "some_class101"
|
tag = "some_class101"
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@handler =
|
@handler =
|
||||||
addProjectToTag: sinon.stub().callsArgWith(3)
|
addProjectToTag: sinon.stub().callsArgWith(3)
|
||||||
removeProjectFromTag: sinon.stub().callsArgWith(3)
|
removeProjectFromTag: sinon.stub().callsArgWith(3)
|
||||||
deleteTag: sinon.stub().callsArg(2)
|
deleteTag: sinon.stub().callsArg(2)
|
||||||
renameTag: sinon.stub().callsArg(3)
|
renameTag: sinon.stub().callsArg(3)
|
||||||
createTag: sinon.stub()
|
createTag: sinon.stub()
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: (req) =>
|
||||||
|
req.session.user._id
|
||||||
@controller = SandboxedModule.require modulePath, requires:
|
@controller = SandboxedModule.require modulePath, requires:
|
||||||
"./TagsHandler":@handler
|
"./TagsHandler":@handler
|
||||||
'logger-sharelatex':
|
'logger-sharelatex':
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
@req =
|
@req =
|
||||||
params:
|
params:
|
||||||
project_id:project_id
|
project_id:project_id
|
||||||
session:
|
session:
|
||||||
user:
|
user:
|
||||||
_id:user_id
|
_id:user_id
|
||||||
|
|
||||||
@res = {}
|
@res = {}
|
||||||
@res.status = sinon.stub().returns @res
|
@res.status = sinon.stub().returns @res
|
||||||
@res.end = sinon.stub()
|
@res.end = sinon.stub()
|
||||||
|
@ -49,26 +53,26 @@ describe 'TagsController', ->
|
||||||
@req.session.user._id = @user_id = "user-id-123"
|
@req.session.user._id = @user_id = "user-id-123"
|
||||||
@req.body = name: @name = "tag-name"
|
@req.body = name: @name = "tag-name"
|
||||||
@controller.createTag @req, @res
|
@controller.createTag @req, @res
|
||||||
|
|
||||||
it "should create the tag in the backend", ->
|
it "should create the tag in the backend", ->
|
||||||
@handler.createTag
|
@handler.createTag
|
||||||
.calledWith(@user_id, @name)
|
.calledWith(@user_id, @name)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return the tag", ->
|
it "should return the tag", ->
|
||||||
@res.json.calledWith(@tag).should.equal true
|
@res.json.calledWith(@tag).should.equal true
|
||||||
|
|
||||||
describe "deleteTag", ->
|
describe "deleteTag", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params.tag_id = @tag_id = "tag-id-123"
|
@req.params.tag_id = @tag_id = "tag-id-123"
|
||||||
@req.session.user._id = @user_id = "user-id-123"
|
@req.session.user._id = @user_id = "user-id-123"
|
||||||
@controller.deleteTag @req, @res
|
@controller.deleteTag @req, @res
|
||||||
|
|
||||||
it "should delete the tag in the backend", ->
|
it "should delete the tag in the backend", ->
|
||||||
@handler.deleteTag
|
@handler.deleteTag
|
||||||
.calledWith(@user_id, @tag_id)
|
.calledWith(@user_id, @tag_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return 204 status code", ->
|
it "should return 204 status code", ->
|
||||||
@res.status.calledWith(204).should.equal true
|
@res.status.calledWith(204).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
@ -82,56 +86,55 @@ describe 'TagsController', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.body = name: @name = "new-name"
|
@req.body = name: @name = "new-name"
|
||||||
@controller.renameTag @req, @res
|
@controller.renameTag @req, @res
|
||||||
|
|
||||||
it "should delete the tag in the backend", ->
|
it "should delete the tag in the backend", ->
|
||||||
@handler.renameTag
|
@handler.renameTag
|
||||||
.calledWith(@user_id, @tag_id, @name)
|
.calledWith(@user_id, @tag_id, @name)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return 204 status code", ->
|
it "should return 204 status code", ->
|
||||||
@res.status.calledWith(204).should.equal true
|
@res.status.calledWith(204).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
describe "without a name", ->
|
describe "without a name", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@controller.renameTag @req, @res
|
@controller.renameTag @req, @res
|
||||||
|
|
||||||
it "should not call the backend", ->
|
it "should not call the backend", ->
|
||||||
@handler.renameTag.called.should.equal false
|
@handler.renameTag.called.should.equal false
|
||||||
|
|
||||||
it "should return 400 (bad request) status code", ->
|
it "should return 400 (bad request) status code", ->
|
||||||
@res.status.calledWith(400).should.equal true
|
@res.status.calledWith(400).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
describe "addProjectToTag", ->
|
describe "addProjectToTag", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params.tag_id = @tag_id = "tag-id-123"
|
@req.params.tag_id = @tag_id = "tag-id-123"
|
||||||
@req.params.project_id = @project_id = "project-id-123"
|
@req.params.project_id = @project_id = "project-id-123"
|
||||||
@req.session.user._id = @user_id = "user-id-123"
|
@req.session.user._id = @user_id = "user-id-123"
|
||||||
@controller.addProjectToTag @req, @res
|
@controller.addProjectToTag @req, @res
|
||||||
|
|
||||||
it "should add the tag to the project in the backend", ->
|
it "should add the tag to the project in the backend", ->
|
||||||
@handler.addProjectToTag
|
@handler.addProjectToTag
|
||||||
.calledWith(@user_id, @tag_id, @project_id)
|
.calledWith(@user_id, @tag_id, @project_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return 204 status code", ->
|
it "should return 204 status code", ->
|
||||||
@res.status.calledWith(204).should.equal true
|
@res.status.calledWith(204).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
describe "removeProjectFromTag", ->
|
describe "removeProjectFromTag", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params.tag_id = @tag_id = "tag-id-123"
|
@req.params.tag_id = @tag_id = "tag-id-123"
|
||||||
@req.params.project_id = @project_id = "project-id-123"
|
@req.params.project_id = @project_id = "project-id-123"
|
||||||
@req.session.user._id = @user_id = "user-id-123"
|
@req.session.user._id = @user_id = "user-id-123"
|
||||||
@controller.removeProjectFromTag @req, @res
|
@controller.removeProjectFromTag @req, @res
|
||||||
|
|
||||||
it "should remove the tag from the project in the backend", ->
|
it "should remove the tag from the project in the backend", ->
|
||||||
@handler.removeProjectFromTag
|
@handler.removeProjectFromTag
|
||||||
.calledWith(@user_id, @tag_id, @project_id)
|
.calledWith(@user_id, @tag_id, @project_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return 204 status code", ->
|
it "should return 204 status code", ->
|
||||||
@res.status.calledWith(204).should.equal true
|
@res.status.calledWith(204).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
|
@ -6,18 +6,20 @@ SandboxedModule = require('sandboxed-module')
|
||||||
|
|
||||||
describe "TrackChangesController", ->
|
describe "TrackChangesController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@user_id = "user-id-123"
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||||
@TrackChangesController = SandboxedModule.require modulePath, requires:
|
@TrackChangesController = SandboxedModule.require modulePath, requires:
|
||||||
"request" : @request = sinon.stub()
|
"request" : @request = sinon.stub()
|
||||||
"settings-sharelatex": @settings = {}
|
"settings-sharelatex": @settings = {}
|
||||||
"logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
|
"logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
|
||||||
"../Authentication/AuthenticationController": @AuthenticationController = {}
|
"../Authentication/AuthenticationController": @AuthenticationController
|
||||||
|
|
||||||
describe "proxyToTrackChangesApi", ->
|
describe "proxyToTrackChangesApi", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req = { url: "/mock/url", method: "POST" }
|
@req = { url: "/mock/url", method: "POST" }
|
||||||
@res = "mock-res"
|
@res = "mock-res"
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
@user_id = "user-id-123"
|
|
||||||
@settings.apis =
|
@settings.apis =
|
||||||
trackchanges:
|
trackchanges:
|
||||||
url: "http://trackchanges.example.com"
|
url: "http://trackchanges.example.com"
|
||||||
|
@ -26,7 +28,6 @@ describe "TrackChangesController", ->
|
||||||
pipe: sinon.stub()
|
pipe: sinon.stub()
|
||||||
on: (event, handler) -> @events[event] = handler
|
on: (event, handler) -> @events[event] = handler
|
||||||
@request.returns @proxy
|
@request.returns @proxy
|
||||||
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id)
|
|
||||||
@TrackChangesController.proxyToTrackChangesApi @req, @res, @next
|
@TrackChangesController.proxyToTrackChangesApi @req, @res, @next
|
||||||
|
|
||||||
describe "successfully", ->
|
describe "successfully", ->
|
||||||
|
@ -56,4 +57,3 @@ describe "TrackChangesController", ->
|
||||||
|
|
||||||
it "should pass the error up the call chain", ->
|
it "should pass the error up the call chain", ->
|
||||||
@next.calledWith(@error).should.equal true
|
@next.calledWith(@error).should.equal true
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,16 @@ describe "ProjectUploadController", ->
|
||||||
@metrics =
|
@metrics =
|
||||||
Timer: class Timer
|
Timer: class Timer
|
||||||
done: sinon.stub()
|
done: sinon.stub()
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||||
@ProjectUploadController = SandboxedModule.require modulePath, requires:
|
@ProjectUploadController = SandboxedModule.require modulePath, requires:
|
||||||
"./ProjectUploadManager" : @ProjectUploadManager = {}
|
"./ProjectUploadManager" : @ProjectUploadManager = {}
|
||||||
"./FileSystemImportManager" : @FileSystemImportManager = {}
|
"./FileSystemImportManager" : @FileSystemImportManager = {}
|
||||||
"logger-sharelatex" : @logger = {log: sinon.stub(), error: sinon.stub(), err:->}
|
"logger-sharelatex" : @logger = {log: sinon.stub(), error: sinon.stub(), err:->}
|
||||||
"../../infrastructure/Metrics": @metrics
|
"../../infrastructure/Metrics": @metrics
|
||||||
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
"fs" : @fs = {}
|
"fs" : @fs = {}
|
||||||
|
|
||||||
describe "uploadProject", ->
|
describe "uploadProject", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@path = "/path/to/file/on/disk.zip"
|
@path = "/path/to/file/on/disk.zip"
|
||||||
|
@ -55,13 +58,13 @@ describe "ProjectUploadController", ->
|
||||||
.createProjectFromZipArchive
|
.createProjectFromZipArchive
|
||||||
.calledWith(sinon.match.any, "filename", sinon.match.any)
|
.calledWith(sinon.match.any, "filename", sinon.match.any)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should create a project from the zip archive", ->
|
it "should create a project from the zip archive", ->
|
||||||
@ProjectUploadManager
|
@ProjectUploadManager
|
||||||
.createProjectFromZipArchive
|
.createProjectFromZipArchive
|
||||||
.calledWith(sinon.match.any, sinon.match.any, @path)
|
.calledWith(sinon.match.any, sinon.match.any, @path)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return a successful response to the FileUploader client", ->
|
it "should return a successful response to the FileUploader client", ->
|
||||||
expect(@res.body).to.deep.equal
|
expect(@res.body).to.deep.equal
|
||||||
success: true
|
success: true
|
||||||
|
|
|
@ -16,9 +16,18 @@ describe "UserController", ->
|
||||||
|
|
||||||
@user =
|
@user =
|
||||||
_id:@user_id
|
_id:@user_id
|
||||||
save:sinon.stub().callsArgWith(0)
|
save: sinon.stub().callsArgWith(0)
|
||||||
ace:{}
|
ace:{}
|
||||||
|
|
||||||
|
@req =
|
||||||
|
user: {}
|
||||||
|
session:
|
||||||
|
destroy:->
|
||||||
|
user :
|
||||||
|
_id : @user_id
|
||||||
|
email:"old@something.com"
|
||||||
|
body:{}
|
||||||
|
|
||||||
@UserDeleter =
|
@UserDeleter =
|
||||||
deleteUser: sinon.stub().callsArgWith(1)
|
deleteUser: sinon.stub().callsArgWith(1)
|
||||||
@UserLocator =
|
@UserLocator =
|
||||||
|
@ -31,6 +40,8 @@ describe "UserController", ->
|
||||||
registerNewUser: sinon.stub()
|
registerNewUser: sinon.stub()
|
||||||
@AuthenticationController =
|
@AuthenticationController =
|
||||||
establishUserSession: sinon.stub().callsArg(2)
|
establishUserSession: sinon.stub().callsArg(2)
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user._id)
|
||||||
|
getSessionUser: sinon.stub().returns(@req.session.user)
|
||||||
@AuthenticationManager =
|
@AuthenticationManager =
|
||||||
authenticate: sinon.stub()
|
authenticate: sinon.stub()
|
||||||
setUserPassword: sinon.stub()
|
setUserPassword: sinon.stub()
|
||||||
|
@ -67,13 +78,6 @@ describe "UserController", ->
|
||||||
err:->
|
err:->
|
||||||
"../../infrastructure/Metrics": inc:->
|
"../../infrastructure/Metrics": inc:->
|
||||||
|
|
||||||
@req =
|
|
||||||
session:
|
|
||||||
destroy:->
|
|
||||||
user :
|
|
||||||
_id : @user_id
|
|
||||||
email:"old@something.com"
|
|
||||||
body:{}
|
|
||||||
@res =
|
@res =
|
||||||
send: sinon.stub()
|
send: sinon.stub()
|
||||||
json: sinon.stub()
|
json: sinon.stub()
|
||||||
|
@ -172,7 +176,7 @@ describe "UserController", ->
|
||||||
cb(null, @user)
|
cb(null, @user)
|
||||||
@res.sendStatus = (code)=>
|
@res.sendStatus = (code)=>
|
||||||
code.should.equal 200
|
code.should.equal 200
|
||||||
@req.session.user.email.should.equal @newEmail
|
@req.user.email.should.equal @newEmail
|
||||||
done()
|
done()
|
||||||
@UserController.updateUserSettings @req, @res
|
@UserController.updateUserSettings @req, @res
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe "UserPagesController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
@settings = {}
|
@settings = {}
|
||||||
@user =
|
@user =
|
||||||
_id: @user_id = "kwjewkl"
|
_id: @user_id = "kwjewkl"
|
||||||
features:{}
|
features:{}
|
||||||
email: "joe@example.com"
|
email: "joe@example.com"
|
||||||
|
@ -25,6 +25,8 @@ describe "UserPagesController", ->
|
||||||
getUserRegistrationStatus : sinon.stub().callsArgWith(1, null, @dropboxStatus)
|
getUserRegistrationStatus : sinon.stub().callsArgWith(1, null, @dropboxStatus)
|
||||||
@ErrorController =
|
@ErrorController =
|
||||||
notFound: sinon.stub()
|
notFound: sinon.stub()
|
||||||
|
@AuthenticationController =
|
||||||
|
getLoggedInUserId: sinon.stub().returns(@user._id)
|
||||||
@UserPagesController = SandboxedModule.require modulePath, requires:
|
@UserPagesController = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex": log:->
|
"logger-sharelatex": log:->
|
||||||
|
@ -32,7 +34,8 @@ describe "UserPagesController", ->
|
||||||
"./UserGetter": @UserGetter
|
"./UserGetter": @UserGetter
|
||||||
"../Errors/ErrorController": @ErrorController
|
"../Errors/ErrorController": @ErrorController
|
||||||
'../Dropbox/DropboxHandler': @DropboxHandler
|
'../Dropbox/DropboxHandler': @DropboxHandler
|
||||||
@req =
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
@req =
|
||||||
query:{}
|
query:{}
|
||||||
session:
|
session:
|
||||||
user:@user
|
user:@user
|
||||||
|
@ -111,24 +114,24 @@ describe "UserPagesController", ->
|
||||||
opts.user.should.equal @user
|
opts.user.should.equal @user
|
||||||
done()
|
done()
|
||||||
@UserPagesController.settingsPage @req, @res
|
@UserPagesController.settingsPage @req, @res
|
||||||
|
|
||||||
describe "activateAccountPage", ->
|
describe "activateAccountPage", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.query.user_id = @user_id
|
@req.query.user_id = @user_id
|
||||||
@req.query.token = @token = "mock-token-123"
|
@req.query.token = @token = "mock-token-123"
|
||||||
|
|
||||||
it "should 404 without a user_id", (done) ->
|
it "should 404 without a user_id", (done) ->
|
||||||
delete @req.query.user_id
|
delete @req.query.user_id
|
||||||
@ErrorController.notFound = () ->
|
@ErrorController.notFound = () ->
|
||||||
done()
|
done()
|
||||||
@UserPagesController.activateAccountPage @req, @res
|
@UserPagesController.activateAccountPage @req, @res
|
||||||
|
|
||||||
it "should 404 without a token", (done) ->
|
it "should 404 without a token", (done) ->
|
||||||
delete @req.query.token
|
delete @req.query.token
|
||||||
@ErrorController.notFound = () ->
|
@ErrorController.notFound = () ->
|
||||||
done()
|
done()
|
||||||
@UserPagesController.activateAccountPage @req, @res
|
@UserPagesController.activateAccountPage @req, @res
|
||||||
|
|
||||||
it "should 404 without a valid user_id", (done) ->
|
it "should 404 without a valid user_id", (done) ->
|
||||||
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
||||||
@ErrorController.notFound = () ->
|
@ErrorController.notFound = () ->
|
||||||
|
@ -142,7 +145,7 @@ describe "UserPagesController", ->
|
||||||
url.should.equal "/login?email=#{encodeURIComponent(@user.email)}"
|
url.should.equal "/login?email=#{encodeURIComponent(@user.email)}"
|
||||||
done()
|
done()
|
||||||
@UserPagesController.activateAccountPage @req, @res
|
@UserPagesController.activateAccountPage @req, @res
|
||||||
|
|
||||||
it "render the activation page if the user has not logged in before", (done) ->
|
it "render the activation page if the user has not logged in before", (done) ->
|
||||||
@user.loginCount = 0
|
@user.loginCount = 0
|
||||||
@res.render = (page, opts) =>
|
@res.render = (page, opts) =>
|
||||||
|
@ -150,4 +153,4 @@ describe "UserPagesController", ->
|
||||||
opts.email.should.equal @user.email
|
opts.email.should.equal @user.email
|
||||||
opts.token.should.equal @token
|
opts.token.should.equal @token
|
||||||
done()
|
done()
|
||||||
@UserPagesController.activateAccountPage @req, @res
|
@UserPagesController.activateAccountPage @req, @res
|
||||||
|
|
Loading…
Reference in a new issue