|
@@ -1,5 +1,6 @@
|
|
|
sinon = require('sinon')
|
|
sinon = require('sinon')
|
|
|
chai = require('chai')
|
|
chai = require('chai')
|
|
|
|
|
+expect = chai.should
|
|
|
should = chai.should()
|
|
should = chai.should()
|
|
|
modulePath = "../../../app/js/Notifications.js"
|
|
modulePath = "../../../app/js/Notifications.js"
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
SandboxedModule = require('sandboxed-module')
|
|
@@ -44,12 +45,27 @@ describe 'Notifications Tests', ->
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
describe 'addNotification', ->
|
|
describe 'addNotification', ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @stubbedNotification = {
|
|
|
|
|
+ user_id: ObjectId(user_id),
|
|
|
|
|
+ key:"notification-key",
|
|
|
|
|
+ messageOpts:"some info",
|
|
|
|
|
+ templateKey:"template-key"
|
|
|
|
|
+ }
|
|
|
|
|
+ @expectedDocument = {
|
|
|
|
|
+ user_id: @stubbedNotification.user_id,
|
|
|
|
|
+ key:"notification-key",
|
|
|
|
|
+ messageOpts:"some info",
|
|
|
|
|
+ templateKey:"template-key",
|
|
|
|
|
+ expires: false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
it 'should insert the notification into the collection', (done)->
|
|
it 'should insert the notification into the collection', (done)->
|
|
|
@insertStub.callsArgWith(1, null)
|
|
@insertStub.callsArgWith(1, null)
|
|
|
@countStub.callsArgWith(1, null, 0)
|
|
@countStub.callsArgWith(1, null, 0)
|
|
|
|
|
|
|
|
@notifications.addNotification user_id, @stubbedNotification, (err)=>
|
|
@notifications.addNotification user_id, @stubbedNotification, (err)=>
|
|
|
- @insertStub.calledWith(@stubbedNotification).should.equal true
|
|
|
|
|
|
|
+ @insertStub.calledWith(@expectedDocument).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it 'should fail insert of existing notification key', (done)->
|
|
it 'should fail insert of existing notification key', (done)->
|
|
@@ -57,9 +73,37 @@ describe 'Notifications Tests', ->
|
|
|
@countStub.callsArgWith(1, null, 1)
|
|
@countStub.callsArgWith(1, null, 1)
|
|
|
|
|
|
|
|
@notifications.addNotification user_id, @stubbedNotification, (err)=>
|
|
@notifications.addNotification user_id, @stubbedNotification, (err)=>
|
|
|
- @insertStub.calledWith(@stubbedNotification).should.equal false
|
|
|
|
|
|
|
+ @insertStub.calledWith(@expectedDocument).should.equal false
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
|
|
+ describe 'when the notification is set to expire', () ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @stubbedNotification = {
|
|
|
|
|
+ user_id: ObjectId(user_id),
|
|
|
|
|
+ key:"notification-key",
|
|
|
|
|
+ messageOpts:"some info",
|
|
|
|
|
+ templateKey:"template-key",
|
|
|
|
|
+ expires: true
|
|
|
|
|
+ }
|
|
|
|
|
+ @expectedDocument = {
|
|
|
|
|
+ user_id: @stubbedNotification.user_id,
|
|
|
|
|
+ key:"notification-key",
|
|
|
|
|
+ messageOpts:"some info",
|
|
|
|
|
+ templateKey:"template-key",
|
|
|
|
|
+ expires: true,
|
|
|
|
|
+ expiresFrom: new Date()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ it 'should add an `expiresFrom` Date field to the inserted notification', (done)->
|
|
|
|
|
+ @insertStub.callsArgWith(1, null)
|
|
|
|
|
+ @countStub.callsArgWith(1, null, 0)
|
|
|
|
|
+
|
|
|
|
|
+ @notifications.addNotification user_id, @stubbedNotification, (err)=>
|
|
|
|
|
+ @insertStub.callCount.should.equal 1
|
|
|
|
|
+ Object.keys(@insertStub.lastCall.args[0]).should.deep.equal Object.keys(@expectedDocument)
|
|
|
|
|
+ @insertStub.firstCall.args[0].expiresFrom.should.be.instanceof Date
|
|
|
|
|
+ done()
|
|
|
|
|
+
|
|
|
describe 'removeNotificationId', ->
|
|
describe 'removeNotificationId', ->
|
|
|
it 'should mark the notification id as read', (done)->
|
|
it 'should mark the notification id as read', (done)->
|
|
|
@updateStub.callsArgWith(2, null)
|
|
@updateStub.callsArgWith(2, null)
|