NotificationsControllerTests.coffee 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. @req =
  14. params:
  15. notification_id:notification_id
  16. session:
  17. user:
  18. _id:user_id
  19. i18n:
  20. translate:->
  21. @AuthenticationController =
  22. getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
  23. @controller = SandboxedModule.require modulePath, requires:
  24. "./NotificationsHandler":@handler
  25. "underscore":@underscore =
  26. map:(arr)-> return arr
  27. 'logger-sharelatex':
  28. log:->
  29. err:->
  30. '../Authentication/AuthenticationController': @AuthenticationController
  31. it 'should ask the handler for all unread notifications', (done)->
  32. allNotifications = [{_id: notification_id, user_id: user_id}]
  33. @handler.getUserNotifications = sinon.stub().callsArgWith(1, null, allNotifications)
  34. @controller.getAllUnreadNotifications @req, send:(body)=>
  35. body.should.equal allNotifications
  36. @handler.getUserNotifications.calledWith(user_id).should.equal true
  37. done()
  38. it 'should send a delete request when a delete has been received to mark a notification', (done)->
  39. @controller.markNotificationAsRead @req, send:=>
  40. @handler.markAsRead.calledWith(user_id, notification_id).should.equal true
  41. done()