Skip to content

Commit

Permalink
fix: enable tags and validate for legacy api (#1264)
Browse files Browse the repository at this point in the history
* fix: enable tags and validate for legacy api

* fix: move delete tag

* fix: test name

* fix: move /api/admin/features
  • Loading branch information
FredrikOseberg committed Jan 14, 2022
1 parent c1826ca commit 1989c53
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
26 changes: 17 additions & 9 deletions src/lib/routes/admin-api/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,25 @@ class FeatureController extends Controller {
this.tagService = featureTagService;
this.service = featureToggleServiceV2;

if (!config.disableLegacyFeaturesApi) {
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.post('/:featureName/stale/on', this.staleOn, UPDATE_FEATURE);
this.post('/:featureName/stale/off', this.staleOff, UPDATE_FEATURE);
}

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('/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(
Expand Down
10 changes: 4 additions & 6 deletions src/lib/routes/admin-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
60 changes: 56 additions & 4 deletions src/test/e2e/api/admin/feature.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,63 @@ test('should not hit endpoints if disable configuration is set', async () => {
);

await appWithDisabledLegacyFeatures.request
.get('/api/admin/features')
.expect(404);

return 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 validate 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);
});

test('should have access to the get all features endpoint even if api is disabled', async () => {
const appWithDisabledLegacyFeatures = await setupAppWithCustomConfig(
db.stores,
{
disableLegacyFeaturesApi: true,
},
);

await appWithDisabledLegacyFeatures.request
.get('/api/admin/features')
.expect(200);
});

1 comment on commit 1989c53

@vercel
Copy link

@vercel vercel bot commented on 1989c53 Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.