1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02: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:
Mateusz Kwasniewski 2023-07-26 09:39:40 +02:00 committed by GitHub
parent 55148eb549
commit 55aa15d96d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View File

@ -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');
});

View File

@ -31,7 +31,7 @@ export const useDefaultStrategy = (
constraints: [],
parameters: {
rollout: '100',
stickiness: project.defaultStickiness,
stickiness: project.defaultStickiness || 'default',
groupId: '',
},
};