mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: remove fields from /api/client/features respnse (#692)
This commit is contained in:
		
							parent
							
								
									f850986b9c
								
							
						
					
					
						commit
						f5aa5b577c
					
				| @ -1,5 +1,9 @@ | |||||||
| # Changelog | # Changelog | ||||||
| 
 | 
 | ||||||
|  | ## 3.10.1 | ||||||
|  | 
 | ||||||
|  | - fix: remove fields from /api/client/features respnse (#692) | ||||||
|  | 
 | ||||||
| ## 3.10.0 | ## 3.10.0 | ||||||
| 
 | 
 | ||||||
| - feat: add tags (#655) | - feat: add tags (#655) | ||||||
| @ -11,7 +15,6 @@ | |||||||
| - fix: Updated docs about event-types (#684) | - fix: Updated docs about event-types (#684) | ||||||
| - fix: Add application-created event (#595) | - fix: Add application-created event (#595) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| ## 3.9.0 | ## 3.9.0 | ||||||
| 
 | 
 | ||||||
| - fix: stateService undefined | - fix: stateService undefined | ||||||
|  | |||||||
| @ -18,6 +18,15 @@ const FEATURE_COLUMNS = [ | |||||||
| ]; | ]; | ||||||
| const TABLE = 'features'; | const TABLE = 'features'; | ||||||
| 
 | 
 | ||||||
|  | const FEATURE_COLUMNS_CLIENT = [ | ||||||
|  |     'name', | ||||||
|  |     'type', | ||||||
|  |     'enabled', | ||||||
|  |     'stale', | ||||||
|  |     'strategies', | ||||||
|  |     'variants', | ||||||
|  | ]; | ||||||
|  | 
 | ||||||
| class FeatureToggleStore { | class FeatureToggleStore { | ||||||
|     constructor(db, eventBus, getLogger) { |     constructor(db, eventBus, getLogger) { | ||||||
|         this.db = db; |         this.db = db; | ||||||
| @ -43,6 +52,34 @@ class FeatureToggleStore { | |||||||
|         return rows.map(this.rowToFeature); |         return rows.map(this.rowToFeature); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     async getFeaturesClient() { | ||||||
|  |         const stopTimer = this.timer('getAllClient'); | ||||||
|  | 
 | ||||||
|  |         const rows = await this.db | ||||||
|  |             .select(FEATURE_COLUMNS_CLIENT) | ||||||
|  |             .from(TABLE) | ||||||
|  |             .where({ archived: 0 }) | ||||||
|  |             .orderBy('name', 'asc'); | ||||||
|  | 
 | ||||||
|  |         stopTimer(); | ||||||
|  | 
 | ||||||
|  |         return rows.map(this.rowToFeature); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async getClientFeatures() { | ||||||
|  |         const stopTimer = this.timer('getAll'); | ||||||
|  | 
 | ||||||
|  |         const rows = await this.db | ||||||
|  |             .select(FEATURE_COLUMNS) | ||||||
|  |             .from(TABLE) | ||||||
|  |             .where({ archived: 0 }) | ||||||
|  |             .orderBy('name', 'asc'); | ||||||
|  | 
 | ||||||
|  |         stopTimer(); | ||||||
|  | 
 | ||||||
|  |         return rows.map(this.rowToFeature); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     async getFeaturesBy(fields) { |     async getFeaturesBy(fields) { | ||||||
|         const rows = await this.db |         const rows = await this.db | ||||||
|             .select(FEATURE_COLUMNS) |             .select(FEATURE_COLUMNS) | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ class FeatureController extends Controller { | |||||||
|     async getAll(req, res) { |     async getAll(req, res) { | ||||||
|         const nameFilter = filter('name', req.query.namePrefix); |         const nameFilter = filter('name', req.query.namePrefix); | ||||||
| 
 | 
 | ||||||
|         const allFeatureToggles = await this.toggleService.getFeatures(); |         const allFeatureToggles = await this.toggleService.getFeaturesClient(); | ||||||
|         const features = nameFilter(allFeatureToggles); |         const features = nameFilter(allFeatureToggles); | ||||||
| 
 | 
 | ||||||
|         res.json({ version, features }); |         res.json({ version, features }); | ||||||
|  | |||||||
| @ -27,6 +27,10 @@ class FeatureToggleService { | |||||||
|         return this.featureToggleStore.getFeatures(); |         return this.featureToggleStore.getFeatures(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     async getFeaturesClient() { | ||||||
|  |         return this.featureToggleStore.getFeaturesClient(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     async getArchivedFeatures() { |     async getArchivedFeatures() { | ||||||
|         return this.featureToggleStore.getArchivedFeatures(); |         return this.featureToggleStore.getArchivedFeatures(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -23,7 +23,18 @@ test.serial('returns four feature toggles', async t => { | |||||||
|         .expect('Content-Type', /json/) |         .expect('Content-Type', /json/) | ||||||
|         .expect(200) |         .expect(200) | ||||||
|         .expect(res => { |         .expect(res => { | ||||||
|             t.true(res.body.features.length === 4); |             t.is(res.body.features.length, 4); | ||||||
|  |         }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test.serial('returns four feature toggles without createdAt', async t => { | ||||||
|  |     const request = await setupApp(stores); | ||||||
|  |     return request | ||||||
|  |         .get('/api/client/features') | ||||||
|  |         .expect('Content-Type', /json/) | ||||||
|  |         .expect(200) | ||||||
|  |         .expect(res => { | ||||||
|  |             t.falsy(res.body.features[0].createdAt); | ||||||
|         }); |         }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								test/fixtures/fake-feature-toggle-store.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								test/fixtures/fake-feature-toggle-store.js
									
									
									
									
										vendored
									
									
								
							| @ -30,6 +30,7 @@ module.exports = () => { | |||||||
|             _features.push(updatedFeature); |             _features.push(updatedFeature); | ||||||
|         }, |         }, | ||||||
|         getFeatures: () => Promise.resolve(_features), |         getFeatures: () => Promise.resolve(_features), | ||||||
|  |         getFeaturesClient: () => Promise.resolve(_features), | ||||||
|         createFeature: feature => _features.push(feature), |         createFeature: feature => _features.push(feature), | ||||||
|         getArchivedFeatures: () => Promise.resolve(_archive), |         getArchivedFeatures: () => Promise.resolve(_archive), | ||||||
|         addArchivedFeature: feature => _archive.push(feature), |         addArchivedFeature: feature => _archive.push(feature), | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user