NotificationsControllerTest.coffee 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../app/js/NotificationsController.js"
  5. SandboxedModule = require('sandboxed-module')
  6. assert = require('assert')
  7. user_id = "51dc93e6fb625a261300003b"
  8. notification_id = "fb625a26f09d"
  9. describe 'Notifications controller', ->
  10. beforeEach ->
  11. self = @
  12. @notifications = {}
  13. @controller = SandboxedModule.require modulePath, requires:
  14. 'logger-sharelatex': log:->
  15. './Notifications':@notifications
  16. @stubbedNotification = [{key:"notification-key", messageOpts:"some info", templateKey:"template-key"}]
  17. describe "getUserNotifications", ->
  18. it 'should ask the notifications for the users notifications', (done)->
  19. @notifications.getUserNotifications = sinon.stub().callsArgWith(1, null, @stubbedNotification)
  20. req =
  21. params:
  22. user_id: user_id
  23. @controller.getUserNotifications req, json:(result)=>
  24. result.should.equal @stubbedNotification
  25. @notifications.getUserNotifications.calledWith(user_id).should.equal true
  26. done()
  27. describe "addNotification", ->
  28. it "should tell the notifications to add the notification for the user", (done)->
  29. @notifications.addNotification = sinon.stub().callsArgWith(2)
  30. req =
  31. params:
  32. user_id: user_id
  33. body: @stubbedNotification
  34. @controller.addNotification req, send:(result)=>
  35. @notifications.addNotification.calledWith(user_id, @stubbedNotification).should.equal true
  36. done()
  37. describe "removeNotification", ->
  38. it "should tell the notifications to mark the notification as read", (done)->
  39. @notifications.removeNotification = sinon.stub().callsArgWith(2)
  40. req =
  41. params:
  42. user_id: user_id
  43. notification_id: notification_id
  44. @controller.removeNotification req, send:(result)=>
  45. @notifications.removeNotification.calledWith(user_id, notification_id).should.equal true
  46. done()