mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: Added feature toggle variants
This commit is contained in:
		
							parent
							
								
									e459d33bea
								
							
						
					
					
						commit
						8c12ead2ae
					
				| @ -24,6 +24,14 @@ This endpoint is the one all admin ui should use to fetch all available feature | ||||
|           "name": "default", | ||||
|           "parameters": {} | ||||
|         } | ||||
|       ], | ||||
|       "variants": [ | ||||
|         { | ||||
|           "name": "variant1", | ||||
|         }, | ||||
|         { | ||||
|           "name": "variant2", | ||||
|         } | ||||
|       ] | ||||
|     }, | ||||
|     { | ||||
| @ -43,7 +51,8 @@ This endpoint is the one all admin ui should use to fetch all available feature | ||||
|             "percentage": "10" | ||||
|           } | ||||
|         } | ||||
|       ] | ||||
|       ], | ||||
|       "variants": [] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| @ -63,7 +72,8 @@ Used to fetch details about a specific featureToggle. This is mostly provded to | ||||
|       "name": "default", | ||||
|       "parameters": {} | ||||
|     } | ||||
|   ] | ||||
|   ], | ||||
|   "variants": [] | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| @ -107,7 +117,8 @@ Returns 200-respose if the feature toggle was created successfully. | ||||
|       "name": "default", | ||||
|       "parameters": {} | ||||
|     } | ||||
|   ] | ||||
|   ], | ||||
|   "variants": [] | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| @ -145,6 +156,7 @@ Used to fetch list of archived feature toggles | ||||
|           "parameters": {} | ||||
|         } | ||||
|       ], | ||||
|       "variants": [], | ||||
|       "strategy": "default", | ||||
|       "parameters": {} | ||||
|     } | ||||
|  | ||||
| @ -13,6 +13,7 @@ const FEATURE_COLUMNS = [ | ||||
|     'description', | ||||
|     'enabled', | ||||
|     'strategies', | ||||
|     'variants', | ||||
|     'created_at', | ||||
| ]; | ||||
| const TABLE = 'features'; | ||||
| @ -85,6 +86,7 @@ class FeatureToggleStore { | ||||
|             description: row.description, | ||||
|             enabled: row.enabled > 0, | ||||
|             strategies: row.strategies, | ||||
|             variants: row.variants, | ||||
|             createdAt: row.created_at, | ||||
|         }; | ||||
|     } | ||||
| @ -96,6 +98,7 @@ class FeatureToggleStore { | ||||
|             enabled: data.enabled ? 1 : 0, | ||||
|             archived: data.archived ? 1 : 0, | ||||
|             strategies: JSON.stringify(data.strategies), | ||||
|             variants: data.variants ? JSON.stringify(data.variants) : null, | ||||
|             created_at: data.createdAt, // eslint-disable-line
 | ||||
|         }; | ||||
|     } | ||||
|  | ||||
| @ -18,7 +18,7 @@ const DEFAULT_OPTIONS = { | ||||
|     enableRequestLogger: isDev(), | ||||
|     secret: 'UNLEASH-SECRET', | ||||
|     sessionAge: THIRTY_DAYS, | ||||
|     adminAuthentication: 'unsecure', | ||||
|     adminAuthentication: 'none', | ||||
| }; | ||||
| 
 | ||||
| module.exports = { | ||||
|  | ||||
| @ -10,6 +10,11 @@ const strategiesSchema = joi.object().keys({ | ||||
|     parameters: joi.object(), | ||||
| }); | ||||
| 
 | ||||
| const variantsSchema = joi.object().keys({ | ||||
|     name: nameType, | ||||
|     percentage: joi.number(), | ||||
| }); | ||||
| 
 | ||||
| const featureShema = joi | ||||
|     .object() | ||||
|     .keys({ | ||||
| @ -21,6 +26,10 @@ const featureShema = joi | ||||
|             .required() | ||||
|             .min(1) | ||||
|             .items(strategiesSchema), | ||||
|         variants: joi | ||||
|             .array() | ||||
|             .optional() | ||||
|             .items(variantsSchema), | ||||
|     }) | ||||
|     .options({ allowUnknown: false, stripUnknown: true }); | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										15
									
								
								migrations/20190123204125-add-variants-to-features.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								migrations/20190123204125-add-variants-to-features.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| exports.up = function(db, callback) { | ||||
|     db.runSql( | ||||
|         ` | ||||
|         ALTER TABLE features ADD "variants" json; | ||||
|         ALTER TABLE features ALTER COLUMN "variants" SET DEFAULT '[]'; | ||||
|     `,
 | ||||
|         callback | ||||
|     ); | ||||
| }; | ||||
| 
 | ||||
| exports.down = function(db, callback) { | ||||
|     db.runSql(`ALTER TABLE features DROP COLUMN "variants";`, callback); | ||||
| }; | ||||
| @ -50,6 +50,26 @@ test.serial('creates new feature toggle', async t => { | ||||
|         .then(destroy); | ||||
| }); | ||||
| 
 | ||||
| test.serial('creates new feature toggle with variants', async t => { | ||||
|     t.plan(1); | ||||
|     const { request, destroy } = await setupApp('feature_api_serial'); | ||||
|     await request | ||||
|         .post('/api/admin/features') | ||||
|         .send({ | ||||
|             name: 'com.test.variants', | ||||
|             enabled: false, | ||||
|             strategies: [{ name: 'default' }], | ||||
|             variants: [{ name: 'variant1' }, { name: 'variant2' }], | ||||
|         }) | ||||
|         .set('Content-Type', 'application/json'); | ||||
|     await request | ||||
|         .get('/api/admin/features/com.test.variants') | ||||
|         .expect(res => { | ||||
|             t.true(res.body.variants.length === 2); | ||||
|         }) | ||||
|         .then(destroy); | ||||
| }); | ||||
| 
 | ||||
| test.serial('creates new feature toggle with createdBy unknown', async t => { | ||||
|     t.plan(1); | ||||
|     const { request, destroy } = await setupApp('feature_api_serial'); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user