diff --git a/src/lib/routes/admin-api/feature.ts b/src/lib/routes/admin-api/feature.ts index afe86a78ee..ca06824506 100644 --- a/src/lib/routes/admin-api/feature.ts +++ b/src/lib/routes/admin-api/feature.ts @@ -40,24 +40,32 @@ class FeatureController extends Controller { this.tagService = featureTagService; this.service = featureToggleServiceV2; - this.get('/', this.getAllToggles); - this.post('/', this.createToggle, CREATE_FEATURE); - this.get('/:featureName', this.getToggle); - this.put('/:featureName', this.updateToggle, UPDATE_FEATURE); - this.delete('/:featureName', this.archiveToggle, DELETE_FEATURE); + if (!config.disableLegacyFeaturesApi) { + this.get('/', this.getAllToggles); + this.post('/', this.createToggle, CREATE_FEATURE); + this.get('/:featureName', this.getToggle); + this.put('/:featureName', this.updateToggle, UPDATE_FEATURE); + this.delete('/:featureName', this.archiveToggle, DELETE_FEATURE); + this.post('/:featureName/toggle', this.toggle, UPDATE_FEATURE); + this.post('/:featureName/toggle/on', this.toggleOn, UPDATE_FEATURE); + this.post( + '/:featureName/toggle/off', + this.toggleOff, + UPDATE_FEATURE, + ); + this.delete( + '/:featureName/tags/:type/:value', + this.removeTag, + UPDATE_FEATURE, + ); + this.post('/:featureName/stale/on', this.staleOn, UPDATE_FEATURE); + this.post('/:featureName/stale/off', this.staleOff, UPDATE_FEATURE); + } + this.post('/validate', this.validate, NONE); - this.post('/:featureName/toggle', this.toggle, UPDATE_FEATURE); - this.post('/:featureName/toggle/on', this.toggleOn, UPDATE_FEATURE); - this.post('/:featureName/toggle/off', this.toggleOff, UPDATE_FEATURE); - this.post('/:featureName/stale/on', this.staleOn, UPDATE_FEATURE); - this.post('/:featureName/stale/off', this.staleOff, UPDATE_FEATURE); + this.get('/:featureName/tags', this.listTags); this.post('/:featureName/tags', this.addTag, UPDATE_FEATURE); - this.delete( - '/:featureName/tags/:type/:value', - this.removeTag, - UPDATE_FEATURE, - ); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types diff --git a/src/lib/routes/admin-api/index.ts b/src/lib/routes/admin-api/index.ts index 7c29cfb2c9..baaab64880 100644 --- a/src/lib/routes/admin-api/index.ts +++ b/src/lib/routes/admin-api/index.ts @@ -31,12 +31,10 @@ class AdminApi extends Controller { this.app.get('/', this.index); - if (!config.disableLegacyFeaturesApi) { - this.app.use( - '/features', - new FeatureController(config, services).router, - ); - } + this.app.use( + '/features', + new FeatureController(config, services).router, + ); this.app.use( '/feature-types', diff --git a/src/test/e2e/api/admin/feature.e2e.test.ts b/src/test/e2e/api/admin/feature.e2e.test.ts index a8a2182130..1550ce0516 100644 --- a/src/test/e2e/api/admin/feature.e2e.test.ts +++ b/src/test/e2e/api/admin/feature.e2e.test.ts @@ -697,8 +697,51 @@ test('should not hit endpoints if disable configuration is set', async () => { .get('/api/admin/features') .expect(404); - return appWithDisabledLegacyFeatures.request + await appWithDisabledLegacyFeatures.request .get('/api/admin/features/featureX') .expect('Content-Type', /json/) .expect(404); + + await appWithDisabledLegacyFeatures.request + .post(`/api/admin/features/featureZ/stale/on`) + .set('Content-Type', 'application/json') + .expect(404); +}); + +test('should hit stale and tags endpoint if legacy api is disabled', async () => { + const appWithDisabledLegacyFeatures = await setupAppWithCustomConfig( + db.stores, + { + disableLegacyFeaturesApi: true, + }, + ); + + const feature = { + name: 'test.feature.disabled.api', + type: 'killswitch', + }; + + await appWithDisabledLegacyFeatures.request + .post('/api/admin/projects/default/features') + .send(feature); + + await appWithDisabledLegacyFeatures.request + .post(`/api/admin/features/${feature.name}/tags`) + .send({ + value: 'TeamGreen', + type: 'simple', + }) + .set('Content-Type', 'application/json'); + + await appWithDisabledLegacyFeatures.request + .get(`/api/admin/features/${feature.name}/tags`) + .expect((res) => { + console.log(res.body); + expect(res.body.tags[0].value).toBe('TeamGreen'); + }); + + await appWithDisabledLegacyFeatures.request + .post('/api/admin/features/validate') + .send({ name: 'validateThis' }) + .expect(200); });