NotificationsControllerTests.coffee 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. 'logger-sharelatex':
  16. log:->
  17. err:->
  18. @req =
  19. params:
  20. notification_id:notification_id
  21. session:
  22. user:
  23. _id:user_id
  24. it 'should ask the handler for all unread notifications', (done)->
  25. allNotifications = [{_id: notification_id, user_id: user_id}]
  26. @handler.getUserNotifications = sinon.stub().callsArgWith(1, null, allNotifications)
  27. @controller.getAllUnreadNotifications @req, send:(body)=>
  28. body.should.equal allNotifications
  29. @handler.getUserNotifications.calledWith(user_id).should.equal true
  30. done()
  31. it 'should send a delete request when a delete has been received to mark a notification', (done)->
  32. @controller.markNotificationAsRead @req, send:=>
  33. @handler.markAsRead.calledWith(user_id, notification_id).should.equal true
  34. done()