2024-07-15 03:42:49 -07:00
|
|
|
import { LicenseMetricsRepository } from '@/databases/repositories/license-metrics.repository';
|
2024-01-22 03:29:28 -08:00
|
|
|
import { createAdmin, createMember, createOwner, createUser } from './shared/db/users';
|
|
|
|
import * as testDb from './shared/testDb';
|
|
|
|
import Container from 'typedi';
|
|
|
|
import { createManyWorkflows } from './shared/db/workflows';
|
|
|
|
import { createManyCredentials } from './shared/db/credentials';
|
|
|
|
import { WorkflowStatisticsRepository } from '@/databases/repositories/workflowStatistics.repository';
|
|
|
|
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics';
|
|
|
|
|
2024-07-15 03:42:49 -07:00
|
|
|
describe('LicenseMetricsRepository', () => {
|
|
|
|
let licenseMetricsRepository: LicenseMetricsRepository;
|
2024-01-22 03:29:28 -08:00
|
|
|
let workflowStatisticsRepository: WorkflowStatisticsRepository;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await testDb.init();
|
|
|
|
|
2024-07-15 03:42:49 -07:00
|
|
|
licenseMetricsRepository = Container.get(LicenseMetricsRepository);
|
2024-01-26 08:50:19 -08:00
|
|
|
|
2024-01-22 03:29:28 -08:00
|
|
|
workflowStatisticsRepository = Container.get(WorkflowStatisticsRepository);
|
2024-01-26 08:50:19 -08:00
|
|
|
});
|
2024-01-22 03:29:28 -08:00
|
|
|
|
2024-01-26 08:50:19 -08:00
|
|
|
beforeEach(async () => {
|
2024-01-22 03:29:28 -08:00
|
|
|
await testDb.truncate(['User', 'Credentials', 'Workflow', 'Execution', 'WorkflowStatistics']);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await testDb.terminate();
|
|
|
|
});
|
|
|
|
|
2024-07-15 03:42:49 -07:00
|
|
|
describe('getLicenseRenewalMetrics', () => {
|
2024-01-22 03:29:28 -08:00
|
|
|
test('should return license renewal metrics', async () => {
|
|
|
|
const [firstWorkflow, secondWorkflow] = await createManyWorkflows(2, { active: false });
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
createOwner(),
|
|
|
|
createAdmin(),
|
|
|
|
createMember(),
|
|
|
|
createMember(),
|
|
|
|
createUser({ disabled: true }),
|
|
|
|
createManyCredentials(2),
|
|
|
|
createManyWorkflows(3, { active: true }),
|
|
|
|
]);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
workflowStatisticsRepository.insertWorkflowStatistics(
|
|
|
|
StatisticsNames.productionSuccess,
|
|
|
|
firstWorkflow.id,
|
|
|
|
),
|
|
|
|
workflowStatisticsRepository.insertWorkflowStatistics(
|
|
|
|
StatisticsNames.productionError,
|
|
|
|
firstWorkflow.id,
|
|
|
|
),
|
|
|
|
workflowStatisticsRepository.insertWorkflowStatistics(
|
|
|
|
StatisticsNames.manualSuccess,
|
|
|
|
secondWorkflow.id,
|
|
|
|
),
|
|
|
|
workflowStatisticsRepository.insertWorkflowStatistics(
|
|
|
|
StatisticsNames.manualError,
|
|
|
|
secondWorkflow.id,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
2024-07-15 03:42:49 -07:00
|
|
|
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
2024-01-22 03:29:28 -08:00
|
|
|
|
|
|
|
expect(metrics).toStrictEqual({
|
|
|
|
enabledUsers: 4,
|
2024-02-09 05:15:05 -08:00
|
|
|
totalUsers: 5,
|
2024-01-22 03:29:28 -08:00
|
|
|
totalCredentials: 2,
|
|
|
|
totalWorkflows: 5,
|
|
|
|
activeWorkflows: 3,
|
|
|
|
productionExecutions: 2,
|
|
|
|
manualExecutions: 2,
|
|
|
|
});
|
|
|
|
});
|
2024-01-26 08:50:19 -08:00
|
|
|
|
|
|
|
test('should handle zero execution statistics correctly', async () => {
|
|
|
|
await Promise.all([createOwner(), createManyWorkflows(3, { active: true })]);
|
|
|
|
|
2024-07-15 03:42:49 -07:00
|
|
|
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
2024-01-26 08:50:19 -08:00
|
|
|
|
|
|
|
expect(metrics).toStrictEqual({
|
|
|
|
enabledUsers: 1,
|
2024-02-09 05:15:05 -08:00
|
|
|
totalUsers: 1,
|
2024-01-26 08:50:19 -08:00
|
|
|
totalCredentials: 0,
|
|
|
|
totalWorkflows: 3,
|
|
|
|
activeWorkflows: 3,
|
|
|
|
productionExecutions: 0, // not NaN
|
|
|
|
manualExecutions: 0, // not NaN
|
|
|
|
});
|
|
|
|
});
|
2024-01-22 03:29:28 -08:00
|
|
|
});
|
|
|
|
});
|