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

fix: reached stage should emit feature name (#7068)

This commit is contained in:
Mateusz Kwasniewski 2024-05-16 12:11:13 +02:00 committed by GitHub
parent 7cf9cfa96e
commit 9281d6b694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 16 deletions

View File

@ -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([

View File

@ -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) {

View File

@ -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 () => {