1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

fix: enable tags and validate for legacy api

This commit is contained in:
Fredrik Oseberg 2022-01-13 12:37:15 +01:00
parent 5696b0fff7
commit 9c83572eb4
3 changed files with 71 additions and 22 deletions

View File

@ -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

View File

@ -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',

View File

@ -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);
});