-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...eatureOverviewEnvironments/FeatureOverviewEnvironment/FeatureOverviewEnvironment.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import FeatureOverviewEnvironment from './FeatureOverviewEnvironment'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { CREATE_FEATURE_STRATEGY } from 'component/providers/AccessProvider/permissions'; | ||
import type { IFeatureStrategy } from 'interfaces/strategy'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = () => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
resourceLimits: true, | ||
}, | ||
}); | ||
|
||
testServerRoute( | ||
server, | ||
'/api/admin/projects/default/features/featureWithoutStrategies', | ||
{ | ||
environments: [environmentWithoutStrategies], | ||
}, | ||
); | ||
|
||
testServerRoute( | ||
server, | ||
'/api/admin/projects/default/features/featureWithManyStrategies', | ||
{ | ||
environments: [environmentWithManyStrategies], | ||
}, | ||
); | ||
}; | ||
|
||
const strategy = { | ||
name: 'default', | ||
} as IFeatureStrategy; | ||
const environmentWithoutStrategies = { | ||
name: 'production', | ||
enabled: true, | ||
type: 'production', | ||
strategies: [], | ||
}; | ||
const environmentWithManyStrategies = { | ||
name: 'production', | ||
enabled: true, | ||
type: 'production', | ||
strategies: [...Array(30).keys()].map(() => strategy), | ||
}; | ||
|
||
test('should allow to add strategy when no strategies', async () => { | ||
setupApi(); | ||
render( | ||
<Routes> | ||
<Route | ||
path='/projects/:projectId/features/:featureId/strategies/create' | ||
element={ | ||
<FeatureOverviewEnvironment | ||
env={environmentWithoutStrategies} | ||
/> | ||
} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/features/featureWithoutStrategies/strategies/create', | ||
permissions: [{ permission: CREATE_FEATURE_STRATEGY }], | ||
}, | ||
); | ||
|
||
const button = await screen.findByText('Add strategy'); | ||
expect(button).toBeEnabled(); | ||
}); | ||
|
||
test('should not allow to add strategy when limit reached', async () => { | ||
setupApi(); | ||
render( | ||
<Routes> | ||
<Route | ||
path='/projects/:projectId/features/:featureId/strategies/create' | ||
element={ | ||
<FeatureOverviewEnvironment | ||
env={environmentWithManyStrategies} | ||
/> | ||
} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/features/featureWithManyStrategies/strategies/create', | ||
permissions: [{ permission: CREATE_FEATURE_STRATEGY }], | ||
}, | ||
); | ||
|
||
await waitFor(async () => { | ||
const button = await screen.findByText('Add strategy'); | ||
expect(button).toBeDisabled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/lib/features/feature-toggle/tests/feature-toggle-service.limit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createFakeFeatureToggleService } from '../createFeatureToggleService'; | ||
import type { | ||
IAuditUser, | ||
IFlagResolver, | ||
IStrategyConfig, | ||
IUnleashConfig, | ||
} from '../../../types'; | ||
import getLogger from '../../../../test/fixtures/no-logger'; | ||
|
||
const alwaysOnFlagResolver = { | ||
isEnabled() { | ||
return true; | ||
}, | ||
} as unknown as IFlagResolver; | ||
|
||
test('Should not allow to exceed strategy limit', async () => { | ||
const { featureToggleService, featureToggleStore } = | ||
createFakeFeatureToggleService({ | ||
getLogger, | ||
flagResolver: alwaysOnFlagResolver, | ||
} as unknown as IUnleashConfig); | ||
|
||
const addStrategy = () => | ||
featureToggleService.unprotectedCreateStrategy( | ||
{ name: 'default', featureName: 'feature' } as IStrategyConfig, | ||
{ projectId: 'default', featureName: 'feature' } as any, | ||
{} as IAuditUser, | ||
); | ||
await featureToggleStore.create('default', { | ||
name: 'feature', | ||
createdByUserId: 1, | ||
}); | ||
|
||
for (let i = 0; i < 30; i++) { | ||
await addStrategy(); | ||
} | ||
|
||
await expect(addStrategy()).rejects.toThrow( | ||
'Strategy limit of 30 exceeded', | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters