mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
wip: test-runs controller
This commit is contained in:
parent
11f9212eda
commit
5e179b6a13
|
@ -13,7 +13,7 @@ export declare namespace TestDefinitionsRequest {
|
||||||
|
|
||||||
type GetOne = AuthenticatedRequest<RouteParams.TestId>;
|
type GetOne = AuthenticatedRequest<RouteParams.TestId>;
|
||||||
|
|
||||||
type GetMany = AuthenticatedRequest<{}, {}, {}, ListQuery.Params & { includeScopes?: string }> & {
|
type GetMany = AuthenticatedRequest<{}, {}, {}, ListQuery.Params> & {
|
||||||
listQueryOptions: ListQuery.Options;
|
listQueryOptions: ListQuery.Options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,3 +63,27 @@ export declare namespace TestMetricsRequest {
|
||||||
|
|
||||||
type Delete = AuthenticatedRequest<RouteParams.TestDefinitionId & RouteParams.TestMetricId>;
|
type Delete = AuthenticatedRequest<RouteParams.TestDefinitionId & RouteParams.TestMetricId>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// /test-definitions/:testDefinitionId/runs
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
export declare namespace TestRunsRequest {
|
||||||
|
namespace RouteParams {
|
||||||
|
type TestId = {
|
||||||
|
testDefinitionId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type TestRunId = {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetMany = AuthenticatedRequest<RouteParams.TestId, {}, {}, ListQuery.Params> & {
|
||||||
|
listQueryOptions: ListQuery.Options;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GetOne = AuthenticatedRequest<RouteParams.TestId & RouteParams.TestRunId>;
|
||||||
|
|
||||||
|
type Delete = AuthenticatedRequest<RouteParams.TestId & RouteParams.TestRunId>;
|
||||||
|
}
|
||||||
|
|
77
packages/cli/src/evaluation/test-runs.controlller.ee.ts
Normal file
77
packages/cli/src/evaluation/test-runs.controlller.ee.ts
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import { TestRunRepository } from '@/databases/repositories/test-run.repository.ee';
|
||||||
|
import { Delete, Get, RestController } from '@/decorators';
|
||||||
|
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||||
|
import { TestRunsRequest } from '@/evaluation/test-definitions.types.ee';
|
||||||
|
import { getSharedWorkflowIds } from '@/public-api/v1/handlers/workflows/workflows.service';
|
||||||
|
|
||||||
|
import { TestDefinitionService } from './test-definition.service.ee';
|
||||||
|
|
||||||
|
@RestController('/evaluation/test-definitions')
|
||||||
|
export class TestRunsController {
|
||||||
|
constructor(
|
||||||
|
private readonly testDefinitionService: TestDefinitionService,
|
||||||
|
private readonly testRunRepository: TestRunRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
// This method is used in multiple places in the controller to get the test definition
|
||||||
|
// (or just check that it exists and the user has access to it).
|
||||||
|
private async getTestDefinition(
|
||||||
|
req: TestRunsRequest.GetOne | TestRunsRequest.GetMany | TestRunsRequest.Delete,
|
||||||
|
) {
|
||||||
|
const { testDefinitionId } = req.params;
|
||||||
|
|
||||||
|
const userAccessibleWorkflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
|
||||||
|
|
||||||
|
const testDefinition = await this.testDefinitionService.findOne(
|
||||||
|
testDefinitionId,
|
||||||
|
userAccessibleWorkflowIds,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!testDefinition) throw new NotFoundError('Test definition not found');
|
||||||
|
|
||||||
|
return testDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('/:testDefinitionId/runs')
|
||||||
|
async getMany(req: TestRunsRequest.GetMany) {
|
||||||
|
const { testDefinitionId } = req.params;
|
||||||
|
|
||||||
|
await this.getTestDefinition(req);
|
||||||
|
|
||||||
|
return await this.testRunRepository.find({
|
||||||
|
where: { testDefinition: { id: testDefinitionId } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('/:testDefinitionId/runs/:id')
|
||||||
|
async getOne(req: TestRunsRequest.GetOne) {
|
||||||
|
const { id: testRunId, testDefinitionId } = req.params;
|
||||||
|
|
||||||
|
await this.getTestDefinition(req);
|
||||||
|
|
||||||
|
const testRun = await this.testRunRepository.findOne({
|
||||||
|
where: { id: testRunId, testDefinition: { id: testDefinitionId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!testRun) throw new NotFoundError('Test run not found');
|
||||||
|
|
||||||
|
return testRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete('/:testDefinitionId/runs/:id')
|
||||||
|
async delete(req: TestRunsRequest.GetOne) {
|
||||||
|
const { id: testRunId, testDefinitionId } = req.params;
|
||||||
|
|
||||||
|
await this.getTestDefinition(req);
|
||||||
|
|
||||||
|
const testRun = await this.testRunRepository.findOne({
|
||||||
|
where: { id: testRunId, testDefinition: { id: testDefinitionId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!testRun) throw new NotFoundError('Test run not found');
|
||||||
|
|
||||||
|
await this.testRunRepository.delete({ id: testRunId });
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,6 +65,7 @@ import '@/external-secrets/external-secrets.controller.ee';
|
||||||
import '@/license/license.controller';
|
import '@/license/license.controller';
|
||||||
import '@/evaluation/test-definitions.controller.ee';
|
import '@/evaluation/test-definitions.controller.ee';
|
||||||
import '@/evaluation/metrics.controller';
|
import '@/evaluation/metrics.controller';
|
||||||
|
import '@/evaluation/test-runs.controlller.ee';
|
||||||
import '@/workflows/workflow-history/workflow-history.controller.ee';
|
import '@/workflows/workflow-history/workflow-history.controller.ee';
|
||||||
import '@/workflows/workflows.controller';
|
import '@/workflows/workflows.controller';
|
||||||
|
|
||||||
|
|
|
@ -281,6 +281,7 @@ export const setupTestServer = ({
|
||||||
case 'evaluation':
|
case 'evaluation':
|
||||||
await import('@/evaluation/metrics.controller');
|
await import('@/evaluation/metrics.controller');
|
||||||
await import('@/evaluation/test-definitions.controller.ee');
|
await import('@/evaluation/test-definitions.controller.ee');
|
||||||
|
await import('@/evaluation/test-runs.controlller.ee');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue