mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: Update variant protocol
This commit is contained in:
		
							parent
							
								
									82bf748341
								
							
						
					
					
						commit
						c25e994322
					
				| @ -28,9 +28,11 @@ This endpoint is the one all admin ui should use to fetch all available feature | ||||
|       "variants": [ | ||||
|         { | ||||
|           "name": "variant1", | ||||
|           "weight": 50 | ||||
|         }, | ||||
|         { | ||||
|           "name": "variant2", | ||||
|           "weight": 50 | ||||
|         } | ||||
|       ] | ||||
|     }, | ||||
|  | ||||
| @ -18,7 +18,7 @@ const DEFAULT_OPTIONS = { | ||||
|     enableRequestLogger: isDev(), | ||||
|     secret: 'UNLEASH-SECRET', | ||||
|     sessionAge: THIRTY_DAYS, | ||||
|     adminAuthentication: 'none', | ||||
|     adminAuthentication: 'unsecure', | ||||
| }; | ||||
| 
 | ||||
| module.exports = { | ||||
|  | ||||
| @ -12,7 +12,18 @@ const strategiesSchema = joi.object().keys({ | ||||
| 
 | ||||
| const variantsSchema = joi.object().keys({ | ||||
|     name: nameType, | ||||
|     percentage: joi.number(), | ||||
|     weight: joi | ||||
|         .number() | ||||
|         .min(0) | ||||
|         .max(100) | ||||
|         .required(), | ||||
|     payload: joi | ||||
|         .object() | ||||
|         .keys({ | ||||
|             type: joi.string().required(), | ||||
|             value: joi.string().required(), | ||||
|         }) | ||||
|         .optional(), | ||||
| }); | ||||
| 
 | ||||
| const featureShema = joi | ||||
| @ -28,6 +39,7 @@ const featureShema = joi | ||||
|             .items(strategiesSchema), | ||||
|         variants: joi | ||||
|             .array() | ||||
|             .unique((a, b) => a.name === b.name) | ||||
|             .optional() | ||||
|             .items(variantsSchema), | ||||
|     }) | ||||
|  | ||||
| @ -241,22 +241,29 @@ test('invalid feature names should have error msg', t => { | ||||
| 
 | ||||
| test('should not allow variants with same name when creating feature flag', t => { | ||||
|     t.plan(0); | ||||
|     const { request, base } = getSetup(); | ||||
|     const { request, base, perms } = getSetup(); | ||||
|     perms.withPermissions(CREATE_FEATURE); | ||||
| 
 | ||||
|     return request | ||||
|         .post(`${base}/api/admin/features`) | ||||
|         .send({ | ||||
|             name: 'ts', | ||||
|             name: 't.variant', | ||||
|             enabled: true, | ||||
|             strategies: [{ name: 'default' }], | ||||
|             variants: [{ name: 'variant1' }, { name: 'variant1' }], | ||||
|             variants: [ | ||||
|                 { name: 'variant1', weight: 50 }, | ||||
|                 { name: 'variant1', weight: 50 }, | ||||
|             ], | ||||
|         }) | ||||
|         .set('Content-Type', 'application/json') | ||||
|         .expect(403); | ||||
|         .expect(400); | ||||
| }); | ||||
| 
 | ||||
| test('should not allow variants with same name when updating feature flag', t => { | ||||
|     t.plan(0); | ||||
|     const { request, featureToggleStore, base } = getSetup(); | ||||
|     const { request, featureToggleStore, base, perms } = getSetup(); | ||||
|     perms.withPermissions(UPDATE_FEATURE); | ||||
| 
 | ||||
|     featureToggleStore.addFeature({ | ||||
|         name: 'ts', | ||||
|         strategies: [{ name: 'default' }], | ||||
| @ -270,5 +277,5 @@ test('should not allow variants with same name when updating feature flag', t => | ||||
|             variants: [{ name: 'variant1' }, { name: 'variant1' }], | ||||
|         }) | ||||
|         .set('Content-Type', 'application/json') | ||||
|         .expect(403); | ||||
|         .expect(400); | ||||
| }); | ||||
|  | ||||
| @ -59,7 +59,10 @@ test.serial('creates new feature toggle with variants', async t => { | ||||
|             name: 'com.test.variants', | ||||
|             enabled: false, | ||||
|             strategies: [{ name: 'default' }], | ||||
|             variants: [{ name: 'variant1' }, { name: 'variant2' }], | ||||
|             variants: [ | ||||
|                 { name: 'variant1', weight: 50 }, | ||||
|                 { name: 'variant2', weight: 50 }, | ||||
|             ], | ||||
|         }) | ||||
|         .set('Content-Type', 'application/json') | ||||
|         .expect(201) | ||||
|  | ||||
| @ -127,7 +127,10 @@ | ||||
|       "enabled": true, | ||||
|       "archived": false, | ||||
|       "strategies": [{ "name": "default" }], | ||||
|       "variants": [{ "name": "control" }, { "name": "new" }] | ||||
|       "variants": [ | ||||
|         { "name": "control", "weight": 50 }, | ||||
|         { "name": "new", "weight": 50 } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user