Skip to content

Commit

Permalink
Merge pull request #1145 from Unleash/feat/update-health-report
Browse files Browse the repository at this point in the history
feat: update health report
  • Loading branch information
ykhedher committed Dec 6, 2021
2 parents 642a237 + 5e6e7e1 commit 7ec9672
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib/db/project-store.ts
Expand Up @@ -11,7 +11,14 @@ import {
} from '../types/stores/project-store';
import { DEFAULT_ENV } from '../util/constants';

const COLUMNS = ['id', 'name', 'description', 'created_at', 'health'];
const COLUMNS = [
'id',
'name',
'description',
'created_at',
'health',
'updated_at',
];
const TABLE = 'projects';

class ProjectStore implements IProjectStore {
Expand Down Expand Up @@ -74,7 +81,7 @@ class ProjectStore implements IProjectStore {
async updateHealth(healthUpdate: IProjectHealthUpdate): Promise<void> {
await this.db(TABLE)
.where({ id: healthUpdate.id })
.update({ health: healthUpdate.health });
.update({ health: healthUpdate.health, updated_at: new Date() });
}

async create(project: IProjectInsert): Promise<IProject> {
Expand Down Expand Up @@ -197,6 +204,7 @@ class ProjectStore implements IProjectStore {
description: row.description,
createdAt: row.created_at,
health: row.health || 100,
updatedAt: row.updated_at || new Date(),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/services/project-health-service.ts
Expand Up @@ -72,6 +72,7 @@ export default class ProjectHealthService {
name: project.name,
description: project.description,
health: project.health,
updatedAt: project.updatedAt,
environments,
features,
members,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/model.ts
Expand Up @@ -143,6 +143,7 @@ export interface IProjectOverview {
members: number;
version: number;
health: number;
updatedAt?: Date;
}

export interface IProjectHealthReport extends IProjectOverview {
Expand Down Expand Up @@ -309,6 +310,7 @@ export interface IProject {
description: string;
health?: number;
createdAt?: Date;
updatedAt?: Date;
}

export interface IProjectWithCount extends IProject {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/stores/project-store.ts
Expand Up @@ -5,6 +5,7 @@ export interface IProjectInsert {
id: string;
name: string;
description: string;
updatedAt?: Date;
}

export interface IProjectArchived {
Expand Down
12 changes: 12 additions & 0 deletions src/migrations/20211130142314-add-updated-at-to-projects.js
@@ -0,0 +1,12 @@
'use strict';

exports.up = function (db, callback) {
db.runSql(
'ALTER TABLE projects ADD COLUMN "updated_at" TIMESTAMP WITH TIME ZONE DEFAULT now();',
callback,
);
};

exports.down = function (db, callback) {
db.runSql('ALTER TABLE projects DROP COLUMN "updated_at";', callback);
};
13 changes: 13 additions & 0 deletions src/test/e2e/api/admin/project/project.health.e2e.test.ts
Expand Up @@ -302,3 +302,16 @@ test('Sorts environments correctly if sort order is equal', async () => {
expect(feature.environments[1].name).toBe(envTwo);
});
});

test('Update update_at when setHealth runs', async () => {
await app.services.projectHealthService.setHealthRating();
await app.request
.get('/api/admin/projects/default/health-report')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
let now = new Date().getTime();
let updatedAt = new Date(res.body.updatedAt).getTime();
expect(now - updatedAt).toBeLessThan(5000);
});
});
1 change: 1 addition & 0 deletions src/test/e2e/stores/project-store.e2e.test.ts
Expand Up @@ -39,6 +39,7 @@ test('should create new project', async () => {
expect(project.name).toEqual(ret.name);
expect(project.description).toEqual(ret.description);
expect(ret.createdAt).toBeTruthy();
expect(ret.updatedAt).toBeTruthy();
expect(exists).toBe(true);
});

Expand Down

1 comment on commit 7ec9672

@vercel
Copy link

@vercel vercel bot commented on 7ec9672 Dec 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.