diff --git a/src/lib/features/feature-search/feature.search.e2e.test.ts b/src/lib/features/feature-search/feature.search.e2e.test.ts index 47a1e15f00..e2c26876d7 100644 --- a/src/lib/features/feature-search/feature.search.e2e.test.ts +++ b/src/lib/features/feature-search/feature.search.e2e.test.ts @@ -244,11 +244,11 @@ test('should filter features by type', async () => { }); await app.createFeature({ name: 'my_feature_b', - type: 'experimental', + type: 'experiment', }); const { body } = await filterFeaturesByType( - 'IS_ANY_OF:experimental,kill-switch', + 'IS_ANY_OF:experiment,kill-switch', ); expect(body).toMatchObject({ @@ -263,7 +263,7 @@ test('should filter features by created by', async () => { }); await app.createFeature({ name: 'my_feature_b', - type: 'experimental', + type: 'experiment', }); const { body } = await filterFeaturesByCreatedBy('IS:1'); diff --git a/src/lib/features/feature-toggle/tests/feature-toggles.e2e.test.ts b/src/lib/features/feature-toggle/tests/feature-toggles.e2e.test.ts index 5a36f84090..59df6653d6 100644 --- a/src/lib/features/feature-toggle/tests/feature-toggles.e2e.test.ts +++ b/src/lib/features/feature-toggle/tests/feature-toggles.e2e.test.ts @@ -2030,7 +2030,7 @@ test('should clone feature flag without strategies', async () => { const envName = 'some-env-3'; const featureName = 'feature.flag.base'; const cloneName = 'feature.flag.clone'; - const type = 'eExperiment'; + const type = 'experiment'; const description = 'Lorem ipsum...'; // Create environment @@ -2069,7 +2069,7 @@ test('should clone feature flag WITH strategies', async () => { const envName = 'some-env-4'; const featureName = 'feature.flag.base.2'; const cloneName = 'feature.flag.clone.2'; - const type = 'eExperiment'; + const type = 'experiment'; const description = 'Lorem ipsum...'; // Create environment @@ -2124,7 +2124,7 @@ test('should clone feature flag WITH variants', async () => { const envName = 'some-env-5'; const featureName = 'feature.flag.base.3'; const cloneName = 'feature.flag.clone.3'; - const type = 'eExperiment'; + const type = 'experiment'; const description = 'Lorem ipsum...'; const variants = [ { name: 'variant1', weight: 50 }, @@ -2211,7 +2211,7 @@ test('should clone feature flag without replacing groupId', async () => { test('should clone feature flag WITHOUT createdAt field', async () => { const featureName = 'feature.flag.base.5'; const cloneName = 'feature.flag.clone.5'; - const type = 'eExperiment'; + const type = 'experiment'; const description = 'Lorem ipsum...'; const originalCreatedAt = new Date(2011, 11, 11); @@ -3707,3 +3707,13 @@ test('can get evaluation metrics', async () => { ], }); }); + +test("Should not be able to create flag with a type that doesn't exist", async () => { + await app.request + .post('/api/admin/projects/default/features') + .send({ + type: 'random', + name: 'random.type.flag', + }) + .expect(400); +}); diff --git a/src/lib/features/project/projects.e2e.test.ts b/src/lib/features/project/projects.e2e.test.ts index e195bbfdfd..d9cd40ea6d 100644 --- a/src/lib/features/project/projects.e2e.test.ts +++ b/src/lib/features/project/projects.e2e.test.ts @@ -150,7 +150,7 @@ test('response for project overview should include feature type counts', async ( }); await app.createFeature({ name: 'my-new-development-toggle', - type: 'development', + type: 'experiment', }); const { body } = await app.request .get('/api/admin/projects/default/overview') @@ -159,7 +159,7 @@ test('response for project overview should include feature type counts', async ( expect(body).toMatchObject({ featureTypeCounts: [ { - type: 'development', + type: 'experiment', count: 1, }, { diff --git a/src/lib/openapi/spec/create-feature-schema.ts b/src/lib/openapi/spec/create-feature-schema.ts index 74a92a4460..9b21d10264 100644 --- a/src/lib/openapi/spec/create-feature-schema.ts +++ b/src/lib/openapi/spec/create-feature-schema.ts @@ -13,7 +13,13 @@ export const createFeatureSchema = { description: 'Unique feature name', }, type: { - type: 'string', + enum: [ + 'experiment', + 'kill-switch', + 'release', + 'operational', + 'permission', + ], example: 'release', description: "The feature flag's [type](https://docs.getunleash.io/reference/feature-toggle-types). One of experiment, kill-switch, release, operational, or permission", diff --git a/src/lib/openapi/spec/update-feature-schema.ts b/src/lib/openapi/spec/update-feature-schema.ts index 13a0e5a087..ecaae0f9f7 100644 --- a/src/lib/openapi/spec/update-feature-schema.ts +++ b/src/lib/openapi/spec/update-feature-schema.ts @@ -13,7 +13,13 @@ export const updateFeatureSchema = { description: 'Detailed description of the feature', }, type: { - type: 'string', + enum: [ + 'experiment', + 'kill-switch', + 'release', + 'operational', + 'permission', + ], example: 'kill-switch', description: 'Type of the flag e.g. experiment, kill-switch, release, operational, permission', diff --git a/src/test/e2e/api/admin/tags.e2e.test.ts b/src/test/e2e/api/admin/tags.e2e.test.ts index a98b95e206..fb5f08428c 100644 --- a/src/test/e2e/api/admin/tags.e2e.test.ts +++ b/src/test/e2e/api/admin/tags.e2e.test.ts @@ -125,7 +125,7 @@ test('Can tag features', async () => { }; await app.request.post('/api/admin/projects/default/features').send({ name: featureName, - type: 'killswitch', + type: 'kill-switch', enabled: true, strategies: [{ name: 'default' }], }); @@ -141,7 +141,7 @@ test('Can tag features', async () => { await app.request.post('/api/admin/projects/default/features').send({ name: featureName2, - type: 'killswitch', + type: 'kill-switch', enabled: true, strategies: [{ name: 'default' }], }); @@ -175,17 +175,20 @@ test('Can bulk remove tags', async () => { await app.request.post('/api/admin/projects/default/features').send({ name: featureName, - type: 'killswitch', + type: 'kill-switch', enabled: true, strategies: [{ name: 'default' }], }); - await app.request.post('/api/admin/projects/default/features').send({ - name: featureName2, - type: 'killswitch', - enabled: true, - strategies: [{ name: 'default' }], - }); + await app.request + .post('/api/admin/projects/default/features') + .send({ + name: featureName2, + type: 'kill-switch', + enabled: true, + strategies: [{ name: 'default' }], + }) + .expect(201); await app.request .put('/api/admin/projects/default/tags') diff --git a/src/test/e2e/api/client/feature.e2e.test.ts b/src/test/e2e/api/client/feature.e2e.test.ts index 38bd9aec8c..578dccb4f6 100644 --- a/src/test/e2e/api/client/feature.e2e.test.ts +++ b/src/test/e2e/api/client/feature.e2e.test.ts @@ -224,7 +224,7 @@ test('Can get strategies for specific environment', async () => { // Create feature flag await app.request.post('/api/admin/projects/default/features').send({ name: featureName, - type: 'killswitch', + type: 'kill-switch', }); // Add global strategy @@ -277,13 +277,13 @@ test('Can use multiple filters', async () => { await app.request.post('/api/admin/projects/default/features').send({ name: 'test.feature', - type: 'killswitch', + type: 'kill-switch', enabled: true, strategies: [{ name: 'default' }], }); await app.request.post('/api/admin/projects/default/features').send({ name: 'test.feature2', - type: 'killswitch', + type: 'kill-switch', enabled: true, strategies: [{ name: 'default' }], }); @@ -367,7 +367,7 @@ test('Can add tags while creating feature flag', async () => { await app.request.post('/api/admin/projects/default/features').send({ name: featureName, - type: 'killswitch', + type: 'kill-switch', tags, });