1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00

feat: pre-live should include disabled prod (#7031)

This commit is contained in:
Mateusz Kwasniewski 2024-05-10 13:53:01 +02:00 committed by GitHub
parent 60a67d4775
commit 56ae53a4da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 12 deletions

View File

@ -13,6 +13,7 @@ export interface LifecycleFeature {
type: string; type: string;
name: string; name: string;
lastSeenAt?: string | null; lastSeenAt?: string | null;
enabled: boolean;
}>; }>;
} }

View File

@ -53,7 +53,7 @@ test('render initial stage', async () => {
await screen.findByText('initial'); await screen.findByText('initial');
await screen.findByText('2 minutes'); await screen.findByText('2 minutes');
await screen.findByText( await screen.findByText(
"This feature toggle is currently in the initial phase of it's life cycle.", 'This feature flag is currently in the initial phase of its lifecycle.',
); );
}); });

View File

@ -136,7 +136,7 @@ const InitialStageDescription: FC = () => {
return ( return (
<> <>
<InfoText> <InfoText>
This feature toggle is currently in the initial phase of it's This feature flag is currently in the initial phase of its
lifecycle. lifecycle.
</InfoText> </InfoText>
<InfoText> <InfoText>
@ -250,8 +250,7 @@ const PreLiveStageDescription: FC = ({ children }) => {
return ( return (
<> <>
<InfoText> <InfoText>
We've seen the feature flag in the following non-production We've seen the feature flag in the following environments:
environments:
</InfoText> </InfoText>
{children} {children}

View File

@ -24,13 +24,27 @@ describe('populateCurrentStage', () => {
lifecycle: { stage: 'pre-live', enteredStageAt }, lifecycle: { stage: 'pre-live', enteredStageAt },
environments: [ environments: [
{ name: 'test', type: 'development', lastSeenAt: null }, { name: 'test', type: 'development', lastSeenAt: null },
{ name: 'test1', type: 'production', lastSeenAt: '2022-08-01' }, {
name: 'test1',
type: 'production',
lastSeenAt: '2022-08-01',
enabled: true,
},
{ name: 'dev', type: 'development', lastSeenAt: '2022-08-01' }, { name: 'dev', type: 'development', lastSeenAt: '2022-08-01' },
{
name: 'prod_disabled',
type: 'production',
lastSeenAt: '2022-08-02',
enabled: false,
},
], ],
} as IFeatureToggle; } as IFeatureToggle;
const expected = { const expected = {
name: 'pre-live', name: 'pre-live',
environments: [{ name: 'dev', lastSeenAt: '2022-08-01' }], environments: [
{ name: 'dev', lastSeenAt: '2022-08-01' },
{ name: 'prod_disabled', lastSeenAt: '2022-08-02' },
],
enteredStageAt, enteredStageAt,
}; };
const result = populateCurrentStage(feature); const result = populateCurrentStage(feature);
@ -41,7 +55,18 @@ describe('populateCurrentStage', () => {
const feature = { const feature = {
lifecycle: { stage: 'live', enteredStageAt }, lifecycle: { stage: 'live', enteredStageAt },
environments: [ environments: [
{ name: 'prod', type: 'production', lastSeenAt: '2022-08-01' }, {
name: 'prod',
type: 'production',
lastSeenAt: '2022-08-01',
enabled: true,
},
{
name: 'prod_ignore',
type: 'production',
lastSeenAt: '2022-08-01',
enabled: false,
},
], ],
} as IFeatureToggle; } as IFeatureToggle;
const expected = { const expected = {

View File

@ -6,9 +6,11 @@ export const populateCurrentStage = (
): LifecycleStage | undefined => { ): LifecycleStage | undefined => {
if (!feature.lifecycle) return undefined; if (!feature.lifecycle) return undefined;
const getFilteredEnvironments = (condition: (type: string) => boolean) => { const getFilteredEnvironments = (
condition: (env: { type: string; enabled: boolean }) => boolean,
) => {
return (feature.environments || []) return (feature.environments || [])
.filter((env) => condition(env.type) && Boolean(env.lastSeenAt)) .filter((env) => condition(env) && Boolean(env.lastSeenAt))
.map((env) => ({ .map((env) => ({
name: env.name, name: env.name,
lastSeenAt: env.lastSeenAt!, lastSeenAt: env.lastSeenAt!,
@ -24,7 +26,9 @@ export const populateCurrentStage = (
return { return {
name: 'pre-live', name: 'pre-live',
environments: getFilteredEnvironments( environments: getFilteredEnvironments(
(type) => type !== 'production', (env) =>
env.type !== 'production' ||
(env.type === 'production' && !env.enabled),
), ),
enteredStageAt, enteredStageAt,
}; };
@ -32,7 +36,7 @@ export const populateCurrentStage = (
return { return {
name: 'live', name: 'live',
environments: getFilteredEnvironments( environments: getFilteredEnvironments(
(type) => type === 'production', (env) => env.type === 'production' && env.enabled,
), ),
enteredStageAt, enteredStageAt,
}; };