|
@@ -12,10 +12,7 @@ describe 'NotificationsHandler', ->
|
|
|
notificationUrl = "notification.sharelatex.testing"
|
|
notificationUrl = "notification.sharelatex.testing"
|
|
|
|
|
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request =
|
|
|
|
|
- post: sinon.stub().callsArgWith(1)
|
|
|
|
|
- del: sinon.stub().callsArgWith(1)
|
|
|
|
|
- get: sinon.stub()
|
|
|
|
|
|
|
+ @request = sinon.stub().callsArgWith(1)
|
|
|
@handler = SandboxedModule.require modulePath, requires:
|
|
@handler = SandboxedModule.require modulePath, requires:
|
|
|
"settings-sharelatex": apis:{notifications:{url:notificationUrl}}
|
|
"settings-sharelatex": apis:{notifications:{url:notificationUrl}}
|
|
|
"request":@request
|
|
"request":@request
|
|
@@ -26,18 +23,19 @@ describe 'NotificationsHandler', ->
|
|
|
describe "getUserNotifications", ->
|
|
describe "getUserNotifications", ->
|
|
|
it 'should get unread notifications', (done)->
|
|
it 'should get unread notifications', (done)->
|
|
|
stubbedNotifications = [{_id: notification_id, user_id: user_id}]
|
|
stubbedNotifications = [{_id: notification_id, user_id: user_id}]
|
|
|
- @request.get.callsArgWith(1, null, {statusCode:200}, stubbedNotifications)
|
|
|
|
|
|
|
+ @request.callsArgWith(1, null, {statusCode:200}, stubbedNotifications)
|
|
|
@handler.getUserNotifications user_id, (err, unreadNotifications)=>
|
|
@handler.getUserNotifications user_id, (err, unreadNotifications)=>
|
|
|
stubbedNotifications.should.deep.equal unreadNotifications
|
|
stubbedNotifications.should.deep.equal unreadNotifications
|
|
|
getOpts =
|
|
getOpts =
|
|
|
uri: "#{notificationUrl}/user/#{user_id}"
|
|
uri: "#{notificationUrl}/user/#{user_id}"
|
|
|
json:true
|
|
json:true
|
|
|
timeout:1000
|
|
timeout:1000
|
|
|
- @request.get.calledWith(getOpts).should.equal true
|
|
|
|
|
|
|
+ method: "GET"
|
|
|
|
|
+ @request.calledWith(getOpts).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it 'should return empty arrays if there are no notifications', ->
|
|
it 'should return empty arrays if there are no notifications', ->
|
|
|
- @request.get.callsArgWith(1, null, {statusCode:200}, null)
|
|
|
|
|
|
|
+ @request.callsArgWith(1, null, {statusCode:200}, null)
|
|
|
@handler.getUserNotifications user_id, (err, unreadNotifications)=>
|
|
@handler.getUserNotifications user_id, (err, unreadNotifications)=>
|
|
|
unreadNotifications.length.should.equal 0
|
|
unreadNotifications.length.should.equal 0
|
|
|
|
|
|
|
@@ -52,7 +50,8 @@ describe 'NotificationsHandler', ->
|
|
|
json:
|
|
json:
|
|
|
key:@key
|
|
key:@key
|
|
|
timeout:1000
|
|
timeout:1000
|
|
|
- @request.del.calledWith(opts).should.equal true
|
|
|
|
|
|
|
+ method: "DELETE"
|
|
|
|
|
+ @request.calledWith(opts).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
@@ -64,7 +63,7 @@ describe 'NotificationsHandler', ->
|
|
|
|
|
|
|
|
it "should post the message over", (done)->
|
|
it "should post the message over", (done)->
|
|
|
@handler.createNotification user_id, @key, @templateKey, @messageOpts, =>
|
|
@handler.createNotification user_id, @key, @templateKey, @messageOpts, =>
|
|
|
- args = @request.post.args[0][0]
|
|
|
|
|
|
|
+ args = @request.args[0][0]
|
|
|
args.uri.should.equal "#{notificationUrl}/user/#{user_id}"
|
|
args.uri.should.equal "#{notificationUrl}/user/#{user_id}"
|
|
|
args.timeout.should.equal 1000
|
|
args.timeout.should.equal 1000
|
|
|
expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts}
|
|
expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts}
|