-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return lifecycle state in feature overview (#6920)
- Loading branch information
Showing
15 changed files
with
202 additions
and
20 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/lib/features/feature-lifecycle/fake-feature-lifecycle-read-model.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,12 @@ | ||
import type { IFeatureLifecycleReadModel } from './feature-lifecycle-read-model-type'; | ||
import type { IFeatureLifecycleStage } from '../../types'; | ||
|
||
export class FakeFeatureLifecycleReadModel | ||
implements IFeatureLifecycleReadModel | ||
{ | ||
findCurrentStage( | ||
feature: string, | ||
): Promise<IFeatureLifecycleStage | undefined> { | ||
return Promise.resolve(undefined); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/lib/features/feature-lifecycle/feature-lifecycle-read-model-type.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,7 @@ | ||
import type { IFeatureLifecycleStage } from '../../types'; | ||
|
||
export interface IFeatureLifecycleReadModel { | ||
findCurrentStage( | ||
feature: string, | ||
): Promise<IFeatureLifecycleStage | undefined>; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/lib/features/feature-lifecycle/feature-lifecycle-read-model.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,33 @@ | ||
import type { Db } from '../../db/db'; | ||
import type { IFeatureLifecycleReadModel } from './feature-lifecycle-read-model-type'; | ||
import { getCurrentStage } from './get-current-stage'; | ||
import type { IFeatureLifecycleStage, StageName } from '../../types'; | ||
|
||
type DBType = { | ||
feature: string; | ||
stage: StageName; | ||
created_at: Date; | ||
}; | ||
|
||
export class FeatureLifecycleReadModel implements IFeatureLifecycleReadModel { | ||
private db: Db; | ||
|
||
constructor(db: Db) { | ||
this.db = db; | ||
} | ||
|
||
async findCurrentStage( | ||
feature: string, | ||
): Promise<IFeatureLifecycleStage | undefined> { | ||
const results = await this.db('feature_lifecycles') | ||
.where({ feature }) | ||
.orderBy('created_at', 'asc'); | ||
|
||
const stages = results.map(({ stage, created_at }: DBType) => ({ | ||
stage, | ||
enteredStageAt: created_at, | ||
})); | ||
|
||
return getCurrentStage(stages); | ||
} | ||
} |
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
14 changes: 2 additions & 12 deletions
14
src/lib/features/feature-lifecycle/feature-lifecycle-store-type.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
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
39 changes: 39 additions & 0 deletions
39
src/lib/features/feature-lifecycle/get-current-stage.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,39 @@ | ||
import { getCurrentStage } from './get-current-stage'; | ||
import type { IFeatureLifecycleStage } from '../../types'; | ||
|
||
const irrelevantDate = new Date('2024-04-22T10:00:00Z'); | ||
|
||
describe('getCurrentStage', () => { | ||
it('should return the first matching stage based on the preferred order', () => { | ||
const stages: IFeatureLifecycleStage[] = [ | ||
{ | ||
stage: 'initial', | ||
enteredStageAt: irrelevantDate, | ||
}, | ||
{ | ||
stage: 'completed', | ||
enteredStageAt: irrelevantDate, | ||
}, | ||
{ | ||
stage: 'archived', | ||
enteredStageAt: irrelevantDate, | ||
}, | ||
{ stage: 'live', enteredStageAt: irrelevantDate }, | ||
]; | ||
|
||
const result = getCurrentStage(stages); | ||
|
||
expect(result).toEqual({ | ||
stage: 'archived', | ||
enteredStageAt: irrelevantDate, | ||
}); | ||
}); | ||
|
||
it('should handle an empty stages array', () => { | ||
const stages: IFeatureLifecycleStage[] = []; | ||
|
||
const result = getCurrentStage(stages); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
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,23 @@ | ||
import type { IFeatureLifecycleStage, StageName } from '../../types'; | ||
|
||
const preferredOrder: StageName[] = [ | ||
'archived', | ||
'completed', | ||
'live', | ||
'pre-live', | ||
'initial', | ||
]; | ||
|
||
export function getCurrentStage( | ||
stages: IFeatureLifecycleStage[], | ||
): IFeatureLifecycleStage | undefined { | ||
for (const preferredStage of preferredOrder) { | ||
const foundStage = stages.find( | ||
(stage) => stage.stage === preferredStage, | ||
); | ||
if (foundStage) { | ||
return foundStage; | ||
} | ||
} | ||
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
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
Oops, something went wrong.