added notifications calls for sending to api and mark as read

not creating it yet
This commit is contained in:
Henry Oswald 2016-02-05 14:13:38 +00:00
parent f136486f4b
commit de0589b051
4 changed files with 71 additions and 8 deletions

View file

@ -0,0 +1,16 @@
NotificationsHandler = require("./NotificationsHandler")
module.exports =
groupPlan: (user, licence)->
key : "join-sub-#{licence.subscription_id}"
create: (callback = ->)->
messageOpts =
groupName: licence.name
subscription_id: licence.subscription_id
NotificationsHandler.createNotification user._id, key, "joinSubscriptionInvite", messageOpts, callback
read: (callback = ->)->
NotificationsHandler.markAsReadWithKey user._id, key, callback

View file

@ -21,6 +21,27 @@ module.exports =
unreadNotifications = []
callback(null, unreadNotifications)
createNotification: (user_id, key, templateKey, messageOpts, callback)->
opts =
uri: "#{settings.apis.notifications.url}/user/#{user_id}"
timeout: 1000
json: {
key:key
messageOpts:messageOpts
templateKey:templateKey
}
request.post opts, callback
markAsReadWithKey: (user_id, key, callback)->
opts =
uri: "#{settings.apis.notifications.url}/user/#{user_id}"
timeout: 1000
json: {
key:key
}
request.del opts, callback
markAsRead: (user_id, notification_id, callback)->
opts =
uri: "#{settings.apis.notifications.url}/user/#{user_id}/notification/#{notification_id}"

View file

@ -1,3 +1,4 @@
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
async = require("async")
_ = require("underscore")
settings = require("settings-sharelatex")
@ -7,17 +8,18 @@ _s = require("underscore.string")
module.exports = SubscriptionDomainHandler =
getLicenceUserCanJoin: (user, callback)->
getLicenceUserCanJoin: (user)->
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
if licence?
callback null, licence
else
callback()
return licence
attemptToJoinGroup: (user, callback)->
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
if licence? and user.emailVerified
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, (err)->
if err?
logger.err err:err, "error adding user to group"
return callback(err)
NotificationsBuilder.groupPlan(user, licence).read()
else
callback "user not verified"

View file

@ -42,7 +42,31 @@ describe 'NotificationsHandler', ->
unreadNotifications.length.should.equal 0
describe "markAsRead", ->
beforeEach ->
@key = "some key here"
it 'should send a delete request when a delete has been received to mark a notification', (done)->
@handler.markAsRead user_id, notification_id, =>
@request.del.calledWith({uri:"#{notificationUrl}/user/#{user_id}/notification/#{notification_id}", timeout:1000}).should.equal true
@handler.markAsReadWithKey user_id, @key, =>
opts =
uri: "#{notificationUrl}/user/#{user_id}"
json:
key:@key
timeout:1000
@request.del.calledWith(opts).should.equal true
done()
describe "createNotification", ->
beforeEach ->
@key = "some key here"
@messageOpts = {value:12344}
@templateKey = "renderThisHtml"
it "should post the message over", (done)->
@handler.createNotification user_id, @key, @templateKey, @messageOpts, =>
args = @request.post.args[0][0]
args.uri.should.equal "#{notificationUrl}/user/#{user_id}"
args.timeout.should.equal 1000
expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts}
assert.deepEqual(args.json, expectedJson)
done()