diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle-service.test.ts b/src/lib/features/feature-lifecycle/feature-lifecycle-service.test.ts index 82f5f962bc..747365d7c6 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle-service.test.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle-service.test.ts @@ -38,10 +38,11 @@ test('can insert and read lifecycle stages', async () => { environment, }); } - function reachedStage(name: StageName) { + function reachedStage(feature: string, name: StageName) { return new Promise((resolve) => featureLifecycleService.on(STAGE_ENTERED, (event) => { - if (event.stage === name) resolve(name); + if (event.stage === name && event.feature === feature) + resolve(name); }), ); } @@ -65,20 +66,20 @@ test('can insert and read lifecycle stages', async () => { featureLifecycleService.listen(); eventStore.emit(FEATURE_CREATED, { featureName }); - await reachedStage('initial'); + await reachedStage(featureName, 'initial'); emitMetricsEvent('unknown-environment'); emitMetricsEvent('my-dev-environment'); - await reachedStage('pre-live'); + await reachedStage(featureName, 'pre-live'); emitMetricsEvent('my-dev-environment'); emitMetricsEvent('my-another-dev-environment'); emitMetricsEvent('my-prod-environment'); - await reachedStage('live'); + await reachedStage(featureName, 'live'); emitMetricsEvent('my-prod-environment'); emitMetricsEvent('my-another-prod-environment'); eventStore.emit(FEATURE_ARCHIVED, { featureName }); - await reachedStage('archived'); + await reachedStage(featureName, 'archived'); const lifecycle = await featureLifecycleService.getFeatureLifecycle(featureName); @@ -91,7 +92,7 @@ test('can insert and read lifecycle stages', async () => { ]); eventStore.emit(FEATURE_REVIVED, { featureName }); - await reachedStage('initial'); + await reachedStage(featureName, 'initial'); const initialLifecycle = await featureLifecycleService.getFeatureLifecycle(featureName); expect(initialLifecycle).toEqual([ diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts b/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts index 164690307d..62978b04b4 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts @@ -125,7 +125,7 @@ export class FeatureLifecycleService extends EventEmitter { await this.featureLifecycleStore.insert([ { feature, stage: 'initial' }, ]); - this.emit(STAGE_ENTERED, { stage: 'initial' }); + this.emit(STAGE_ENTERED, { stage: 'initial', feature }); } private async stageReceivedMetrics( @@ -135,7 +135,9 @@ export class FeatureLifecycleService extends EventEmitter { await this.featureLifecycleStore.insert( features.map((feature) => ({ feature, stage })), ); - this.emit(STAGE_ENTERED, { stage }); + features.forEach((feature) => + this.emit(STAGE_ENTERED, { stage, feature }), + ); } private async featuresReceivedMetrics( @@ -207,7 +209,7 @@ export class FeatureLifecycleService extends EventEmitter { await this.featureLifecycleStore.insert([ { feature, stage: 'archived' }, ]); - this.emit(STAGE_ENTERED, { stage: 'archived' }); + this.emit(STAGE_ENTERED, { stage: 'archived', feature }); } private async featureRevived(feature: string) { diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts b/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts index 8e5effacf1..5d15fd25ff 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts @@ -95,10 +95,10 @@ const uncompleteFeature = async (featureName: string, expectedCode = 200) => { .expect(expectedCode); }; -function reachedStage(name: StageName) { +function reachedStage(feature: string, stage: StageName) { return new Promise((resolve) => featureLifecycleService.on(STAGE_ENTERED, (event) => { - if (event.stage === name) resolve(name); + if (event.stage === stage) resolve(stage); }), ); } @@ -118,7 +118,7 @@ test('should return lifecycle stages', async () => { await app.createFeature('my_feature_a'); await app.enableFeature('my_feature_a', 'default'); eventStore.emit(FEATURE_CREATED, { featureName: 'my_feature_a' }); - await reachedStage('initial'); + await reachedStage('my_feature_a', 'initial'); await expectFeatureStage('my_feature_a', 'initial'); eventBus.emit(CLIENT_METRICS, { bucket: { @@ -143,10 +143,10 @@ test('should return lifecycle stages', async () => { }, environment: 'non-existent', }); - await reachedStage('live'); + await reachedStage('my_feature_a', 'live'); await expectFeatureStage('my_feature_a', 'live'); eventStore.emit(FEATURE_ARCHIVED, { featureName: 'my_feature_a' }); - await reachedStage('archived'); + await reachedStage('my_feature_a', 'archived'); const { body } = await getFeatureLifecycle('my_feature_a'); @@ -168,7 +168,7 @@ test('should return lifecycle stages', async () => { await expectFeatureStage('my_feature_a', 'archived'); eventStore.emit(FEATURE_REVIVED, { featureName: 'my_feature_a' }); - await reachedStage('initial'); + await reachedStage('my_feature_a', 'initial'); }); test('should be able to toggle between completed/uncompleted', async () => {