From f290c593b5b23a5367a374b5c0519c5329b92b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Mon, 30 Jan 2023 14:32:43 +0100 Subject: [PATCH] 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) --- src/lib/db/project-store.ts | 3 +-- .../e2e/services/project-service.e2e.test.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index 0663d59688..b15ab1eb54 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -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)[]; diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index 19bf80bfb0..91595d419b 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -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')