mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: enable tags and validate for legacy api (#1264)
* fix: enable tags and validate for legacy api * fix: move delete tag * fix: test name * fix: move /api/admin/features
This commit is contained in:
		
							parent
							
								
									c1826ca79a
								
							
						
					
					
						commit
						1989c53fb0
					
				| @ -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( | ||||
|  | ||||
| @ -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', | ||||
|  | ||||
| @ -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); | ||||
| }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user