NotificationsControllerTest.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 modulePath = '../../../app/js/NotificationsController.js'
  15. const SandboxedModule = require('sandboxed-module')
  16. const assert = require('assert')
  17. const user_id = '51dc93e6fb625a261300003b'
  18. const notification_id = 'fb625a26f09d'
  19. const notification_key = 'my-notification-key'
  20. describe('Notifications Controller', function () {
  21. beforeEach(function () {
  22. const self = this
  23. this.notifications = {}
  24. this.controller = SandboxedModule.require(modulePath, {
  25. requires: {
  26. './Notifications': this.notifications,
  27. '@overleaf/metrics': {
  28. inc: sinon.stub()
  29. }
  30. }
  31. })
  32. return (this.stubbedNotification = [
  33. {
  34. key: notification_key,
  35. messageOpts: 'some info',
  36. templateKey: 'template-key'
  37. }
  38. ])
  39. })
  40. describe('getUserNotifications', function () {
  41. return it('should ask the notifications for the users notifications', function (done) {
  42. this.notifications.getUserNotifications = sinon
  43. .stub()
  44. .callsArgWith(1, null, this.stubbedNotification)
  45. const req = {
  46. params: {
  47. user_id
  48. }
  49. }
  50. return this.controller.getUserNotifications(req, {
  51. json: (result) => {
  52. result.should.equal(this.stubbedNotification)
  53. this.notifications.getUserNotifications
  54. .calledWith(user_id)
  55. .should.equal(true)
  56. return done()
  57. }
  58. })
  59. })
  60. })
  61. describe('addNotification', function () {
  62. return it('should tell the notifications to add the notification for the user', function (done) {
  63. this.notifications.addNotification = sinon.stub().callsArgWith(2)
  64. const req = {
  65. params: {
  66. user_id
  67. },
  68. body: this.stubbedNotification
  69. }
  70. return this.controller.addNotification(req, {
  71. sendStatus: (code) => {
  72. this.notifications.addNotification
  73. .calledWith(user_id, this.stubbedNotification)
  74. .should.equal(true)
  75. code.should.equal(200)
  76. return done()
  77. }
  78. })
  79. })
  80. })
  81. describe('removeNotificationId', function () {
  82. return 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. sendStatus: (code) => {
  92. this.notifications.removeNotificationId
  93. .calledWith(user_id, notification_id)
  94. .should.equal(true)
  95. code.should.equal(200)
  96. return done()
  97. }
  98. })
  99. })
  100. })
  101. describe('removeNotificationKey', function () {
  102. return it('should tell the notifications to mark the notification Key as read', function (done) {
  103. this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
  104. const req = {
  105. params: {
  106. user_id
  107. },
  108. body: { key: notification_key }
  109. }
  110. return this.controller.removeNotificationKey(req, {
  111. sendStatus: (code) => {
  112. this.notifications.removeNotificationKey
  113. .calledWith(user_id, notification_key)
  114. .should.equal(true)
  115. code.should.equal(200)
  116. return done()
  117. }
  118. })
  119. })
  120. })
  121. return describe('removeNotificationByKeyOnly', function () {
  122. return it('should tell the notifications to mark the notification Key as read', function (done) {
  123. this.notifications.removeNotificationByKeyOnly = sinon
  124. .stub()
  125. .callsArgWith(1)
  126. const req = {
  127. params: {
  128. key: notification_key
  129. }
  130. }
  131. return this.controller.removeNotificationByKeyOnly(req, {
  132. sendStatus: (code) => {
  133. this.notifications.removeNotificationByKeyOnly
  134. .calledWith(notification_key)
  135. .should.equal(true)
  136. code.should.equal(200)
  137. return done()
  138. }
  139. })
  140. })
  141. })
  142. })