1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: list projects with all archived toggles (#3020)

## About the changes
While trying to count only features that are not archived to display the
amount of features of a project, accidentally we filtered out projects
with all features archived (they should show up in the list but with
count of features zero)
This commit is contained in:
Gastón Fournier 2023-01-30 14:32:43 +01:00 committed by GitHub
parent b0ef6920e8
commit 812604902b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -89,14 +89,13 @@ class ProjectStore implements IProjectStore {
const projectTimer = this.timer('getProjectsWithCount'); const projectTimer = this.timer('getProjectsWithCount');
let projects = this.db(TABLE) let projects = this.db(TABLE)
.leftJoin('features', 'features.project', 'projects.id') .leftJoin('features', 'features.project', 'projects.id')
.where('features.archived_at', null)
.orderBy('projects.name', 'asc'); .orderBy('projects.name', 'asc');
if (query) { if (query) {
projects = projects.where(query); projects = projects.where(query);
} }
let selectColumns = [ let selectColumns = [
this.db.raw( this.db.raw(
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) AS number_of_features', 'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features',
), ),
] as (string | Raw<any>)[]; ] as (string | Raw<any>)[];

View File

@ -1057,6 +1057,28 @@ test('should only count active feature toggles for project', async () => {
expect(theProject?.featureCount).toBe(1); expect(theProject?.featureCount).toBe(1);
}); });
test('should list projects with all features archived', async () => {
const project = {
id: 'only-archived',
name: 'Listed project',
description: 'Blah',
};
await projectService.createProject(project, user);
await stores.featureToggleStore.create(project.id, {
name: 'archived-toggle',
project: project.id,
enabled: false,
});
await featureToggleService.archiveToggle('archived-toggle', 'me');
const projects = await projectService.getProjects();
const theProject = projects.find((p) => p.id === project.id);
expect(theProject?.featureCount).toBe(0);
});
const updateEventCreatedAt = async (date: Date, featureName: string) => { const updateEventCreatedAt = async (date: Date, featureName: string) => {
return db.rawDatabase return db.rawDatabase
.table('events') .table('events')