From 23e6292fd7c60dccde57407fef8b74024e12c31d Mon Sep 17 00:00:00 2001 From: hugh-obrien Date: Wed, 5 Sep 2018 10:44:34 +0100 Subject: [PATCH] updating tests for ip matcher logic --- .../Notifications/NotificationsController.coffee | 1 - .../AuthenticationControllerTests.coffee | 1 + .../Notifications/NotificationsBuilderTests.coffee | 10 +++++----- .../Notifications/NotificationsControllerTests.coffee | 5 ++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/services/web/app/coffee/Features/Notifications/NotificationsController.coffee b/services/web/app/coffee/Features/Notifications/NotificationsController.coffee index 53ae2af4ac..08ac42b6ac 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsController.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsController.coffee @@ -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 ([ () -> diff --git a/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee b/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee index 24af9971d2..5f28a207b2 100644 --- a/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee +++ b/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee @@ -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() diff --git a/services/web/test/unit/coffee/Notifications/NotificationsBuilderTests.coffee b/services/web/test/unit/coffee/Notifications/NotificationsBuilderTests.coffee index 8b984a8cee..941e26df1e 100644 --- a/services/web/test/unit/coffee/Notifications/NotificationsBuilderTests.coffee +++ b/services/web/test/unit/coffee/Notifications/NotificationsBuilderTests.coffee @@ -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}", diff --git a/services/web/test/unit/coffee/Notifications/NotificationsControllerTests.coffee b/services/web/test/unit/coffee/Notifications/NotificationsControllerTests.coffee index 9fab8a96f5..191b869fec 100644 --- a/services/web/test/unit/coffee/Notifications/NotificationsControllerTests.coffee +++ b/services/web/test/unit/coffee/Notifications/NotificationsControllerTests.coffee @@ -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()