|
|
@@ -10,7 +10,9 @@ expect = require("chai").expect
|
|
|
describe 'AnnouncementsHandler', ->
|
|
|
|
|
|
beforeEach ->
|
|
|
- @user_id = "some_id"
|
|
|
+ @user =
|
|
|
+ _id:"some_id"
|
|
|
+ email: "someone@gmail.com"
|
|
|
@AnalyticsManager =
|
|
|
getLastOccurance: sinon.stub()
|
|
|
@BlogHandler =
|
|
|
@@ -44,7 +46,7 @@ describe 'AnnouncementsHandler', ->
|
|
|
|
|
|
it "should mark all announcements as read is false", (done)->
|
|
|
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
|
|
|
- @handler.getUnreadAnnouncements @user_id, (err, announcements)=>
|
|
|
+ @handler.getUnreadAnnouncements @user, (err, announcements)=>
|
|
|
announcements[0].read.should.equal false
|
|
|
announcements[1].read.should.equal false
|
|
|
announcements[2].read.should.equal false
|
|
|
@@ -53,7 +55,7 @@ describe 'AnnouncementsHandler', ->
|
|
|
|
|
|
it "should should be sorted again to ensure correct order", (done)->
|
|
|
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
|
|
|
- @handler.getUnreadAnnouncements @user_id, (err, announcements)=>
|
|
|
+ @handler.getUnreadAnnouncements @user, (err, announcements)=>
|
|
|
announcements[3].should.equal @stubbedAnnouncements[2]
|
|
|
announcements[2].should.equal @stubbedAnnouncements[3]
|
|
|
announcements[1].should.equal @stubbedAnnouncements[1]
|
|
|
@@ -62,7 +64,7 @@ describe 'AnnouncementsHandler', ->
|
|
|
|
|
|
it "should return older ones marked as read as well", (done)->
|
|
|
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2014/04/12/title-date-irrelivant"}})
|
|
|
- @handler.getUnreadAnnouncements @user_id, (err, announcements)=>
|
|
|
+ @handler.getUnreadAnnouncements @user, (err, announcements)=>
|
|
|
announcements[0].id.should.equal @stubbedAnnouncements[0].id
|
|
|
announcements[0].read.should.equal false
|
|
|
|
|
|
@@ -79,7 +81,7 @@ describe 'AnnouncementsHandler', ->
|
|
|
|
|
|
it "should return all of them marked as read", (done)->
|
|
|
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2016/11/01/introducting-latex-code-checker"}})
|
|
|
- @handler.getUnreadAnnouncements @user_id, (err, announcements)=>
|
|
|
+ @handler.getUnreadAnnouncements @user, (err, announcements)=>
|
|
|
announcements[0].read.should.equal true
|
|
|
announcements[1].read.should.equal true
|
|
|
announcements[2].read.should.equal true
|
|
|
@@ -87,3 +89,27 @@ describe 'AnnouncementsHandler', ->
|
|
|
done()
|
|
|
|
|
|
|
|
|
+ describe "with custom domain announcements", ->
|
|
|
+ beforeEach ->
|
|
|
+ @stubbedDomainSpecificAnn = [
|
|
|
+ {
|
|
|
+ domains: ["gmail.com", 'yahoo.edu']
|
|
|
+ title: "some message"
|
|
|
+ excerpt: "read this"
|
|
|
+ url:"http://www.sharelatex.com/i/somewhere"
|
|
|
+ id:"iaaa"
|
|
|
+ date: new Date(1308369600000).toString()
|
|
|
+ }
|
|
|
+ ]
|
|
|
+
|
|
|
+ @handler._domainSpecificAnnouncements = sinon.stub().returns(@stubbedDomainSpecificAnn)
|
|
|
+
|
|
|
+ it "should insert the domain specific in the correct place", (done)->
|
|
|
+ @AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
|
|
|
+ @handler.getUnreadAnnouncements @user, (err, announcements)=>
|
|
|
+ announcements[4].should.equal @stubbedAnnouncements[2]
|
|
|
+ announcements[3].should.equal @stubbedAnnouncements[3]
|
|
|
+ announcements[2].should.equal @stubbedAnnouncements[1]
|
|
|
+ announcements[1].should.equal @stubbedDomainSpecificAnn[0]
|
|
|
+ announcements[0].should.equal @stubbedAnnouncements[0]
|
|
|
+ done()
|