NotificationsControllerTests.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const SandboxedModule = require('sandboxed-module')
  15. const assert = require('assert')
  16. require('chai').should()
  17. const sinon = require('sinon')
  18. const modulePath = require('path').join(
  19. __dirname,
  20. '../../../../app/src/Features/Notifications/NotificationsController.js'
  21. )
  22. describe('NotificationsController', function() {
  23. const user_id = '123nd3ijdks'
  24. const notification_id = '123njdskj9jlk'
  25. beforeEach(function() {
  26. this.handler = {
  27. getUserNotifications: sinon.stub().callsArgWith(1),
  28. markAsRead: sinon.stub().callsArgWith(2)
  29. }
  30. this.req = {
  31. params: {
  32. notification_id
  33. },
  34. session: {
  35. user: {
  36. _id: user_id
  37. }
  38. },
  39. i18n: {
  40. translate() {}
  41. }
  42. }
  43. this.AuthenticationController = {
  44. getLoggedInUserId: sinon.stub().returns(this.req.session.user._id)
  45. }
  46. return (this.controller = SandboxedModule.require(modulePath, {
  47. globals: {
  48. console: console
  49. },
  50. requires: {
  51. './NotificationsHandler': this.handler,
  52. underscore: (this.underscore = {
  53. map(arr) {
  54. return arr
  55. }
  56. }),
  57. 'logger-sharelatex': {
  58. log() {},
  59. err() {}
  60. },
  61. '../Authentication/AuthenticationController': this
  62. .AuthenticationController
  63. }
  64. }))
  65. })
  66. it('should ask the handler for all unread notifications', function(done) {
  67. const allNotifications = [{ _id: notification_id, user_id }]
  68. this.handler.getUserNotifications = sinon
  69. .stub()
  70. .callsArgWith(1, null, allNotifications)
  71. return this.controller.getAllUnreadNotifications(this.req, {
  72. send: body => {
  73. body.should.equal(allNotifications)
  74. this.handler.getUserNotifications.calledWith(user_id).should.equal(true)
  75. return done()
  76. }
  77. })
  78. })
  79. it('should send a delete request when a delete has been received to mark a notification', function(done) {
  80. return this.controller.markNotificationAsRead(this.req, {
  81. send: () => {
  82. this.handler.markAsRead
  83. .calledWith(user_id, notification_id)
  84. .should.equal(true)
  85. return done()
  86. }
  87. })
  88. })
  89. })