From c9ff3972e2d1b998b7ea0aa9308c515fe1f8ece6 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Thu, 25 Nov 2021 10:09:23 +0100 Subject: [PATCH] fix: Stop healthrating from including archived (#1128) - Since the archived toggles are not visible in the health dashboard, including them in the health rating calculation makes for some really confusing dashboards. This PR makes sure we only include non-archived toggles when calculating health. --- src/lib/services/project-health-service.ts | 1 + .../admin/project/project.health.e2e.test.ts | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/lib/services/project-health-service.ts b/src/lib/services/project-health-service.ts index 0dee3b60f0..24651affb5 100644 --- a/src/lib/services/project-health-service.ts +++ b/src/lib/services/project-health-service.ts @@ -129,6 +129,7 @@ export default class ProjectHealthService { async calculateHealthRating(project: IProject): Promise { const toggles = await this.featureToggleStore.getAll({ project: project.id, + archived: false, }); const activeToggles = toggles.filter((feature) => !feature.stale); diff --git a/src/test/e2e/api/admin/project/project.health.e2e.test.ts b/src/test/e2e/api/admin/project/project.health.e2e.test.ts index 335a17fae1..a10daed317 100644 --- a/src/test/e2e/api/admin/project/project.health.e2e.test.ts +++ b/src/test/e2e/api/admin/project/project.health.e2e.test.ts @@ -97,7 +97,67 @@ test('Health rating endpoint yields stale, potentially stale and active count on expect(res.body.potentiallyStaleCount).toBe(0); }); }); +test('Health rating endpoint does not include archived toggles when calculating potentially stale toggles', async () => { + const project = { + id: 'potentially-stale-archived', + name: 'Health rating', + description: 'Fancy', + }; + await app.services.projectService.createProject(project, user); + await app.request + .post(`/api/admin/projects/${project.id}/features`) + .send({ + name: 'potentially-stale-archive-fresh', + description: 'new', + stale: false, + }) + .expect(201); + await app.request + .post(`/api/admin/projects/${project.id}/features`) + .send({ + name: 'potentially-stale-archive-fresh-2', + description: 'new too', + stale: false, + }) + .expect(201); + await app.request + .post(`/api/admin/projects/${project.id}/features`) + .send({ + name: 'potentially-stale-archive-stale', + description: 'stale', + stale: true, + }) + .expect(201); + await app.request + .post(`/api/admin/projects/${project.id}/features`) + .send({ + name: 'potentially-archive-stale', + description: 'Really Old', + createdAt: new Date(2019, 5, 1), + }) + .expect(201); + await app.request + .post(`/api/admin/projects/${project.id}/features`) + .send({ + name: 'potentially-archive-stale-archived', + description: 'Really Old', + createdAt: new Date(2019, 5, 1), + archived: true, + }) + .expect(201); + await app.services.projectHealthService.setHealthRating(); + await app.request + .get(`/api/admin/projects/${project.id}/health-report`) + .expect(200) + .expect('Content-Type', /json/) + .expect((res) => { + expect(res.body.health).toBe(50); + expect(res.body.activeCount).toBe(3); + expect(res.body.staleCount).toBe(1); + expect(res.body.potentiallyStaleCount).toBe(1); + }); +}); test('Health rating endpoint correctly handles potentially stale toggles', async () => { const project = { id: 'potentially-stale',