fix unit tests

This commit is contained in:
Shane Kilkelly 2016-09-07 16:40:49 +01:00
parent 8e0103a1bc
commit 438ac45854
20 changed files with 237 additions and 183 deletions

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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 = ""

View file

@ -8,13 +8,17 @@ 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()
@ -46,8 +50,7 @@ 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 ->
@ -75,6 +78,7 @@ describe "AuthorizationMiddlewear", ->
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)
@ -85,6 +89,7 @@ describe "AuthorizationMiddlewear", ->
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)
@ -114,8 +119,7 @@ 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 ->
@ -143,6 +147,7 @@ describe "AuthorizationMiddlewear", ->
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)
@ -153,6 +158,7 @@ describe "AuthorizationMiddlewear", ->
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)
@ -173,8 +179,7 @@ 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 to access all projects", -> describe "when user has permission to access all projects", ->
beforeEach -> beforeEach ->
@ -209,6 +214,7 @@ describe "AuthorizationMiddlewear", ->
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)
@ -222,6 +228,7 @@ describe "AuthorizationMiddlewear", ->
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)

View file

@ -10,6 +10,7 @@ describe "ChatController", ->
beforeEach -> beforeEach ->
@user_id = 'ier_'
@settings = {} @settings = {}
@ChatHandler = @ChatHandler =
sendMessage:sinon.stub() sendMessage:sinon.stub()
@ -17,11 +18,15 @@ describe "ChatController", ->
@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
'../Authentication/AuthenticationController': @AuthenticationController
@query = @query =
before:"some time" before:"some time"
@ -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

View file

@ -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()

View file

@ -10,6 +10,13 @@ MockResponse = require "../helpers/MockResponse"
describe "CompileController", -> describe "CompileController", ->
beforeEach -> beforeEach ->
@user_id = 'wat'
@user =
_id: @user_id
email: 'user@example.com'
features:
compileGroup: "premium"
compileTimeout: 100
@CompileManager = @CompileManager =
compile: sinon.stub() compile: sinon.stub()
@ClsiManager = {} @ClsiManager = {}
@ -25,6 +32,11 @@ describe "CompileController", ->
@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 ->

View file

@ -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,7 +33,7 @@ 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)

View file

@ -13,13 +13,6 @@ describe 'NotificationsController', ->
@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}]

View file

@ -12,6 +12,9 @@ describe "ProjectController", ->
@project_id = "123213jlkj9kdlsaj" @project_id = "123213jlkj9kdlsaj"
@user =
_id:"!£123213kjljkl"
first_name: "bjkdsjfk"
@settings = @settings =
apis: apis:
chat: chat:
@ -50,6 +53,11 @@ 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":
@ -73,10 +81,8 @@ 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:
@ -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

View file

@ -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 =
@ -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

View file

@ -20,11 +20,14 @@ 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)
getLoggedInUserId: sinon.stub().returns(@user._id)
getSessionUser: sinon.stub().returns(@user)
isUserLoggedIn: sinon.stub().returns(true)
@SubscriptionHandler = @SubscriptionHandler =
createSubscription: sinon.stub().callsArgWith(3) createSubscription: sinon.stub().callsArgWith(3)
updateSubscription: sinon.stub().callsArgWith(3) updateSubscription: sinon.stub().callsArgWith(3)
@ -452,6 +455,3 @@ describe "SubscriptionController sanboxed", ->
done() done()
@SubscriptionController.processUpgradeToAnnualPlan @req, @res @SubscriptionController.processUpgradeToAnnualPlan @req, @res

View file

@ -9,6 +9,17 @@ 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)
@ -18,6 +29,9 @@ 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()
@ -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"

View file

@ -17,11 +17,15 @@ describe 'TagsController', ->
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
@ -134,4 +138,3 @@ describe 'TagsController', ->
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

View file

@ -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

View file

@ -15,11 +15,14 @@ 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", ->

View file

@ -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

View file

@ -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,6 +34,7 @@ describe "UserPagesController", ->
"./UserGetter": @UserGetter "./UserGetter": @UserGetter
"../Errors/ErrorController": @ErrorController "../Errors/ErrorController": @ErrorController
'../Dropbox/DropboxHandler': @DropboxHandler '../Dropbox/DropboxHandler': @DropboxHandler
'../Authentication/AuthenticationController': @AuthenticationController
@req = @req =
query:{} query:{}
session: session: