mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Evaluations backend (no-changelog) (#15542)
Co-authored-by: Yiorgis Gozadinos <yiorgis@n8n.io> Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com>
This commit is contained in:
68
packages/cli/test/integration/shared/db/evaluation.ts
Normal file
68
packages/cli/test/integration/shared/db/evaluation.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { TestRunRepository, TestCaseExecutionRepository } from '@n8n/db';
|
||||
import type { TestRun } from '@n8n/db';
|
||||
import type { TestCaseExecution } from '@n8n/db';
|
||||
import type { AggregatedTestRunMetrics } from '@n8n/db';
|
||||
import type { TestCaseExecutionErrorCode, TestRunErrorCode } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Creates a test run for a workflow
|
||||
*/
|
||||
export const createTestRun = async (
|
||||
workflowId: string,
|
||||
options: {
|
||||
status?: TestRun['status'];
|
||||
runAt?: Date | null;
|
||||
completedAt?: Date | null;
|
||||
metrics?: AggregatedTestRunMetrics;
|
||||
errorCode?: TestRunErrorCode;
|
||||
errorDetails?: IDataObject;
|
||||
} = {},
|
||||
) => {
|
||||
const testRunRepository = Container.get(TestRunRepository);
|
||||
|
||||
const testRun = testRunRepository.create({
|
||||
workflow: { id: workflowId },
|
||||
status: options.status ?? 'new',
|
||||
runAt: options.runAt ?? null,
|
||||
completedAt: options.completedAt ?? null,
|
||||
metrics: options.metrics ?? {},
|
||||
errorCode: options.errorCode,
|
||||
errorDetails: options.errorDetails,
|
||||
});
|
||||
|
||||
return await testRunRepository.save(testRun);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a test case execution for a test run
|
||||
*/
|
||||
export const createTestCaseExecution = async (
|
||||
testRunId: string,
|
||||
options: {
|
||||
status?: TestCaseExecution['status'];
|
||||
runAt?: Date | null;
|
||||
completedAt?: Date | null;
|
||||
metrics?: Record<string, number>;
|
||||
errorCode?: TestCaseExecutionErrorCode;
|
||||
errorDetails?: IDataObject;
|
||||
executionId?: string;
|
||||
pastExecutionId?: string;
|
||||
} = {},
|
||||
) => {
|
||||
const testCaseExecutionRepository = Container.get(TestCaseExecutionRepository);
|
||||
|
||||
const testCaseExecution = testCaseExecutionRepository.create({
|
||||
testRun: { id: testRunId },
|
||||
status: options.status ?? 'success',
|
||||
runAt: options.runAt ?? null,
|
||||
completedAt: options.completedAt ?? null,
|
||||
metrics: options.metrics ?? {},
|
||||
errorCode: options.errorCode,
|
||||
errorDetails: options.errorDetails,
|
||||
executionId: options.executionId,
|
||||
});
|
||||
|
||||
return await testCaseExecutionRepository.save(testCaseExecution);
|
||||
};
|
||||
Reference in New Issue
Block a user