-
-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connect feature lifecycle to real API (#6921)
- Loading branch information
Showing
4 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...mponent/feature/FeatureView/FeatureOverview/FeatureLifecycle/populateCurrentStage.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,76 @@ | ||
import { populateCurrentStage } from './populateCurrentStage'; | ||
import type { IFeatureToggle } from '../../../../../interfaces/featureToggle'; | ||
|
||
describe('populateCurrentStage', () => { | ||
it('should return undefined if lifecycle is not defined', () => { | ||
const feature = {}; | ||
const result = populateCurrentStage(feature as IFeatureToggle); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return initial stage when lifecycle stage is initial', () => { | ||
const feature = { | ||
lifecycle: { stage: 'initial' }, | ||
}; | ||
const expected = { name: 'initial' }; | ||
const result = populateCurrentStage(feature as IFeatureToggle); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should correctly populate pre-live stage with dev environments', () => { | ||
const feature = { | ||
lifecycle: { stage: 'pre-live' }, | ||
environments: [ | ||
{ name: 'test', type: 'development', lastSeenAt: null }, | ||
{ name: 'test1', type: 'production', lastSeenAt: '2022-08-01' }, | ||
{ name: 'dev', type: 'development', lastSeenAt: '2022-08-01' }, | ||
], | ||
} as IFeatureToggle; | ||
const expected = { | ||
name: 'pre-live', | ||
environments: [{ name: 'dev', lastSeenAt: '2022-08-01' }], | ||
}; | ||
const result = populateCurrentStage(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should handle live stage with production environments', () => { | ||
const feature = { | ||
lifecycle: { stage: 'live' }, | ||
environments: [ | ||
{ name: 'prod', type: 'production', lastSeenAt: '2022-08-01' }, | ||
], | ||
} as IFeatureToggle; | ||
const expected = { | ||
name: 'live', | ||
environments: [{ name: 'prod', lastSeenAt: '2022-08-01' }], | ||
}; | ||
const result = populateCurrentStage(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should return completed stage with production environments', () => { | ||
const feature = { | ||
lifecycle: { stage: 'completed' }, | ||
environments: [ | ||
{ name: 'prod', type: 'production', lastSeenAt: '2022-08-01' }, | ||
], | ||
} as IFeatureToggle; | ||
const expected = { | ||
name: 'completed', | ||
status: 'kept', | ||
environments: [{ name: 'prod', lastSeenAt: '2022-08-01' }], | ||
}; | ||
const result = populateCurrentStage(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should return archived stage when lifecycle stage is archived', () => { | ||
const feature = { | ||
lifecycle: { stage: 'archived' }, | ||
} as IFeatureToggle; | ||
const expected = { name: 'archived' }; | ||
const result = populateCurrentStage(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...rc/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/populateCurrentStage.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,48 @@ | ||
import type { IFeatureToggle } from 'interfaces/featureToggle'; | ||
import type { LifecycleStage } from './LifecycleStage'; | ||
|
||
export const populateCurrentStage = ( | ||
feature: Pick<IFeatureToggle, 'lifecycle' | 'environments'>, | ||
): LifecycleStage | undefined => { | ||
if (!feature.lifecycle) return undefined; | ||
|
||
const getFilteredEnvironments = (condition: (type: string) => boolean) => { | ||
return feature.environments | ||
.filter((env) => condition(env.type) && Boolean(env.lastSeenAt)) | ||
.map((env) => ({ | ||
name: env.name, | ||
lastSeenAt: env.lastSeenAt!, | ||
})); | ||
}; | ||
|
||
switch (feature.lifecycle.stage) { | ||
case 'initial': | ||
return { name: 'initial' }; | ||
case 'pre-live': | ||
return { | ||
name: 'pre-live', | ||
environments: getFilteredEnvironments( | ||
(type) => type !== 'production', | ||
), | ||
}; | ||
case 'live': | ||
return { | ||
name: 'live', | ||
environments: getFilteredEnvironments( | ||
(type) => type === 'production', | ||
), | ||
}; | ||
case 'completed': | ||
return { | ||
name: 'completed', | ||
status: 'kept', | ||
environments: getFilteredEnvironments( | ||
(type) => type === 'production', | ||
), | ||
}; | ||
case 'archived': | ||
return { name: 'archived' }; | ||
default: | ||
return undefined; | ||
} | ||
}; |
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