overleaf/services/notifications/test/unit/coffee/NotificationsControllerTest.coffee

77 lines
2.8 KiB
CoffeeScript
Raw Normal View History

2016-01-14 07:35:16 -05:00
sinon = require('sinon')
chai = require('chai')
should = chai.should()
modulePath = "../../../app/js/NotificationsController.js"
SandboxedModule = require('sandboxed-module')
assert = require('assert')
user_id = "51dc93e6fb625a261300003b"
2016-01-16 15:28:19 -05:00
notification_id = "fb625a26f09d"
2016-02-05 04:38:32 -05:00
notification_key = "my-notification-key"
2016-01-14 07:35:16 -05:00
2016-02-05 04:38:32 -05:00
describe 'Notifications Controller', ->
2016-01-16 15:28:19 -05:00
beforeEach ->
self = @
@notifications = {}
@controller = SandboxedModule.require modulePath, requires:
'logger-sharelatex': log:->
'./Notifications':@notifications
2016-01-20 08:57:29 -05:00
'metrics-sharelatex':
inc: sinon.stub()
2016-01-16 15:28:19 -05:00
2016-02-05 04:38:32 -05:00
@stubbedNotification = [{key: notification_key, messageOpts:"some info", templateKey:"template-key"}]
2016-01-16 15:28:19 -05:00
describe "getUserNotifications", ->
it 'should ask the notifications for the users notifications', (done)->
@notifications.getUserNotifications = sinon.stub().callsArgWith(1, null, @stubbedNotification)
req =
2016-01-16 15:28:19 -05:00
params:
user_id: user_id
@controller.getUserNotifications req, json:(result)=>
result.should.equal @stubbedNotification
@notifications.getUserNotifications.calledWith(user_id).should.equal true
done()
describe "addNotification", ->
it "should tell the notifications to add the notification for the user", (done)->
@notifications.addNotification = sinon.stub().callsArgWith(2)
req =
2016-01-16 15:28:19 -05:00
params:
user_id: user_id
body: @stubbedNotification
@controller.addNotification req, send:(result)=>
@notifications.addNotification.calledWith(user_id, @stubbedNotification).should.equal true
done()
2016-02-05 04:38:32 -05:00
describe "removeNotificationId", ->
it "should tell the notifications to mark the notification Id as read", (done)->
@notifications.removeNotificationId = sinon.stub().callsArgWith(2)
req =
2016-01-16 15:28:19 -05:00
params:
user_id: user_id
notification_id: notification_id
2016-02-05 04:38:32 -05:00
@controller.removeNotificationId req, send:(result)=>
@notifications.removeNotificationId.calledWith(user_id, notification_id).should.equal true
2016-01-16 15:28:19 -05:00
done()
2016-02-05 04:38:32 -05:00
describe "removeNotificationKey", ->
it "should tell the notifications to mark the notification Key as read", (done)->
@notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
req =
2016-02-05 04:38:32 -05:00
params:
user_id: user_id
body: {key: notification_key}
@controller.removeNotificationKey req, send:(result)=>
@notifications.removeNotificationKey.calledWith(user_id, notification_key).should.equal true
done()
describe "removeNotificationByKeyOnly", ->
it "should tell the notifications to mark the notification Key as read", (done)->
@notifications.removeNotificationByKeyOnly = sinon.stub().callsArgWith(1)
req =
params:
key: notification_key
@controller.removeNotificationByKeyOnly req, send:(result)=>
@notifications.removeNotificationByKeyOnly.calledWith(notification_key).should.equal true
done()