Skip to content

Commit

Permalink
feat: export all features in project
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Dec 18, 2023
1 parent 32533f1 commit 449a067
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,14 @@ export default class ExportImportService
featureNames = await this.featureTagService.listFeatures(query.tag);
} else if (Array.isArray(query.features) && query.features.length) {
featureNames = query.features;
} else if (typeof query.project === 'string') {
const allProjectFeatures = await this.toggleStore.getAll({
project: query.project,
});
featureNames = allProjectFeatures.map((feature) => feature.name);
} else {
const features = await this.toggleStore.getAll();
featureNames = features.map((feature) => feature.name);
const allFeatures = await this.toggleStore.getAll();
featureNames = allFeatures.map((feature) => feature.name);
}

const [
Expand Down
33 changes: 33 additions & 0 deletions src/lib/features/export-import-toggles/export-import.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,39 @@ test('returns all features, when no explicit feature was requested', async () =>
expect(body.features).toHaveLength(2);
});

test('returns all project features', async () => {
await createProjects();
await createToggle({
name: defaultFeatureName,
description: 'the #1 feature',
});
await createToggle({
name: 'second_feature',
description: 'the #1 feature',
});
const { body } = await app.request
.post('/api/admin/features-batch/export')
.send({
environment: 'default',
project: DEFAULT_PROJECT,
})
.set('Content-Type', 'application/json')
.expect(200);

expect(body.features).toHaveLength(2);

const { body: otherProject } = await app.request
.post('/api/admin/features-batch/export')
.send({
environment: 'default',
project: 'other_project',
})
.set('Content-Type', 'application/json')
.expect(200);

expect(otherProject.features).toHaveLength(0);
});

const variants: VariantsSchema = [
{
name: 'variantA',
Expand Down
13 changes: 12 additions & 1 deletion src/lib/openapi/spec/export-query-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@ export const exportQuerySchema = {
tag: {
type: 'string',
example: 'release',
description: 'Selects features to export by tag.',
},
},
},
{
required: ['environment', 'project'],
properties: {
...commonProps,
project: {
type: 'string',
example: 'my-project',
description:
'Selects features to export by tag. Takes precedence over the features field.',
'Selects project to export the features from. Used when no tags or features are provided.',
},
},
},
Expand Down

0 comments on commit 449a067

Please sign in to comment.