NotificationsControllerTest.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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, { requires: {
  27. 'logger-sharelatex': { log() {}
  28. },
  29. './Notifications':this.notifications,
  30. 'metrics-sharelatex': {
  31. inc: sinon.stub()
  32. }
  33. }
  34. }
  35. );
  36. return this.stubbedNotification = [{key: notification_key, messageOpts:"some info", templateKey:"template-key"}];});
  37. describe("getUserNotifications", () =>
  38. it('should ask the notifications for the users notifications', function(done){
  39. this.notifications.getUserNotifications = sinon.stub().callsArgWith(1, null, this.stubbedNotification);
  40. const req = {
  41. params: {
  42. user_id
  43. }
  44. };
  45. return this.controller.getUserNotifications(req, { json:result=> {
  46. result.should.equal(this.stubbedNotification);
  47. this.notifications.getUserNotifications.calledWith(user_id).should.equal(true);
  48. return done();
  49. }
  50. }
  51. );
  52. })
  53. );
  54. describe("addNotification", () =>
  55. it("should tell the notifications to add the notification for the user", function(done){
  56. this.notifications.addNotification = sinon.stub().callsArgWith(2);
  57. const req = {
  58. params: {
  59. user_id
  60. },
  61. body: this.stubbedNotification
  62. };
  63. return this.controller.addNotification(req, { send:result=> {
  64. this.notifications.addNotification.calledWith(user_id, this.stubbedNotification).should.equal(true);
  65. return done();
  66. }
  67. }
  68. );
  69. })
  70. );
  71. describe("removeNotificationId", () =>
  72. it("should tell the notifications to mark the notification Id as read", function(done){
  73. this.notifications.removeNotificationId = sinon.stub().callsArgWith(2);
  74. const req = {
  75. params: {
  76. user_id,
  77. notification_id
  78. }
  79. };
  80. return this.controller.removeNotificationId(req, { send:result=> {
  81. this.notifications.removeNotificationId.calledWith(user_id, notification_id).should.equal(true);
  82. return done();
  83. }
  84. }
  85. );
  86. })
  87. );
  88. describe("removeNotificationKey", () =>
  89. it("should tell the notifications to mark the notification Key as read", function(done){
  90. this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2);
  91. const req = {
  92. params: {
  93. user_id
  94. },
  95. body: {key: notification_key}
  96. };
  97. return this.controller.removeNotificationKey(req, { send:result=> {
  98. this.notifications.removeNotificationKey.calledWith(user_id, notification_key).should.equal(true);
  99. return done();
  100. }
  101. }
  102. );
  103. })
  104. );
  105. return describe("removeNotificationByKeyOnly", () =>
  106. it("should tell the notifications to mark the notification Key as read", function(done){
  107. this.notifications.removeNotificationByKeyOnly = sinon.stub().callsArgWith(1);
  108. const req = {
  109. params: {
  110. key: notification_key
  111. }
  112. };
  113. return this.controller.removeNotificationByKeyOnly(req, { send:result=> {
  114. this.notifications.removeNotificationByKeyOnly.calledWith(notification_key).should.equal(true);
  115. return done();
  116. }
  117. }
  118. );
  119. })
  120. );
  121. });