2020-01-13 14:01:13 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-01-13 14:01:07 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-01-13 14:01:20 -05:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = '../../../app/js/NotificationsController.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const assert = require('assert')
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2023-03-16 08:38:09 -04:00
|
|
|
const userId = '51dc93e6fb625a261300003b'
|
|
|
|
const notificationId = 'fb625a26f09d'
|
|
|
|
const notificationKey = 'my-notification-key'
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
describe('Notifications Controller', function () {
|
|
|
|
beforeEach(function () {
|
2020-01-13 14:01:20 -05:00
|
|
|
const self = this
|
|
|
|
this.notifications = {}
|
|
|
|
this.controller = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./Notifications': this.notifications,
|
2020-11-25 06:57:20 -05:00
|
|
|
'@overleaf/metrics': {
|
2021-07-13 07:04:44 -04:00
|
|
|
inc: sinon.stub(),
|
|
|
|
},
|
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2016-01-16 15:28:19 -05:00
|
|
|
|
2020-01-13 14:01:20 -05:00
|
|
|
return (this.stubbedNotification = [
|
|
|
|
{
|
2023-03-16 08:38:09 -04:00
|
|
|
key: notificationKey,
|
2020-01-13 14:01:20 -05:00
|
|
|
messageOpts: 'some info',
|
2021-07-13 07:04:44 -04:00
|
|
|
templateKey: 'template-key',
|
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
])
|
|
|
|
})
|
2016-01-16 15:28:19 -05:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
describe('getUserNotifications', function () {
|
|
|
|
return it('should ask the notifications for the users notifications', function (done) {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.getUserNotifications = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.stubbedNotification)
|
|
|
|
const req = {
|
|
|
|
params: {
|
2023-03-16 08:38:09 -04:00
|
|
|
user_id: userId,
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
}
|
|
|
|
return this.controller.getUserNotifications(req, {
|
2021-07-13 07:04:44 -04:00
|
|
|
json: result => {
|
2020-01-13 14:01:20 -05:00
|
|
|
result.should.equal(this.stubbedNotification)
|
|
|
|
this.notifications.getUserNotifications
|
2023-03-16 08:38:09 -04:00
|
|
|
.calledWith(userId)
|
2020-01-13 14:01:20 -05:00
|
|
|
.should.equal(true)
|
|
|
|
return done()
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2020-02-11 04:08:35 -05:00
|
|
|
})
|
|
|
|
})
|
2016-01-16 15:28:19 -05:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
describe('addNotification', function () {
|
|
|
|
return it('should tell the notifications to add the notification for the user', function (done) {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.addNotification = sinon.stub().callsArgWith(2)
|
|
|
|
const req = {
|
|
|
|
params: {
|
2023-03-16 08:38:09 -04:00
|
|
|
user_id: userId,
|
2020-01-13 14:01:20 -05:00
|
|
|
},
|
2021-07-13 07:04:44 -04:00
|
|
|
body: this.stubbedNotification,
|
2020-01-13 14:01:20 -05:00
|
|
|
}
|
|
|
|
return this.controller.addNotification(req, {
|
2021-07-13 07:04:44 -04:00
|
|
|
sendStatus: code => {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.addNotification
|
2023-03-16 08:38:09 -04:00
|
|
|
.calledWith(userId, this.stubbedNotification)
|
2020-01-13 14:01:20 -05:00
|
|
|
.should.equal(true)
|
2020-03-18 11:29:28 -04:00
|
|
|
code.should.equal(200)
|
2020-01-13 14:01:20 -05:00
|
|
|
return done()
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2020-02-11 04:08:35 -05:00
|
|
|
})
|
|
|
|
})
|
2016-01-16 15:28:19 -05:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
describe('removeNotificationId', function () {
|
|
|
|
return it('should tell the notifications to mark the notification Id as read', function (done) {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationId = sinon.stub().callsArgWith(2)
|
|
|
|
const req = {
|
|
|
|
params: {
|
2023-03-16 08:38:09 -04:00
|
|
|
user_id: userId,
|
|
|
|
notification_id: notificationId,
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
}
|
|
|
|
return this.controller.removeNotificationId(req, {
|
2021-07-13 07:04:44 -04:00
|
|
|
sendStatus: code => {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationId
|
2023-03-16 08:38:09 -04:00
|
|
|
.calledWith(userId, notificationId)
|
2020-01-13 14:01:20 -05:00
|
|
|
.should.equal(true)
|
2020-03-18 11:29:28 -04:00
|
|
|
code.should.equal(200)
|
2020-01-13 14:01:20 -05:00
|
|
|
return done()
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2020-02-11 04:08:35 -05:00
|
|
|
})
|
|
|
|
})
|
2016-02-05 04:38:32 -05:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
describe('removeNotificationKey', function () {
|
|
|
|
return it('should tell the notifications to mark the notification Key as read', function (done) {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
|
|
|
|
const req = {
|
|
|
|
params: {
|
2023-03-16 08:38:09 -04:00
|
|
|
user_id: userId,
|
2020-01-13 14:01:20 -05:00
|
|
|
},
|
2023-03-16 08:38:09 -04:00
|
|
|
body: { key: notificationKey },
|
2020-01-13 14:01:20 -05:00
|
|
|
}
|
|
|
|
return this.controller.removeNotificationKey(req, {
|
2021-07-13 07:04:44 -04:00
|
|
|
sendStatus: code => {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationKey
|
2023-03-16 08:38:09 -04:00
|
|
|
.calledWith(userId, notificationKey)
|
2020-01-13 14:01:20 -05:00
|
|
|
.should.equal(true)
|
2020-03-18 11:29:28 -04:00
|
|
|
code.should.equal(200)
|
2020-01-13 14:01:20 -05:00
|
|
|
return done()
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2020-02-11 04:08:35 -05:00
|
|
|
})
|
|
|
|
})
|
2016-08-11 05:01:21 -04:00
|
|
|
|
2020-06-04 03:50:05 -04:00
|
|
|
return describe('removeNotificationByKeyOnly', function () {
|
|
|
|
return it('should tell the notifications to mark the notification Key as read', function (done) {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationByKeyOnly = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1)
|
|
|
|
const req = {
|
|
|
|
params: {
|
2023-03-16 08:38:09 -04:00
|
|
|
key: notificationKey,
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
}
|
|
|
|
return this.controller.removeNotificationByKeyOnly(req, {
|
2021-07-13 07:04:44 -04:00
|
|
|
sendStatus: code => {
|
2020-01-13 14:01:20 -05:00
|
|
|
this.notifications.removeNotificationByKeyOnly
|
2023-03-16 08:38:09 -04:00
|
|
|
.calledWith(notificationKey)
|
2020-01-13 14:01:20 -05:00
|
|
|
.should.equal(true)
|
2020-03-18 11:29:28 -04:00
|
|
|
code.should.equal(200)
|
2020-01-13 14:01:20 -05:00
|
|
|
return done()
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|
2020-02-11 04:08:35 -05:00
|
|
|
})
|
|
|
|
})
|
2020-01-13 14:01:20 -05:00
|
|
|
})
|