From bb20c6d10213f5e3eecd1d1c83a998f8700474d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 18 Jan 2023 15:58:27 +0100 Subject: [PATCH] fix: project feature_count should not include archived (#2919) fixes: #2923 --- src/lib/db/project-store.ts | 1 + .../e2e/services/project-service.e2e.test.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index 8a438d012c..0663d59688 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -88,6 +88,7 @@ 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); diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index f455477997..9d272447e1 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -1026,3 +1026,30 @@ test('Should allow bulk update of only groups', async () => { 'some-admin-user', ); }); + +test('should only count active feature toggles for project', async () => { + const project = { + id: 'only-active', + name: 'New project', + description: 'Blah', + }; + + await projectService.createProject(project, user); + + await stores.featureToggleStore.create(project.id, { + name: 'only-active-t1', + project: project.id, + enabled: false, + }); + await stores.featureToggleStore.create(project.id, { + name: 'only-active-t2', + project: project.id, + enabled: false, + }); + + await featureToggleService.archiveToggle('only-active-t2', 'me'); + + const projects = await projectService.getProjects(); + const theProject = projects.find((p) => p.id === project.id); + expect(theProject?.featureCount).toBe(1); +});