mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 11:32:25 +00:00
updating tests for ip matcher logic
This commit is contained in:
parent
f20d27986b
commit
23e6292fd7
4 changed files with 10 additions and 7 deletions
|
@ -18,7 +18,6 @@ module.exports =
|
|||
# in v2 add notifications for matching university IPs
|
||||
if Settings.overleaf?
|
||||
UserGetter.getUser user_id, { 'lastLoginIp': 1 }, (error, user) ->
|
||||
console.log(user.lastLoginIp)
|
||||
if ip != user.lastLoginIp
|
||||
async.series ([
|
||||
() ->
|
||||
|
|
|
@ -603,6 +603,7 @@ 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()
|
||||
|
|
|
@ -9,10 +9,10 @@ describe 'NotificationsBuilder', ->
|
|||
|
||||
beforeEach ->
|
||||
@handler =
|
||||
createNotification: sinon.stub().callsArgWith(5)
|
||||
createNotification: sinon.stub().callsArgWith(6)
|
||||
|
||||
@settings = apis: { v1: { url: 'v1.url', user: '', pass: '' } }
|
||||
@body = {university_id: 1, university_name: 'stanford', ad_copy: 'v1 ad content'}
|
||||
@body = {id: 1, name: 'stanford', enrolment_ad_html: 'v1 ad content'}
|
||||
response = {statusCode: 200}
|
||||
@request = sinon.stub().returns(@stubResponse).callsArgWith(1, null, response, @body)
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
|
@ -28,9 +28,9 @@ describe 'NotificationsBuilder', ->
|
|||
@controller.ipMatcherAffiliation(user_id, ip).create (callback)=>
|
||||
@request.calledOnce.should.equal true
|
||||
expectedOpts =
|
||||
university_id: @body.university_id
|
||||
university_name: @body.university_name
|
||||
content: @body.ad_copy
|
||||
university_id: @body.id
|
||||
university_name: @body.name
|
||||
content: @body.enrolment_ad_html
|
||||
@handler.createNotification.calledWith(
|
||||
user_id,
|
||||
"ip-matched-affiliation-#{ip}",
|
||||
|
|
|
@ -15,6 +15,8 @@ describe 'NotificationsController', ->
|
|||
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 =
|
||||
|
@ -33,6 +35,7 @@ describe 'NotificationsController', ->
|
|||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./NotificationsHandler":@handler
|
||||
"./NotificationsBuilder":@builder
|
||||
"../User/UserGetter": @userGetter
|
||||
"settings-sharelatex":@settings
|
||||
"underscore":@underscore =
|
||||
map:(arr)-> return arr
|
||||
|
@ -49,7 +52,7 @@ describe 'NotificationsController', ->
|
|||
@handler.getUserNotifications.calledWith(user_id).should.equal true
|
||||
done()
|
||||
|
||||
it 'should send a delete request when a delete has been received to mark a notification', (done)->
|
||||
it 'should send a remove request when notification read', (done)->
|
||||
@controller.markNotificationAsRead @req, send:=>
|
||||
@handler.markAsRead.calledWith(user_id, notification_id).should.equal true
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue