| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /* eslint-disable
- camelcase,
- no-return-assign,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const sinon = require('sinon')
- const modulePath = '../../../app/js/NotificationsController.js'
- const SandboxedModule = require('sandboxed-module')
- const assert = require('assert')
- const user_id = '51dc93e6fb625a261300003b'
- const notification_id = 'fb625a26f09d'
- const notification_key = 'my-notification-key'
- describe('Notifications Controller', function () {
- beforeEach(function () {
- const self = this
- this.notifications = {}
- this.controller = SandboxedModule.require(modulePath, {
- requires: {
- './Notifications': this.notifications,
- '@overleaf/metrics': {
- inc: sinon.stub()
- }
- }
- })
- return (this.stubbedNotification = [
- {
- key: notification_key,
- messageOpts: 'some info',
- templateKey: 'template-key'
- }
- ])
- })
- describe('getUserNotifications', function () {
- return it('should ask the notifications for the users notifications', function (done) {
- this.notifications.getUserNotifications = sinon
- .stub()
- .callsArgWith(1, null, this.stubbedNotification)
- const req = {
- params: {
- user_id
- }
- }
- return this.controller.getUserNotifications(req, {
- json: (result) => {
- result.should.equal(this.stubbedNotification)
- this.notifications.getUserNotifications
- .calledWith(user_id)
- .should.equal(true)
- return done()
- }
- })
- })
- })
- describe('addNotification', function () {
- return it('should tell the notifications to add the notification for the user', function (done) {
- this.notifications.addNotification = sinon.stub().callsArgWith(2)
- const req = {
- params: {
- user_id
- },
- body: this.stubbedNotification
- }
- return this.controller.addNotification(req, {
- sendStatus: (code) => {
- this.notifications.addNotification
- .calledWith(user_id, this.stubbedNotification)
- .should.equal(true)
- code.should.equal(200)
- return done()
- }
- })
- })
- })
- describe('removeNotificationId', function () {
- return it('should tell the notifications to mark the notification Id as read', function (done) {
- this.notifications.removeNotificationId = sinon.stub().callsArgWith(2)
- const req = {
- params: {
- user_id,
- notification_id
- }
- }
- return this.controller.removeNotificationId(req, {
- sendStatus: (code) => {
- this.notifications.removeNotificationId
- .calledWith(user_id, notification_id)
- .should.equal(true)
- code.should.equal(200)
- return done()
- }
- })
- })
- })
- describe('removeNotificationKey', function () {
- return it('should tell the notifications to mark the notification Key as read', function (done) {
- this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
- const req = {
- params: {
- user_id
- },
- body: { key: notification_key }
- }
- return this.controller.removeNotificationKey(req, {
- sendStatus: (code) => {
- this.notifications.removeNotificationKey
- .calledWith(user_id, notification_key)
- .should.equal(true)
- code.should.equal(200)
- return done()
- }
- })
- })
- })
- return describe('removeNotificationByKeyOnly', function () {
- return it('should tell the notifications to mark the notification Key as read', function (done) {
- this.notifications.removeNotificationByKeyOnly = sinon
- .stub()
- .callsArgWith(1)
- const req = {
- params: {
- key: notification_key
- }
- }
- return this.controller.removeNotificationByKeyOnly(req, {
- sendStatus: (code) => {
- this.notifications.removeNotificationByKeyOnly
- .calledWith(notification_key)
- .should.equal(true)
- code.should.equal(200)
- return done()
- }
- })
- })
- })
- })
|