first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import { createManyActiveWorkflows, createManyWorkflows, testDb } from '@n8n/backend-test-utils';
|
||||
import { StatisticsNames, LicenseMetricsRepository, WorkflowStatisticsRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
|
||||
import { createManyCredentials } from './shared/db/credentials';
|
||||
import { createAdmin, createMember, createOwner, createUser } from './shared/db/users';
|
||||
|
||||
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',
|
||||
'CredentialsEntity',
|
||||
'WorkflowEntity',
|
||||
'ExecutionEntity',
|
||||
'WorkflowStatistics',
|
||||
]);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
describe('getLicenseRenewalMetrics', () => {
|
||||
test('should return license renewal metrics', async () => {
|
||||
const [firstWorkflow, secondWorkflow] = await createManyWorkflows(2);
|
||||
|
||||
await Promise.all([
|
||||
createOwner(),
|
||||
createAdmin(),
|
||||
createMember(),
|
||||
createMember(),
|
||||
createUser({ disabled: true }),
|
||||
createManyCredentials(2),
|
||||
createManyActiveWorkflows(3),
|
||||
]);
|
||||
|
||||
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,
|
||||
),
|
||||
workflowStatisticsRepository.upsertWorkflowStatistics(
|
||||
StatisticsNames.productionSuccess,
|
||||
secondWorkflow.id,
|
||||
true,
|
||||
),
|
||||
]);
|
||||
|
||||
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
||||
|
||||
expect(metrics).toStrictEqual({
|
||||
enabledUsers: 4,
|
||||
totalUsers: 5,
|
||||
totalCredentials: 2,
|
||||
totalWorkflows: 5,
|
||||
activeWorkflows: 3,
|
||||
productionExecutions: 3,
|
||||
productionRootExecutions: 3,
|
||||
manualExecutions: 2,
|
||||
evaluations: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle zero execution statistics correctly', async () => {
|
||||
const owner = await createOwner();
|
||||
await createManyActiveWorkflows(3, {}, owner);
|
||||
|
||||
const metrics = await licenseMetricsRepository.getLicenseRenewalMetrics();
|
||||
|
||||
expect(metrics).toStrictEqual({
|
||||
enabledUsers: 1,
|
||||
totalUsers: 1,
|
||||
totalCredentials: 0,
|
||||
totalWorkflows: 3,
|
||||
activeWorkflows: 3,
|
||||
productionExecutions: 0, // not NaN
|
||||
productionRootExecutions: 0, // not NaN
|
||||
manualExecutions: 0, // not NaN
|
||||
evaluations: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user