mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: post global events even when filtering by env (#4672)
https://linear.app/unleash/issue/2-1276/deal-with-events-without-an-environment This makes it so that global events (events not tied to a specific environment) are always received, no matter the configured environment filter. It also includes a respective test and small sentence on the UI explaining the behavior. 
This commit is contained in:
		
							parent
							
								
									43878230b7
								
							
						
					
					
						commit
						4de8ea2553
					
				| @ -386,6 +386,7 @@ export const IntegrationForm: VFC<IntegrationFormProps> = ({ | |||||||
|                                 onChange={setEnvironments} |                                 onChange={setEnvironments} | ||||||
|                                 entityName="environment" |                                 entityName="environment" | ||||||
|                                 selectAllEnabled={true} |                                 selectAllEnabled={true} | ||||||
|  |                                 description="Global events that are not specific to an environment will still be received." | ||||||
|                             /> |                             /> | ||||||
|                         </div> |                         </div> | ||||||
|                     </StyledConfigurationSection> |                     </StyledConfigurationSection> | ||||||
|  | |||||||
| @ -154,14 +154,14 @@ export const IntegrationMultiSelector: VFC<IIntegrationMultiSelectorProps> = ({ | |||||||
|                     </Typography> |                     </Typography> | ||||||
|                 ) : null} |                 ) : null} | ||||||
|             </StyledTitle> |             </StyledTitle> | ||||||
|             <ConditionallyRender |  | ||||||
|                 condition={description !== undefined} |  | ||||||
|                 show={<StyledHelpText>{description}</StyledHelpText>} |  | ||||||
|             /> |  | ||||||
|             <ConditionallyRender |             <ConditionallyRender | ||||||
|                 condition={selectAllEnabled} |                 condition={selectAllEnabled} | ||||||
|                 show={<DefaultHelpText />} |                 show={<DefaultHelpText />} | ||||||
|             /> |             /> | ||||||
|  |             <ConditionallyRender | ||||||
|  |                 condition={description !== undefined} | ||||||
|  |                 show={<StyledHelpText>{description}</StyledHelpText>} | ||||||
|  |             /> | ||||||
|             <ConditionallyRender |             <ConditionallyRender | ||||||
|                 condition={selectAllEnabled} |                 condition={selectAllEnabled} | ||||||
|                 show={<SelectAllFormControl />} |                 show={<SelectAllFormControl />} | ||||||
|  | |||||||
| @ -292,6 +292,43 @@ test('should filter events on environment if addon is setup to filter for it', a | |||||||
|     expect(events[0].event.data.name).toBe('some-toggle'); |     expect(events[0].event.data.name).toBe('some-toggle'); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | test('should not filter out global events (no specific environment) even if addon is setup to filter for environments', async () => { | ||||||
|  |     const { addonService, stores } = getSetup(); | ||||||
|  |     const filteredEnvironment = 'filtered'; | ||||||
|  |     const config = { | ||||||
|  |         provider: 'simple', | ||||||
|  |         enabled: true, | ||||||
|  |         events: [FEATURE_CREATED], | ||||||
|  |         projects: [], | ||||||
|  |         environments: [filteredEnvironment], | ||||||
|  |         description: '', | ||||||
|  |         parameters: { | ||||||
|  |             url: 'http://localhost:wh', | ||||||
|  |         }, | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     const globalEventWithNoEnvironment = { | ||||||
|  |         type: FEATURE_CREATED, | ||||||
|  |         createdBy: 'some@user.com', | ||||||
|  |         project: 'some-project', | ||||||
|  |         data: { | ||||||
|  |             name: 'some-toggle', | ||||||
|  |             enabled: false, | ||||||
|  |             strategies: [{ name: 'default' }], | ||||||
|  |         }, | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     await addonService.createAddon(config, 'me@mail.com'); | ||||||
|  |     await stores.eventStore.store(globalEventWithNoEnvironment); | ||||||
|  |     const simpleProvider = addonService.addonProviders.simple; | ||||||
|  |     // @ts-expect-error
 | ||||||
|  |     const events = simpleProvider.getEvents(); | ||||||
|  | 
 | ||||||
|  |     expect(events.length).toBe(1); | ||||||
|  |     expect(events[0].event.type).toBe(FEATURE_CREATED); | ||||||
|  |     expect(events[0].event.data.name).toBe('some-toggle'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| test('should support wildcard option for filtering addons', async () => { | test('should support wildcard option for filtering addons', async () => { | ||||||
|     const { addonService, stores } = getSetup(); |     const { addonService, stores } = getSetup(); | ||||||
|     const desiredProjects = ['desired', 'desired2']; |     const desiredProjects = ['desired', 'desired2']; | ||||||
|  | |||||||
| @ -121,6 +121,7 @@ export default class AddonService { | |||||||
|                     ) |                     ) | ||||||
|                     .filter( |                     .filter( | ||||||
|                         (addon) => |                         (addon) => | ||||||
|  |                             !event.environment || | ||||||
|                             !addon.environments || |                             !addon.environments || | ||||||
|                             addon.environments.length == 0 || |                             addon.environments.length == 0 || | ||||||
|                             addon.environments[0] === WILDCARD_OPTION || |                             addon.environments[0] === WILDCARD_OPTION || | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user