mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	Fix error and add test (#1825)
Co-authored-by: sjaanus <sellinjaanus@gmail.com>
This commit is contained in:
		
							parent
							
								
									d89d8c0d0e
								
							
						
					
					
						commit
						9e7f05fb35
					
				| @ -100,7 +100,7 @@ export default class FeatureToggleClientStore | |||||||
|                 'fe.feature_name', |                 'fe.feature_name', | ||||||
|                 'features.name', |                 'features.name', | ||||||
|             ) |             ) | ||||||
|             .fullOuterJoin( |             .leftJoin( | ||||||
|                 'feature_strategy_segment as fss', |                 'feature_strategy_segment as fss', | ||||||
|                 `fss.feature_strategy_id`, |                 `fss.feature_strategy_id`, | ||||||
|                 `fs.id`, |                 `fs.id`, | ||||||
|  | |||||||
| @ -4,10 +4,21 @@ import dbInit from '../helpers/database-init'; | |||||||
| import { DEFAULT_ENV } from '../../../lib/util/constants'; | import { DEFAULT_ENV } from '../../../lib/util/constants'; | ||||||
| import { SegmentService } from '../../../lib/services/segment-service'; | import { SegmentService } from '../../../lib/services/segment-service'; | ||||||
| import { FeatureStrategySchema } from '../../../lib/openapi/spec/feature-strategy-schema'; | import { FeatureStrategySchema } from '../../../lib/openapi/spec/feature-strategy-schema'; | ||||||
|  | import User from '../../../lib/types/user'; | ||||||
|  | import { IConstraint } from '../../../lib/types/model'; | ||||||
| 
 | 
 | ||||||
| let stores; | let stores; | ||||||
| let db; | let db; | ||||||
| let service: FeatureToggleService; | let service: FeatureToggleService; | ||||||
|  | let segmentService: SegmentService; | ||||||
|  | 
 | ||||||
|  | const mockConstraints = (): IConstraint[] => { | ||||||
|  |     return Array.from({ length: 5 }).map(() => ({ | ||||||
|  |         values: ['x', 'y', 'z'], | ||||||
|  |         operator: 'IN', | ||||||
|  |         contextName: 'a', | ||||||
|  |     })); | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| beforeAll(async () => { | beforeAll(async () => { | ||||||
|     const config = createTestConfig(); |     const config = createTestConfig(); | ||||||
| @ -16,11 +27,8 @@ beforeAll(async () => { | |||||||
|         config.getLogger, |         config.getLogger, | ||||||
|     ); |     ); | ||||||
|     stores = db.stores; |     stores = db.stores; | ||||||
|     service = new FeatureToggleService( |     segmentService = new SegmentService(stores, config); | ||||||
|         stores, |     service = new FeatureToggleService(stores, config, segmentService); | ||||||
|         config, |  | ||||||
|         new SegmentService(stores, config), |  | ||||||
|     ); |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| afterAll(async () => { | afterAll(async () => { | ||||||
| @ -152,3 +160,40 @@ test('should ignore name in the body when updating feature toggle', async () => | |||||||
|     expect(featureOne.description).toBe(`I'm changed`); |     expect(featureOne.description).toBe(`I'm changed`); | ||||||
|     expect(featureTwo.description).toBe('Second toggle'); |     expect(featureTwo.description).toBe('Second toggle'); | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | test('should not get empty rows as features', async () => { | ||||||
|  |     const projectId = 'default'; | ||||||
|  | 
 | ||||||
|  |     const userName = 'strategy'; | ||||||
|  | 
 | ||||||
|  |     await service.createFeatureToggle( | ||||||
|  |         projectId, | ||||||
|  |         { | ||||||
|  |             name: 'linked-with-segment', | ||||||
|  |             description: 'First toggle', | ||||||
|  |         }, | ||||||
|  |         userName, | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     await service.createFeatureToggle( | ||||||
|  |         projectId, | ||||||
|  |         { | ||||||
|  |             name: 'not-linked-with-segment', | ||||||
|  |             description: 'Second toggle', | ||||||
|  |         }, | ||||||
|  |         userName, | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     const user = { email: 'test@example.com' } as User; | ||||||
|  |     const postData = { | ||||||
|  |         name: 'Unlinked segment', | ||||||
|  |         constraints: mockConstraints(), | ||||||
|  |     }; | ||||||
|  |     await segmentService.create(postData, user); | ||||||
|  | 
 | ||||||
|  |     const features = await service.getClientFeatures(); | ||||||
|  |     const namelessFeature = features.find((p) => !p.name); | ||||||
|  | 
 | ||||||
|  |     expect(features.length).toBe(7); | ||||||
|  |     expect(namelessFeature).toBeUndefined(); | ||||||
|  | }); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user