mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-06 21:40:35 +00:00
make forceCreate the default for creating notifications
This commit is contained in:
parent
26a4076c22
commit
ddc0023c64
3 changed files with 9 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ->
|
||||
|
|
Loading…
Add table
Reference in a new issue