-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
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
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
13 changes: 12 additions & 1 deletion
13
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 |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import type { IFeatureLifecycleStage } from '../../types'; | ||
import type { IFeatureLifecycleStage, StageName } from '../../types'; | ||
|
||
export type StageCount = { | ||
stage: StageName; | ||
count: number; | ||
}; | ||
|
||
export type StageCountByProject = StageCount & { | ||
project: string; | ||
}; | ||
|
||
export interface IFeatureLifecycleReadModel { | ||
findCurrentStage( | ||
feature: string, | ||
): Promise<IFeatureLifecycleStage | undefined>; | ||
getStageCount(): Promise<StageCount[]>; | ||
getStageCountByProject(): Promise<StageCountByProject[]>; | ||
} |
64 changes: 64 additions & 0 deletions
64
src/lib/features/feature-lifecycle/feature-lifecycle-read-model.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,64 @@ | ||
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; | ||
import getLogger from '../../../test/fixtures/no-logger'; | ||
import { FeatureLifecycleReadModel } from './feature-lifecycle-read-model'; | ||
import type { IFeatureLifecycleStore } from './feature-lifecycle-store-type'; | ||
import type { IFeatureLifecycleReadModel } from './feature-lifecycle-read-model-type'; | ||
import type { IFeatureToggleStore } from '../feature-toggle/types/feature-toggle-store-type'; | ||
|
||
let db: ITestDb; | ||
let featureLifeycycleReadModel: IFeatureLifecycleReadModel; | ||
let featureLifecycleStore: IFeatureLifecycleStore; | ||
let featureToggleStore: IFeatureToggleStore; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('feature_lifecycle_read_model', getLogger); | ||
featureLifeycycleReadModel = new FeatureLifecycleReadModel(db.rawDatabase); | ||
featureLifecycleStore = db.stores.featureLifecycleStore; | ||
featureToggleStore = db.stores.featureToggleStore; | ||
}); | ||
|
||
afterAll(async () => { | ||
if (db) { | ||
await db.destroy(); | ||
} | ||
}); | ||
|
||
beforeEach(async () => { | ||
await featureToggleStore.deleteAll(); | ||
}); | ||
|
||
test('can return stage count', async () => { | ||
await featureToggleStore.create('default', { | ||
name: 'featureA', | ||
createdByUserId: 9999, | ||
}); | ||
await featureToggleStore.create('default', { | ||
name: 'featureB', | ||
createdByUserId: 9999, | ||
}); | ||
await featureToggleStore.create('default', { | ||
name: 'featureC', | ||
createdByUserId: 9999, | ||
}); | ||
await featureLifecycleStore.insert([ | ||
{ feature: 'featureA', stage: 'initial' }, | ||
{ feature: 'featureB', stage: 'initial' }, | ||
{ feature: 'featureC', stage: 'initial' }, | ||
]); | ||
await featureLifecycleStore.insert([ | ||
{ feature: 'featureA', stage: 'pre-live' }, | ||
]); | ||
|
||
const stageCount = await featureLifeycycleReadModel.getStageCount(); | ||
expect(stageCount).toMatchObject([ | ||
{ stage: 'pre-live', count: 1 }, | ||
{ stage: 'initial', count: 2 }, | ||
]); | ||
|
||
const stageCountByProject = | ||
await featureLifeycycleReadModel.getStageCountByProject(); | ||
expect(stageCountByProject).toMatchObject([ | ||
{ project: 'default', stage: 'pre-live', count: 1 }, | ||
{ project: 'default', stage: 'initial', count: 2 }, | ||
]); | ||
}); |
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