mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
test: project insights read model test (#6657)
This commit is contained in:
parent
85454bf488
commit
3241d14a05
@ -0,0 +1,66 @@
|
|||||||
|
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
|
||||||
|
import getLogger from '../../../test/fixtures/no-logger';
|
||||||
|
import type { IUser } from '../../types';
|
||||||
|
import type { IProjectInsightsReadModel } from './project-insights-read-model-type';
|
||||||
|
import {
|
||||||
|
type ChangeRequestDBState,
|
||||||
|
ProjectInsightsReadModel,
|
||||||
|
} from './project-insights-read-model';
|
||||||
|
|
||||||
|
let projectInsightsReadModel: IProjectInsightsReadModel;
|
||||||
|
let user: IUser;
|
||||||
|
let db: ITestDb;
|
||||||
|
const projectId = 'default';
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
db = await dbInit('project_insights_read_model', getLogger);
|
||||||
|
projectInsightsReadModel = new ProjectInsightsReadModel(db.rawDatabase);
|
||||||
|
user = await db.stores.userStore.insert({
|
||||||
|
username: 'test',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await db.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.rawDatabase.table('change_requests').delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
const createChangeRequest = (id: number, state: string) =>
|
||||||
|
db.rawDatabase.table('change_requests').insert({
|
||||||
|
id,
|
||||||
|
state,
|
||||||
|
environment: 'default',
|
||||||
|
project: projectId,
|
||||||
|
created_by: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
test('can read change request status counts', async () => {
|
||||||
|
const states: ChangeRequestDBState[] = [
|
||||||
|
'Approved',
|
||||||
|
'Approved',
|
||||||
|
'Applied',
|
||||||
|
'Rejected',
|
||||||
|
'Scheduled',
|
||||||
|
'In review',
|
||||||
|
'Draft',
|
||||||
|
'Cancelled',
|
||||||
|
];
|
||||||
|
await Promise.all(
|
||||||
|
states.map((state, id) => createChangeRequest(id, state)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const changeRequests =
|
||||||
|
await projectInsightsReadModel.getChangeRequests(projectId);
|
||||||
|
|
||||||
|
expect(changeRequests).toEqual({
|
||||||
|
total: 6,
|
||||||
|
approved: 2,
|
||||||
|
applied: 1,
|
||||||
|
rejected: 1,
|
||||||
|
reviewRequired: 1,
|
||||||
|
scheduled: 1,
|
||||||
|
});
|
||||||
|
});
|
@ -5,6 +5,8 @@ import type {
|
|||||||
import type { Db } from '../../db/db';
|
import type { Db } from '../../db/db';
|
||||||
|
|
||||||
export type ChangeRequestDBState =
|
export type ChangeRequestDBState =
|
||||||
|
| 'Draft'
|
||||||
|
| 'Cancelled'
|
||||||
| 'Approved'
|
| 'Approved'
|
||||||
| 'In review'
|
| 'In review'
|
||||||
| 'Applied'
|
| 'Applied'
|
||||||
|
Loading…
Reference in New Issue
Block a user