mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
test: default strategy stickiness (#4341)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
## About the changes
Unit tests for the default strategy and fallback strategy
### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->
## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
This commit is contained in:
parent
55148eb549
commit
55aa15d96d
@ -0,0 +1,55 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { render } from 'utils/testRenderer';
|
||||
import React from 'react';
|
||||
import { useDefaultStrategy } from './EditDefaultStrategy';
|
||||
import { testServerRoute, testServerSetup } from 'utils/testServer';
|
||||
|
||||
const server = testServerSetup();
|
||||
|
||||
const RenderStrategy = () => {
|
||||
const { strategy } = useDefaultStrategy('default', 'development');
|
||||
|
||||
return <div>{strategy?.name ?? 'no-default-strategy'}</div>;
|
||||
};
|
||||
|
||||
const RenderFallbackStrategy = () => {
|
||||
const { defaultStrategyFallback } = useDefaultStrategy(
|
||||
'default',
|
||||
'development'
|
||||
);
|
||||
|
||||
return <div>{defaultStrategyFallback.parameters.stickiness}</div>;
|
||||
};
|
||||
|
||||
test('should render default strategy from project', async () => {
|
||||
testServerRoute(server, '/api/admin/projects/default', {
|
||||
environments: [
|
||||
{
|
||||
environment: 'development',
|
||||
defaultStrategy: { name: 'my-strategy' },
|
||||
},
|
||||
],
|
||||
});
|
||||
render(<RenderStrategy />);
|
||||
|
||||
await screen.findByText('my-strategy');
|
||||
});
|
||||
|
||||
test('should render fallback default strategy with project default stickiness', async () => {
|
||||
testServerRoute(server, '/api/admin/projects/default', {
|
||||
defaultStickiness: 'clientId',
|
||||
environments: [],
|
||||
});
|
||||
render(<RenderFallbackStrategy />);
|
||||
|
||||
await screen.findByText('clientId');
|
||||
});
|
||||
|
||||
test('should render fallback default strategy with no project default stickiness', async () => {
|
||||
testServerRoute(server, '/api/admin/projects/default', {
|
||||
environments: [],
|
||||
});
|
||||
render(<RenderFallbackStrategy />);
|
||||
|
||||
await screen.findByText('default');
|
||||
});
|
@ -31,7 +31,7 @@ export const useDefaultStrategy = (
|
||||
constraints: [],
|
||||
parameters: {
|
||||
rollout: '100',
|
||||
stickiness: project.defaultStickiness,
|
||||
stickiness: project.defaultStickiness || 'default',
|
||||
groupId: '',
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user