mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: add sort order to environments (#1004)
* fix: add sort order to environments * fix: lint * fix: remove display name
This commit is contained in:
		
							parent
							
								
									a401580228
								
							
						
					
					
						commit
						12245664ad
					
				| @ -351,7 +351,14 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore { | ||||
|             }, {}); | ||||
|             return Object.values(overview).map((o: IFeatureOverview) => ({ | ||||
|                 ...o, | ||||
|                 environments: o.environments.filter((f) => f.name), | ||||
|                 environments: o.environments | ||||
|                     .filter((f) => f.name) | ||||
|                     .sort((a, b) => { | ||||
|                         if (a.sortOrder === b.sortOrder) { | ||||
|                             return a.name.localeCompare(b.name); | ||||
|                         } | ||||
|                         return a.sortOrder - b.sortOrder; | ||||
|                     }), | ||||
|             })); | ||||
|         } | ||||
|         return []; | ||||
|  | ||||
| @ -155,3 +155,90 @@ test('Health report for non-existing project yields 404', async () => { | ||||
|         .get('/api/admin/projects/some-crazy-project-name/health-report') | ||||
|         .expect(404); | ||||
| }); | ||||
| 
 | ||||
| test('Sorts environments by sort order', async () => { | ||||
|     const envOne = 'my-sorted-env1'; | ||||
|     const envTwo = 'my-sorted-env2'; | ||||
|     const featureName = 'My-new-toggle'; | ||||
|     const defaultEnvName = 'default'; | ||||
|     await db.stores.environmentStore.create({ | ||||
|         name: envOne, | ||||
|         type: 'production', | ||||
|         sortOrder: 0, | ||||
|     }); | ||||
| 
 | ||||
|     await db.stores.environmentStore.create({ | ||||
|         name: envTwo, | ||||
|         type: 'production', | ||||
|         sortOrder: 500, | ||||
|     }); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/environments') | ||||
|         .send({ | ||||
|             environment: envOne, | ||||
|         }) | ||||
|         .expect(200); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/environments') | ||||
|         .send({ | ||||
|             environment: envTwo, | ||||
|         }) | ||||
|         .expect(200); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/features') | ||||
|         .send({ name: featureName }) | ||||
|         .expect(201); | ||||
| 
 | ||||
|     await app.request.get('/api/admin/projects/default').expect((res) => { | ||||
|         const feature = res.body.features[0]; | ||||
|         expect(feature.environments[0].name).toBe(envOne); | ||||
|         expect(feature.environments[1].name).toBe(defaultEnvName); | ||||
|         expect(feature.environments[2].name).toBe(envTwo); | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| test('Sorts environments correctly if sort order is equal', async () => { | ||||
|     const envOne = 'my-sorted-env3'; | ||||
|     const envTwo = 'my-sorted-env4'; | ||||
|     const featureName = 'My-new-toggle-2'; | ||||
| 
 | ||||
|     await db.stores.environmentStore.create({ | ||||
|         name: envOne, | ||||
|         type: 'production', | ||||
|         sortOrder: -5, | ||||
|     }); | ||||
| 
 | ||||
|     await db.stores.environmentStore.create({ | ||||
|         name: envTwo, | ||||
|         type: 'production', | ||||
|         sortOrder: -5, | ||||
|     }); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/environments') | ||||
|         .send({ | ||||
|             environment: envOne, | ||||
|         }) | ||||
|         .expect(200); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/environments') | ||||
|         .send({ | ||||
|             environment: envTwo, | ||||
|         }) | ||||
|         .expect(200); | ||||
| 
 | ||||
|     await app.request | ||||
|         .post('/api/admin/projects/default/features') | ||||
|         .send({ name: featureName }) | ||||
|         .expect(201); | ||||
| 
 | ||||
|     await app.request.get('/api/admin/projects/default').expect((res) => { | ||||
|         const feature = res.body.features[0]; | ||||
|         expect(feature.environments[0].name).toBe(envOne); | ||||
|         expect(feature.environments[1].name).toBe(envTwo); | ||||
|     }); | ||||
| }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user