NotificationsControllerTests.coffee 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. SandboxedModule = require('sandboxed-module')
  2. assert = require('assert')
  3. require('chai').should()
  4. sinon = require('sinon')
  5. modulePath = require('path').join __dirname, '../../../../app/js/Features/Notifications/NotificationsController.js'
  6. describe 'NotificationsController', ->
  7. user_id = "123nd3ijdks"
  8. notification_id = "123njdskj9jlk"
  9. beforeEach ->
  10. @handler =
  11. getUserNotifications: sinon.stub().callsArgWith(1)
  12. markAsRead: sinon.stub().callsArgWith(2)
  13. @controller = SandboxedModule.require modulePath, requires:
  14. "./NotificationsHandler":@handler
  15. "underscore":@underscore =
  16. map:(arr)-> return arr
  17. 'logger-sharelatex':
  18. log:->
  19. err:->
  20. @req =
  21. params:
  22. notification_id:notification_id
  23. session:
  24. user:
  25. _id:user_id
  26. i18n:
  27. translate:->
  28. it 'should ask the handler for all unread notifications', (done)->
  29. allNotifications = [{_id: notification_id, user_id: user_id}]
  30. @handler.getUserNotifications = sinon.stub().callsArgWith(1, null, allNotifications)
  31. @controller.getAllUnreadNotifications @req, send:(body)=>
  32. body.should.equal allNotifications
  33. @handler.getUserNotifications.calledWith(user_id).should.equal true
  34. done()
  35. it 'should send a delete request when a delete has been received to mark a notification', (done)->
  36. @controller.markNotificationAsRead @req, send:=>
  37. @handler.markAsRead.calledWith(user_id, notification_id).should.equal true
  38. done()