[web] Fix feature refresh handling in ProjectController (#32353)

* Update tests to check that refreshed features are used correctly

* Fix feature refresh handling in ProjectController

GitOrigin-RevId: 14c0cedf72f6cfe6657aa35fab16e319a37231e7
This commit is contained in:
Antoine Clausse
2026-03-20 13:40:39 +01:00
committed by Copybot
parent 6486ef3e1e
commit f3fbfeab20
2 changed files with 13 additions and 5 deletions
@@ -1082,10 +1082,11 @@ const _ProjectController = {
refreshTimeoutHandler(),
(async () => {
try {
user.features = await FeaturesUpdater.promises.refreshFeatures(
const { features } = await FeaturesUpdater.promises.refreshFeatures(
user._id,
'load-editor'
)
user.features = features
metrics.inc('features-refresh', 1, {
path: 'load-editor',
status: 'success',
@@ -169,7 +169,10 @@ describe('ProjectController', function () {
ctx.FeaturesUpdater = {
featuresEpochIsCurrent: sinon.stub().returns(true),
promises: {
refreshFeatures: sinon.stub().resolves(ctx.user),
refreshFeatures: sinon.stub().resolves({
features: { symbolPalette: true },
featuresChanged: true,
}),
},
}
ctx.BrandVariationsHandler = {
@@ -1112,16 +1115,20 @@ describe('ProjectController', function () {
})
it('should refresh the user features if the epoch is outdated', async function (ctx) {
await new Promise(resolve => {
ctx.Features.hasFeature.withArgs('saas').returns(true)
await new Promise((resolve, reject) => {
ctx.FeaturesUpdater.featuresEpochIsCurrent = sinon.stub().returns(false)
ctx.res.render = () => {
ctx.res.render = (_, data) => {
ctx.FeaturesUpdater.promises.refreshFeatures.should.have.been.calledWith(
ctx.user._id,
'load-editor'
)
expect(data.showSymbolPalette).to.equal(true)
resolve()
}
ctx.ProjectController.loadEditor(ctx.req, ctx.res)
ctx.ProjectController.loadEditor(ctx.req, ctx.res, err => {
if (err) reject(err)
})
})
})