From ddc0023c647183cb22069c4bd24a587ad54051d6 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 30 Aug 2016 13:07:37 +0100 Subject: [PATCH] make forceCreate the default for creating notifications --- .../Notifications/NotificationsBuilder.coffee | 4 +-- .../Notifications/NotificationsHandler.coffee | 5 ++-- .../NotificationsHandlerTests.coffee | 27 ++++--------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee index 646a520a1c..ffb71f70e6 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee @@ -12,7 +12,7 @@ module.exports = groupName: licence.name subscription_id: licence.subscription_id logger.log user_id:user._id, key:key, "creating notification key for user" - NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, null, false, callback + NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, null, callback read: (callback = ->)-> NotificationsHandler.markAsReadWithKey user._id, @key, callback @@ -26,6 +26,6 @@ module.exports = projectId: project._id.toString() token: invite.token logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user" - NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, true, callback + NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, callback read: (callback=()->) -> NotificationsHandler.markAsReadByKeyOnly @key, callback diff --git a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee index 2ee97dae49..5a6ca47c2e 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee @@ -29,16 +29,15 @@ module.exports = unreadNotifications = [] callback(null, unreadNotifications) - createNotification: (user_id, key, templateKey, messageOpts, expiryDateTime, forceCreate, callback)-> + createNotification: (user_id, key, templateKey, messageOpts, expiryDateTime, callback)-> payload = { key:key messageOpts:messageOpts templateKey:templateKey + forceCreate: true } if expiryDateTime? payload.expires = expiryDateTime - if forceCreate - payload.forceCreate = true opts = uri: "#{settings.apis.notifications?.url}/user/#{user_id}" timeout: oneSecond diff --git a/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee index 0aafe6e5fc..7ee3476b4b 100644 --- a/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee @@ -61,14 +61,13 @@ describe 'NotificationsHandler', -> @messageOpts = {value:12344} @templateKey = "renderThisHtml" @expiry = null - @forceCreate = false it "should post the message over", (done)-> - @handler.createNotification user_id, @key, @templateKey, @messageOpts, @expiry, @forceCreate, => + @handler.createNotification user_id, @key, @templateKey, @messageOpts, @expiry, => args = @request.args[0][0] args.uri.should.equal "#{notificationUrl}/user/#{user_id}" args.timeout.should.equal 1000 - expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts} + expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts, forceCreate:true} assert.deepEqual(args.json, expectedJson) done() @@ -78,33 +77,17 @@ describe 'NotificationsHandler', -> @messageOpts = {value:12344} @templateKey = "renderThisHtml" @expiry = new Date() - @forceCreate = false it 'should post the message over with expiry field', (done) -> - @handler.createNotification user_id, @key, @templateKey, @messageOpts, @expiry, @forceCreate, => + @handler.createNotification user_id, @key, @templateKey, @messageOpts, @expiry, => args = @request.args[0][0] args.uri.should.equal "#{notificationUrl}/user/#{user_id}" args.timeout.should.equal 1000 - expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts, expires: @expiry} + expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts, expires: @expiry, forceCreate:true} assert.deepEqual(args.json, expectedJson) done() - describe 'when forceCreate is true', -> - beforeEach -> - @key = "some key here" - @messageOpts = {value:12344} - @templateKey = "renderThisHtml" - @expiry = null - @forceCreate = true - - it 'should add a forceCreate=true flag to the payload', (done) -> - @handler.createNotification user_id, @key, @templateKey, @messageOpts, @expiry, @forceCreate, => - args = @request.args[0][0] - args.uri.should.equal "#{notificationUrl}/user/#{user_id}" - args.timeout.should.equal 1000 - expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts, forceCreate: @forceCreate} - assert.deepEqual(args.json, expectedJson) - done() + describe "markAsReadByKeyOnly", -> beforeEach ->