Merge pull request #5479 from overleaf/bg-refresh-features-on-editor-load

refresh user features on editor load when out of date

GitOrigin-RevId: ef39b5626cfdc6ed611137a6f6eca3417d3ce73f
This commit is contained in:
Brian Gough
2021-10-27 08:03:22 +00:00
committed by Copybot
parent 5862359ff0
commit e681c6322f
7 changed files with 123 additions and 3 deletions
@@ -105,6 +105,10 @@ describe('ProjectController', function () {
this.Features = {
hasFeature: sinon.stub(),
}
this.FeaturesUpdater = {
featuresEpochIsCurrent: sinon.stub().returns(true),
refreshFeatures: sinon.stub().yields(null, this.user),
}
this.BrandVariationsHandler = {
getBrandVariationById: sinon
.stub()
@@ -167,6 +171,7 @@ describe('ProjectController', function () {
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
'./ProjectEntityHandler': this.ProjectEntityHandler,
'../../infrastructure/Features': this.Features,
'../Subscription/FeaturesUpdater': this.FeaturesUpdater,
'../Notifications/NotificationsBuilder': this.NotificationBuilder,
'../User/UserGetter': this.UserGetter,
'../BrandVariations/BrandVariationsHandler': this
@@ -1083,6 +1088,18 @@ describe('ProjectController', function () {
this.ProjectController.loadEditor(this.req, this.res)
})
it('should refresh the user features if the epoch is outdated', function (done) {
this.FeaturesUpdater.featuresEpochIsCurrent = sinon.stub().returns(false)
this.res.render = () => {
this.FeaturesUpdater.refreshFeatures.should.have.been.calledWith(
this.user._id,
'load-editor'
)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
describe('pdf caching feature flags', function () {
/* eslint-disable mocha/no-identical-title */
function showNoVariant() {
@@ -31,6 +31,7 @@ describe('UserFeaturesUpdater', function () {
'../../models/User': {
User: this.User,
},
'@overleaf/settings': (this.Settings = {}),
},
})
})
@@ -58,6 +59,31 @@ describe('UserFeaturesUpdater', function () {
)
expect(updateArgs[1].featuresUpdatedAt instanceof Date).to.be.true
features.should.deep.equal(update)
expect(updateArgs[1].featuresEpoch).to.be.undefined
done()
}
)
})
it('should set the featuresEpoch when present', function (done) {
const userId = '5208dd34438842e2db000005'
const update = {
versioning: true,
}
this.Settings.featuresEpoch = 'epoch-1'
this.UserFeaturesUpdater.updateFeatures(
userId,
update,
(err, features) => {
const updateArgs = this.User.findByIdAndUpdate.lastCall.args
expect(updateArgs[0]).to.deep.equal(userId)
assert.equal(err, null)
expect(Object.keys(updateArgs[1]).length).to.equal(3)
expect(updateArgs[1]['features.versioning']).to.equal(
update.versioning
)
expect(updateArgs[1].featuresUpdatedAt instanceof Date).to.be.true
features.should.deep.equal(update)
expect(updateArgs[1].featuresEpoch).to.equal('epoch-1')
done()
}
)