mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 10:03:13 +00:00
adding tests for ip matching notifications
This commit is contained in:
parent
38faa5c25e
commit
de83df2703
2 changed files with 55 additions and 0 deletions
|
@ -0,0 +1,40 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('chai').assert
|
||||
require('chai').should()
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Notifications/NotificationsBuilder.js'
|
||||
|
||||
describe 'NotificationsBuilder', ->
|
||||
user_id = "123nd3ijdks"
|
||||
|
||||
beforeEach ->
|
||||
@handler =
|
||||
createNotification: sinon.stub().callsArgWith(5)
|
||||
|
||||
@settings = apis: { v1: { url: 'v1.url', user: '', pass: '' } }
|
||||
@body = {university_id: 1, university_name: 'stanford', ad_copy: 'v1 ad content'}
|
||||
response = {statusCode: 200}
|
||||
@request = sinon.stub().returns(@stubResponse).callsArgWith(1, null, response, @body)
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./NotificationsHandler":@handler
|
||||
"settings-sharelatex":@settings
|
||||
'request': @request
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
|
||||
it 'should call v1 and create affiliation notifications', (done)->
|
||||
ip = '192.168.0.1'
|
||||
@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
|
||||
@handler.createNotification.calledWith(
|
||||
user_id,
|
||||
"ip-matched-affiliation-#{ip}",
|
||||
"notification_ip_matched_affiliation",
|
||||
expectedOpts
|
||||
).should.equal true
|
||||
done()
|
|
@ -13,7 +13,14 @@ describe 'NotificationsController', ->
|
|||
@handler =
|
||||
getUserNotifications: sinon.stub().callsArgWith(1)
|
||||
markAsRead: sinon.stub().callsArgWith(2)
|
||||
@builder =
|
||||
ipMatcherAffiliation: sinon.stub().returns({create: sinon.stub()})
|
||||
@settings =
|
||||
apis: { v1: { url: 'v1.url', user: '', pass: '' } }
|
||||
@req =
|
||||
headers: {}
|
||||
connection:
|
||||
remoteAddress: "192.170.18.1"
|
||||
params:
|
||||
notification_id:notification_id
|
||||
session:
|
||||
|
@ -25,6 +32,8 @@ describe 'NotificationsController', ->
|
|||
getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./NotificationsHandler":@handler
|
||||
"./NotificationsBuilder":@builder
|
||||
"settings-sharelatex":@settings
|
||||
"underscore":@underscore =
|
||||
map:(arr)-> return arr
|
||||
'logger-sharelatex':
|
||||
|
@ -44,3 +53,9 @@ describe 'NotificationsController', ->
|
|||
@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()
|
||||
|
|
Loading…
Reference in a new issue