Merge pull request #7742 from overleaf/ta-email-preferences-page
Create Email Preferences Page GitOrigin-RevId: 371a62e8423e5cbebff83e61bf35a8b3b638c398
This commit is contained in:
@@ -13,6 +13,7 @@ describe('NewsletterManager', function () {
|
||||
},
|
||||
}
|
||||
this.mailchimp = {
|
||||
get: sinon.stub(),
|
||||
put: sinon.stub(),
|
||||
patch: sinon.stub(),
|
||||
delete: sinon.stub(),
|
||||
@@ -42,6 +43,30 @@ describe('NewsletterManager', function () {
|
||||
this.emailHash = 'c02f60ed0ef51818186274e406c9a48f'
|
||||
})
|
||||
|
||||
describe('subscribed', function () {
|
||||
it('calls Mailchimp to get the user status', async function () {
|
||||
await this.NewsletterManager.subscribed(this.user)
|
||||
expect(this.mailchimp.get).to.have.been.calledWith(
|
||||
`/lists/list_id/members/${this.emailHash}`
|
||||
)
|
||||
})
|
||||
|
||||
it('returns true when subscribed', async function () {
|
||||
this.mailchimp.get.resolves({ status: 'subscribed' })
|
||||
|
||||
const subscribed = await this.NewsletterManager.subscribed(this.user)
|
||||
expect(subscribed).to.be.true
|
||||
})
|
||||
|
||||
it('returns false on 404', async function () {
|
||||
const err = new Error()
|
||||
err.status = 404
|
||||
this.mailchimp.get.rejects(err)
|
||||
const subscribed = await this.NewsletterManager.subscribed(this.user)
|
||||
expect(subscribed).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
describe('subscribe', function () {
|
||||
it('calls Mailchimp to subscribe the user', async function () {
|
||||
await this.NewsletterManager.subscribe(this.user)
|
||||
|
||||
@@ -42,7 +42,10 @@ describe('UserController', function () {
|
||||
promises: { getUser: sinon.stub().resolves(this.user) },
|
||||
}
|
||||
this.User = { findById: sinon.stub().callsArgWith(1, null, this.user) }
|
||||
this.NewsLetterManager = { unsubscribe: sinon.stub().callsArgWith(1) }
|
||||
this.NewsLetterManager = {
|
||||
subscribe: sinon.stub().yields(),
|
||||
unsubscribe: sinon.stub().yields(),
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
establishUserSession: sinon.stub().callsArg(2),
|
||||
}
|
||||
@@ -288,9 +291,23 @@ describe('UserController', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('subscribe', function () {
|
||||
it('should send the user to subscribe', function (done) {
|
||||
this.res.json = data => {
|
||||
expect(data.message).to.equal('thanks_settings_updated')
|
||||
this.NewsLetterManager.subscribe
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
done()
|
||||
}
|
||||
this.UserController.subscribe(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('unsubscribe', function () {
|
||||
it('should send the user to unsubscribe', function (done) {
|
||||
this.res.sendStatus = () => {
|
||||
this.res.json = data => {
|
||||
expect(data.message).to.equal('thanks_settings_updated')
|
||||
this.NewsLetterManager.unsubscribe
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
|
||||
@@ -60,6 +60,9 @@ describe('UserPagesController', function () {
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
getSessionUser: sinon.stub().returns(this.user),
|
||||
}
|
||||
this.NewsletterManager = {
|
||||
subscribed: sinon.stub().yields(),
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
_getRedirectFromSession: sinon.stub(),
|
||||
setRedirectInSession: sinon.stub(),
|
||||
@@ -74,6 +77,7 @@ describe('UserPagesController', function () {
|
||||
'@overleaf/settings': this.settings,
|
||||
'./UserGetter': this.UserGetter,
|
||||
'./UserSessionsManager': this.UserSessionsManager,
|
||||
'../Newsletter/NewsletterManager': this.NewsletterManager,
|
||||
'../Errors/ErrorController': this.ErrorController,
|
||||
'../Authentication/AuthenticationController':
|
||||
this.AuthenticationController,
|
||||
@@ -225,6 +229,34 @@ describe('UserPagesController', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('emailPreferencesPage', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
||||
})
|
||||
|
||||
it('render page with subscribed status', function (done) {
|
||||
this.NewsletterManager.subscribed.yields(null, true)
|
||||
this.res.render = function (page, data) {
|
||||
page.should.equal('user/email-preferences')
|
||||
data.title.should.equal('newsletter_info_title')
|
||||
data.subscribed.should.equal(true)
|
||||
return done()
|
||||
}
|
||||
return this.UserPagesController.emailPreferencesPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('render page with unsubscribed status', function (done) {
|
||||
this.NewsletterManager.subscribed.yields(null, false)
|
||||
this.res.render = function (page, data) {
|
||||
page.should.equal('user/email-preferences')
|
||||
data.title.should.equal('newsletter_info_title')
|
||||
data.subscribed.should.equal(false)
|
||||
return done()
|
||||
}
|
||||
return this.UserPagesController.emailPreferencesPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('settingsPage', function () {
|
||||
beforeEach(function () {
|
||||
this.request.get = sinon
|
||||
|
||||
Reference in New Issue
Block a user