NotificationsControllerTest.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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', function() {
  44. return 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. })
  64. describe('addNotification', function() {
  65. return it('should tell the notifications to add the notification for the user', function(done) {
  66. this.notifications.addNotification = sinon.stub().callsArgWith(2)
  67. const req = {
  68. params: {
  69. user_id
  70. },
  71. body: this.stubbedNotification
  72. }
  73. return this.controller.addNotification(req, {
  74. send: result => {
  75. this.notifications.addNotification
  76. .calledWith(user_id, this.stubbedNotification)
  77. .should.equal(true)
  78. return done()
  79. }
  80. })
  81. })
  82. })
  83. describe('removeNotificationId', function() {
  84. return it('should tell the notifications to mark the notification Id as read', function(done) {
  85. this.notifications.removeNotificationId = sinon.stub().callsArgWith(2)
  86. const req = {
  87. params: {
  88. user_id,
  89. notification_id
  90. }
  91. }
  92. return this.controller.removeNotificationId(req, {
  93. send: result => {
  94. this.notifications.removeNotificationId
  95. .calledWith(user_id, notification_id)
  96. .should.equal(true)
  97. return done()
  98. }
  99. })
  100. })
  101. })
  102. describe('removeNotificationKey', function() {
  103. return it('should tell the notifications to mark the notification Key as read', function(done) {
  104. this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
  105. const req = {
  106. params: {
  107. user_id
  108. },
  109. body: { key: notification_key }
  110. }
  111. return this.controller.removeNotificationKey(req, {
  112. send: result => {
  113. this.notifications.removeNotificationKey
  114. .calledWith(user_id, notification_key)
  115. .should.equal(true)
  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. send: result => {
  133. this.notifications.removeNotificationByKeyOnly
  134. .calledWith(notification_key)
  135. .should.equal(true)
  136. return done()
  137. }
  138. })
  139. })
  140. })
  141. })