1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Merge pull request #1145 from Unleash/feat/update-health-report

feat: update health report
This commit is contained in:
Youssef Khedher 2021-12-06 15:39:45 +01:00 committed by GitHub
commit 7ec9672a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 2 deletions

View File

@ -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 {
@ -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> {
@ -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(),
};
}
}

View File

@ -72,6 +72,7 @@ export default class ProjectHealthService {
name: project.name,
description: project.description,
health: project.health,
updatedAt: project.updatedAt,
environments,
features,
members,

View File

@ -143,6 +143,7 @@ export interface IProjectOverview {
members: number;
version: number;
health: number;
updatedAt?: Date;
}
export interface IProjectHealthReport extends IProjectOverview {
@ -309,6 +310,7 @@ export interface IProject {
description: string;
health?: number;
createdAt?: Date;
updatedAt?: Date;
}
export interface IProjectWithCount extends IProject {

View File

@ -5,6 +5,7 @@ export interface IProjectInsert {
id: string;
name: string;
description: string;
updatedAt?: Date;
}
export interface IProjectArchived {

View File

@ -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);
};

View File

@ -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);
});
});

View File

@ -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);
});