Files
alighasami 3d5eaf9445
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
first commit
2026-03-17 16:22:57 +03:30

72 lines
1.9 KiB
TypeScript

import { TestRunRepository, TestCaseExecutionRepository } from '@n8n/db';
import type {
TestRun,
TestCaseExecution,
AggregatedTestRunMetrics,
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);
};