NotificationsControllerTest.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* eslint-disable
  2. camelcase,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const sinon = require('sinon')
  14. const chai = require('chai')
  15. const should = chai.should()
  16. const modulePath = '../../../app/js/NotificationsController.js'
  17. const SandboxedModule = require('sandboxed-module')
  18. const assert = require('assert')
  19. const user_id = '51dc93e6fb625a261300003b'
  20. const notification_id = 'fb625a26f09d'
  21. const notification_key = 'my-notification-key'
  22. describe('Notifications Controller', function() {
  23. beforeEach(function() {
  24. const self = this
  25. this.notifications = {}
  26. this.controller = SandboxedModule.require(modulePath, {
  27. requires: {
  28. 'logger-sharelatex': { log() {} },
  29. './Notifications': this.notifications,
  30. 'metrics-sharelatex': {
  31. inc: sinon.stub()
  32. }
  33. }
  34. })
  35. return (this.stubbedNotification = [
  36. {
  37. key: notification_key,
  38. messageOpts: 'some info',
  39. templateKey: 'template-key'
  40. }
  41. ])
  42. })
  43. describe('getUserNotifications', () =>
  44. it('should ask the notifications for the users notifications', function(done) {
  45. this.notifications.getUserNotifications = sinon
  46. .stub()
  47. .callsArgWith(1, null, this.stubbedNotification)
  48. const req = {
  49. params: {
  50. user_id
  51. }
  52. }
  53. return this.controller.getUserNotifications(req, {
  54. json: result => {
  55. result.should.equal(this.stubbedNotification)
  56. this.notifications.getUserNotifications
  57. .calledWith(user_id)
  58. .should.equal(true)
  59. return done()
  60. }
  61. })
  62. }))
  63. describe('addNotification', () =>
  64. it('should tell the notifications to add the notification for the user', function(done) {
  65. this.notifications.addNotification = sinon.stub().callsArgWith(2)
  66. const req = {
  67. params: {
  68. user_id
  69. },
  70. body: this.stubbedNotification
  71. }
  72. return this.controller.addNotification(req, {
  73. send: result => {
  74. this.notifications.addNotification
  75. .calledWith(user_id, this.stubbedNotification)
  76. .should.equal(true)
  77. return done()
  78. }
  79. })
  80. }))
  81. describe('removeNotificationId', () =>
  82. it('should tell the notifications to mark the notification Id as read', function(done) {
  83. this.notifications.removeNotificationId = sinon.stub().callsArgWith(2)
  84. const req = {
  85. params: {
  86. user_id,
  87. notification_id
  88. }
  89. }
  90. return this.controller.removeNotificationId(req, {
  91. send: result => {
  92. this.notifications.removeNotificationId
  93. .calledWith(user_id, notification_id)
  94. .should.equal(true)
  95. return done()
  96. }
  97. })
  98. }))
  99. describe('removeNotificationKey', () =>
  100. it('should tell the notifications to mark the notification Key as read', function(done) {
  101. this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
  102. const req = {
  103. params: {
  104. user_id
  105. },
  106. body: { key: notification_key }
  107. }
  108. return this.controller.removeNotificationKey(req, {
  109. send: result => {
  110. this.notifications.removeNotificationKey
  111. .calledWith(user_id, notification_key)
  112. .should.equal(true)
  113. return done()
  114. }
  115. })
  116. }))
  117. return describe('removeNotificationByKeyOnly', () =>
  118. it('should tell the notifications to mark the notification Key as read', function(done) {
  119. this.notifications.removeNotificationByKeyOnly = sinon
  120. .stub()
  121. .callsArgWith(1)
  122. const req = {
  123. params: {
  124. key: notification_key
  125. }
  126. }
  127. return this.controller.removeNotificationByKeyOnly(req, {
  128. send: result => {
  129. this.notifications.removeNotificationByKeyOnly
  130. .calledWith(notification_key)
  131. .should.equal(true)
  132. return done()
  133. }
  134. })
  135. }))
  136. })