mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-17 01:17:29 +02:00
feat: show archived toggles on a project level (#1555)
* feat: show archived toggles on a project level * refactor: split behaviour in 2 separate routes and methods for clarity * add e2e test
This commit is contained in:
parent
188352cb7a
commit
7e938a21b4
@ -42,6 +42,20 @@ export default class ArchiveController extends Controller {
|
||||
],
|
||||
});
|
||||
|
||||
this.route({
|
||||
method: 'get',
|
||||
path: '/features/:projectId',
|
||||
acceptAnyContentType: true,
|
||||
handler: this.getArchivedFeaturesByProjectId,
|
||||
middleware: [
|
||||
openApiService.validPath({
|
||||
tags: ['admin'],
|
||||
responses: { 200: featuresResponse },
|
||||
deprecated: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
this.delete('/:featureName', this.deleteFeature, DELETE_FEATURE);
|
||||
this.post(
|
||||
'/revive/:featureName',
|
||||
@ -60,6 +74,19 @@ export default class ArchiveController extends Controller {
|
||||
res.json({ version: 2, features });
|
||||
}
|
||||
|
||||
async getArchivedFeaturesByProjectId(
|
||||
req: Request<{ projectId: string }, any, any, any>,
|
||||
res: Response<FeaturesSchema>,
|
||||
): Promise<void> {
|
||||
const { projectId } = req.params;
|
||||
const features =
|
||||
await this.featureService.getMetadataForAllFeaturesByProjectId(
|
||||
true,
|
||||
projectId,
|
||||
);
|
||||
res.json({ version: 2, features });
|
||||
}
|
||||
|
||||
async deleteFeature(
|
||||
req: IAuthRequest<any, { featureName: string }, any, any>,
|
||||
res: Response,
|
||||
|
@ -997,6 +997,13 @@ class FeatureToggleService {
|
||||
return this.featureToggleStore.getAll({ archived });
|
||||
}
|
||||
|
||||
async getMetadataForAllFeaturesByProjectId(
|
||||
archived: boolean,
|
||||
project: string,
|
||||
): Promise<FeatureToggle[]> {
|
||||
return this.featureToggleStore.getAll({ archived, project });
|
||||
}
|
||||
|
||||
async getProjectId(name: string): Promise<string> {
|
||||
return this.featureToggleStore.getProjectId(name);
|
||||
}
|
||||
|
@ -68,6 +68,58 @@ test('Should get archived toggles via admin', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Should get archived toggles via project', async () => {
|
||||
await db.stores.featureToggleStore.deleteAll();
|
||||
|
||||
await db.stores.projectStore.create({
|
||||
id: 'proj-1',
|
||||
name: 'proj-1',
|
||||
description: '',
|
||||
});
|
||||
await db.stores.projectStore.create({
|
||||
id: 'proj-2',
|
||||
name: 'proj-2',
|
||||
description: '',
|
||||
});
|
||||
|
||||
await db.stores.featureToggleStore.create('proj-1', {
|
||||
name: 'feat-proj-1',
|
||||
archived: true,
|
||||
});
|
||||
await db.stores.featureToggleStore.create('proj-2', {
|
||||
name: 'feat-proj-2',
|
||||
archived: true,
|
||||
});
|
||||
await db.stores.featureToggleStore.create('proj-2', {
|
||||
name: 'feat-proj-2-2',
|
||||
archived: true,
|
||||
});
|
||||
|
||||
await app.request
|
||||
.get('/api/admin/archive/features/proj-1')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
expect(res.body.features).toHaveLength(1);
|
||||
});
|
||||
|
||||
await app.request
|
||||
.get('/api/admin/archive/features/proj-2')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
expect(res.body.features).toHaveLength(2);
|
||||
});
|
||||
|
||||
await app.request
|
||||
.get('/api/admin/archive/features')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
expect(res.body.features).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
test('Should be able to revive toggle', async () => {
|
||||
await app.request.post('/api/admin/projects/default/features').send({
|
||||
name: 'archived.revival',
|
||||
|
Loading…
Reference in New Issue
Block a user