mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import Container from 'typedi';
|
|
|
|
import { StatisticsNames } from '@/databases/entities/workflow-statistics';
|
|
import { LicenseMetricsRepository } from '@/databases/repositories/license-metrics.repository';
|
|
import { WorkflowStatisticsRepository } from '@/databases/repositories/workflow-statistics.repository';
|
|
|
|
import { createManyCredentials } from './shared/db/credentials';
|
|
import { createAdmin, createMember, createOwner, createUser } from './shared/db/users';
|
|
import { createManyWorkflows } from './shared/db/workflows';
|
|
import * as testDb from './shared/test-db';
|
|
|
|
describe('LicenseMetricsRepository', () => {
|
|
let licenseMetricsRepository: LicenseMetricsRepository;
|
|
let workflowStatisticsRepository: WorkflowStatisticsRepository;
|
|
|
|
beforeAll(async () => {
|
|
await testDb.init();
|
|
|
|
licenseMetricsRepository = Container.get(LicenseMetricsRepository);
|
|
|
|
workflowStatisticsRepository = Container.get(WorkflowStatisticsRepository);
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await testDb.truncate(['User', 'Credentials', 'Workflow', 'Execution', 'WorkflowStatistics']);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await testDb.terminate();
|
|
});
|
|
|
|
describe('getLicenseRenewalMetrics', () => {
|
|
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,
|
|
),
|
|
]);
|
|
|
|
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
|
|
|
expect(metrics).toStrictEqual({
|
|
enabledUsers: 4,
|
|
totalUsers: 5,
|
|
totalCredentials: 2,
|
|
totalWorkflows: 5,
|
|
activeWorkflows: 3,
|
|
productionExecutions: 2,
|
|
manualExecutions: 2,
|
|
});
|
|
});
|
|
|
|
test('should handle zero execution statistics correctly', async () => {
|
|
await Promise.all([createOwner(), createManyWorkflows(3, { active: true })]);
|
|
|
|
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
|
|
|
expect(metrics).toStrictEqual({
|
|
enabledUsers: 1,
|
|
totalUsers: 1,
|
|
totalCredentials: 0,
|
|
totalWorkflows: 3,
|
|
activeWorkflows: 3,
|
|
productionExecutions: 0, // not NaN
|
|
manualExecutions: 0, // not NaN
|
|
});
|
|
});
|
|
});
|
|
});
|