mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: list projects with all archived toggles (#3020)
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:
		
							parent
							
								
									7f2acafb81
								
							
						
					
					
						commit
						f290c593b5
					
				@ -88,14 +88,13 @@ class ProjectStore implements IProjectStore {
 | 
			
		||||
        const projectTimer = this.timer('getProjectsWithCount');
 | 
			
		||||
        let projects = this.db(TABLE)
 | 
			
		||||
            .leftJoin('features', 'features.project', 'projects.id')
 | 
			
		||||
            .where('features.archived_at', null)
 | 
			
		||||
            .orderBy('projects.name', 'asc');
 | 
			
		||||
        if (query) {
 | 
			
		||||
            projects = projects.where(query);
 | 
			
		||||
        }
 | 
			
		||||
        let selectColumns = [
 | 
			
		||||
            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>)[];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1057,6 +1057,28 @@ test('should only count active feature toggles for project', async () => {
 | 
			
		||||
    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 (days: number, featureName: string) => {
 | 
			
		||||
    await db.rawDatabase
 | 
			
		||||
        .table('events')
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user