move call for creating ip matched notifcation to project controller

This commit is contained in:
hugh-obrien
2018-09-05 15:40:59 +01:00
parent 5605e1c5c3
commit 8ef90a0dcb
7 changed files with 32 additions and 42 deletions
@@ -15,7 +15,7 @@ describe "AuthenticationController", ->
tk.freeze(Date.now())
@AuthenticationController = SandboxedModule.require modulePath, requires:
"./AuthenticationManager": @AuthenticationManager = {}
"../User/UserUpdater" : @UserUpdater = {}
"../User/UserUpdater" : @UserUpdater = {updateUser:sinon.stub()}
"metrics-sharelatex": @Metrics = { inc: sinon.stub() }
"../Security/LoginRateLimiter": @LoginRateLimiter = { processLoginRequest:sinon.stub(), recordSuccessfulLogin:sinon.stub() }
"../User/UserHandler": @UserHandler = {setupLoginData:sinon.stub()}
@@ -603,7 +603,6 @@ describe "AuthenticationController", ->
@AuthenticationController._loginAsyncHandlers = sinon.stub()
@AuthenticationController.afterLoginSessionSetup = sinon.stub().callsArgWith(2, null)
@AuthenticationController._clearRedirectFromSession = sinon.stub()
@UserUpdater.updateUser = sinon.stub()
@req.headers = {accept: 'application/json, whatever'}
@res.json = sinon.stub()
@res.redirect = sinon.stub()
@@ -13,16 +13,7 @@ describe 'NotificationsController', ->
@handler =
getUserNotifications: sinon.stub().callsArgWith(1)
markAsRead: sinon.stub().callsArgWith(2)
@builder =
ipMatcherAffiliation: sinon.stub().returns({create: sinon.stub()})
@userGetter =
getUser: sinon.stub().callsArgWith 2, null, {lastLoginIp: '192.170.18.2'}
@settings =
apis: { v1: { url: 'v1.url', user: '', pass: '' } }
@req =
headers: {}
connection:
remoteAddress: "192.170.18.1"
params:
notification_id:notification_id
session:
@@ -34,9 +25,6 @@ describe 'NotificationsController', ->
getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
@controller = SandboxedModule.require modulePath, requires:
"./NotificationsHandler":@handler
"./NotificationsBuilder":@builder
"../User/UserGetter": @userGetter
"settings-sharelatex":@settings
"underscore":@underscore =
map:(arr)-> return arr
'logger-sharelatex':
@@ -52,13 +40,7 @@ describe 'NotificationsController', ->
@handler.getUserNotifications.calledWith(user_id).should.equal true
done()
it 'should send a remove request when notification read', (done)->
it 'should send a delete request when a delete has been received to mark a notification', (done)->
@controller.markNotificationAsRead @req, send:=>
@handler.markAsRead.calledWith(user_id, notification_id).should.equal true
done()
it 'should call the builder with the user ip if v2', (done)->
@settings.overleaf = true
@controller.getAllUnreadNotifications @req, send:(body)=>
@builder.ipMatcherAffiliation.calledWith(user_id, @req.connection.remoteAddress).should.equal true
done()
@@ -69,6 +69,10 @@ describe "ProjectController", ->
@CollaboratorsHandler =
userIsTokenMember: sinon.stub().callsArgWith(2, null, false)
@ProjectEntityHandler = {}
@NotificationBuilder =
ipMatcherAffiliation: sinon.stub().returns({create: sinon.stub()})
@UserGetter =
getUser: sinon.stub().callsArgWith 2, null, {lastLoginIp: '192.170.18.2'}
@Modules =
hooks:
fire: sinon.stub()
@@ -105,11 +109,16 @@ describe "ProjectController", ->
"./ProjectEntityHandler": @ProjectEntityHandler
"../Errors/Errors": Errors
"../../infrastructure/Features": @Features
"../Notifications/NotificationsBuilder":@NotificationBuilder
"../User/UserGetter": @UserGetter
@projectName = "£12321jkj9ujkljds"
@req =
params:
Project_id: @project_id
headers: {}
connection:
remoteAddress: "192.170.18.1"
session:
user: @user
body:
@@ -301,6 +310,13 @@ describe "ProjectController", ->
done()
@ProjectController.projectListPage @req, @res
it "should create trigger ip matcher notifications", (done)->
@settings.overleaf = true
@res.render = (pageName, opts)=>
@NotificationBuilder.ipMatcherAffiliation.called.should.equal true
done()
@ProjectController.projectListPage @req, @res
it "should send the projects", (done)->
@res.render = (pageName, opts)=>
opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length + @tokenReadAndWrite.length + @tokenReadOnly.length)