mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
46 lines
1.6 KiB
CoffeeScript
46 lines
1.6 KiB
CoffeeScript
SandboxedModule = require('sandboxed-module')
|
|
assert = require('assert')
|
|
require('chai').should()
|
|
sinon = require('sinon')
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Notifications/NotificationsController.js'
|
|
|
|
|
|
describe 'NotificationsController', ->
|
|
user_id = "123nd3ijdks"
|
|
notification_id = "123njdskj9jlk"
|
|
|
|
beforeEach ->
|
|
@handler =
|
|
getUserNotifications: sinon.stub().callsArgWith(1)
|
|
markAsRead: sinon.stub().callsArgWith(2)
|
|
@req =
|
|
params:
|
|
notification_id:notification_id
|
|
session:
|
|
user:
|
|
_id:user_id
|
|
i18n:
|
|
translate:->
|
|
@AuthenticationController =
|
|
getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
|
|
@controller = SandboxedModule.require modulePath, requires:
|
|
"./NotificationsHandler":@handler
|
|
"underscore":@underscore =
|
|
map:(arr)-> return arr
|
|
'logger-sharelatex':
|
|
log:->
|
|
err:->
|
|
'../Authentication/AuthenticationController': @AuthenticationController
|
|
|
|
it 'should ask the handler for all unread notifications', (done)->
|
|
allNotifications = [{_id: notification_id, user_id: user_id}]
|
|
@handler.getUserNotifications = sinon.stub().callsArgWith(1, null, allNotifications)
|
|
@controller.getAllUnreadNotifications @req, send:(body)=>
|
|
body.should.equal allNotifications
|
|
@handler.getUserNotifications.calledWith(user_id).should.equal true
|
|
done()
|
|
|
|
it 'should send a delete request when a delete has been received to mark a notification', (done)->
|
|
@controller.markNotificationAsRead @req, send:=>
|
|
@handler.markAsRead.calledWith(user_id, notification_id).should.equal true
|
|
done()
|