1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/frontend/src/hooks/useHighestPermissionChangeRequestEnvironment.test.ts
Thomas Heartman 452f3942a7
feat(#4209): add segment to drafts (#4408)
This PR sends segments to CR drafts when you use the `add to draft`
button.

It also adds the logic for which environment to pick.

Segments sent to the API are added to drafts, but not displayed in the
UI yet. CRs with only segment changes are also not listed in the table.
This'll be covered in upcoming work.
2023-08-04 12:57:26 +00:00

67 lines
1.8 KiB
TypeScript

import { getHighestChangeRequestEnv } from './useHighestPermissionChangeRequestEnvironment';
describe('Get the right change request env', () => {
it('gets a production env if present', () => {
const data = [
{
environment: 'x',
type: 'development',
changeRequestEnabled: true,
requiredApprovals: 1,
},
{
environment: 'y',
type: 'production',
changeRequestEnabled: true,
requiredApprovals: 1,
},
];
const result = getHighestChangeRequestEnv(data)();
expect(result).toBe('y');
});
it('gets a non-production env if no production envs have change requests enabled', () => {
const data = [
{
environment: 'x',
type: 'development',
changeRequestEnabled: true,
requiredApprovals: 1,
},
{
environment: 'y',
type: 'production',
changeRequestEnabled: false,
requiredApprovals: 1,
},
];
const result = getHighestChangeRequestEnv(data)();
expect(result).toBe('x');
});
it('returns undefined if no envs have change requests enabled', () => {
const data = [
{
environment: 'x',
type: 'development',
changeRequestEnabled: false,
requiredApprovals: 1,
},
{
environment: 'y',
type: 'production',
changeRequestEnabled: false,
requiredApprovals: 1,
},
];
const result = getHighestChangeRequestEnv(data)();
expect(result).toBe(undefined);
});
});