Check features before showing upgrade prompts

GitOrigin-RevId: 6f0ed9eca88197e1160b149cb304e27075aa0627
This commit is contained in:
Thomas Mees 2022-07-20 12:52:56 +02:00 committed by Copybot
parent 9ea1226460
commit fc65e54718
2 changed files with 25 additions and 1 deletions

View file

@ -443,6 +443,9 @@ const ProjectController = {
}) })
}, },
usersBestSubscription(cb) { usersBestSubscription(cb) {
if (!Features.hasFeature('saas')) {
return cb()
}
SubscriptionViewModelBuilder.getBestSubscription( SubscriptionViewModelBuilder.getBestSubscription(
{ _id: userId }, { _id: userId },
(err, subscription) => { (err, subscription) => {
@ -1113,6 +1116,7 @@ const ProjectController = {
// Persistent upgrade prompts // Persistent upgrade prompts
const showHeaderUpgradePrompt = const showHeaderUpgradePrompt =
Features.hasFeature('saas') &&
userId && userId &&
!subscription && !subscription &&
!userIsMemberOfGroupSubscription && !userIsMemberOfGroupSubscription &&

View file

@ -524,7 +524,8 @@ describe('ProjectController', function () {
this.ProjectController.projectListPage(this.req, this.res) this.ProjectController.projectListPage(this.req, this.res)
}) })
it("should send the user's best subscription", function (done) { it("should send the user's best subscription when saas feature present", function (done) {
this.Features.hasFeature.withArgs('saas').returns(true)
this.res.render = (pageName, opts) => { this.res.render = (pageName, opts) => {
expect(opts.usersBestSubscription).to.deep.include({ type: 'free' }) expect(opts.usersBestSubscription).to.deep.include({ type: 'free' })
done() done()
@ -532,6 +533,15 @@ describe('ProjectController', function () {
this.ProjectController.projectListPage(this.req, this.res) this.ProjectController.projectListPage(this.req, this.res)
}) })
it('should not return a best subscription without saas feature', function (done) {
this.Features.hasFeature.withArgs('saas').returns(false)
this.res.render = (pageName, opts) => {
expect(opts.usersBestSubscription).to.be.undefined
done()
}
this.ProjectController.projectListPage(this.req, this.res)
})
describe('front widget', function (done) { describe('front widget', function (done) {
beforeEach(function () { beforeEach(function () {
this.settings.overleaf = { this.settings.overleaf = {
@ -1404,11 +1414,21 @@ describe('ProjectController', function () {
describe('persistent upgrade prompt', function () { describe('persistent upgrade prompt', function () {
beforeEach(function () { beforeEach(function () {
// default to saas enabled
this.Features.hasFeature.withArgs('saas').returns(true)
// default to without a subscription // default to without a subscription
this.SubscriptionLocator.getUsersSubscription = sinon this.SubscriptionLocator.getUsersSubscription = sinon
.stub() .stub()
.callsArgWith(1, null, null) .callsArgWith(1, null, null)
}) })
it('should not show without the saas feature', function (done) {
this.Features.hasFeature.withArgs('saas').returns(false)
this.res.render = (pageName, opts) => {
expect(opts.showHeaderUpgradePrompt).to.equal(false)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
it('should show for a user without a subscription or only non-paid affiliations', function (done) { it('should show for a user without a subscription or only non-paid affiliations', function (done) {
this.res.render = (pageName, opts) => { this.res.render = (pageName, opts) => {
expect(opts.showHeaderUpgradePrompt).to.equal(true) expect(opts.showHeaderUpgradePrompt).to.equal(true)