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

fix: exclude archived features in segments count (#7897)

This commit is contained in:
Mateusz Kwasniewski 2024-08-15 13:27:18 +02:00 committed by GitHub
parent cf83043d8a
commit c2e6f74bfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

View File

@ -948,4 +948,39 @@ describe('detect strategy usage in change requests', () => {
{ usedInFeatures: 0, usedInProjects: 0 },
]);
});
test('If a segment is used in an archived feature it should be excluded from count - enterprise version', async () => {
await app.createSegment({
name: 'a',
constraints: [],
});
const flag = mockFeatureFlag();
await createFeatureFlag(enterpriseApp, flag);
const [segment] = await enterpriseFetchSegments();
await addStrategyToFeatureEnv(
enterpriseApp,
{ ...flag.strategies[0] },
'default',
flag.name,
);
const [feature] = await fetchFeatures();
const [strategy] = await fetchFeatureStrategies(feature.name);
const strategyId = strategy.id;
await addSegmentsToStrategy([segment.id], strategyId!);
const segments = await enterpriseFetchSegments();
expect(segments).toMatchObject([
{ usedInFeatures: 1, usedInProjects: 1 },
]);
await enterpriseApp.archiveFeature(flag.name, 'default');
const segmentsAfter = await enterpriseFetchSegments();
expect(segmentsAfter).toMatchObject([
{ usedInFeatures: 0, usedInProjects: 0 },
]);
});
});

View File

@ -187,7 +187,13 @@ export default class SegmentStore implements ISegmentStore {
T.featureStrategies,
`${T.featureStrategies}.id`,
`${T.featureStrategySegment}.feature_strategy_id`,
);
)
.leftJoin(
T.features,
`${T.featureStrategies}.feature_name`,
`${T.features}.name`,
)
.where(`${T.features}.archived_at`, null);
this.mergeCurrentUsageWithCombinedData(
combinedUsageData,