feat(api): add get execution endpoint
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import Execution from '../../../../models/execution.js';
|
||||||
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
|
|
||||||
|
export default async (request, response) => {
|
||||||
|
const execution = await Execution.query()
|
||||||
|
.withGraphFetched({
|
||||||
|
flow: {
|
||||||
|
steps: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.withSoftDeleted()
|
||||||
|
.findById(request.params.executionId)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
renderObject(response, execution);
|
||||||
|
};
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import Crypto from 'node:crypto';
|
||||||
|
import request from 'supertest';
|
||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import { createApiToken } from '../../../../../test/factories/api-token.js';
|
||||||
|
import { createExecution } from '../../../../../test/factories/execution.js';
|
||||||
|
import { createFlow } from '../../../../../test/factories/flow.js';
|
||||||
|
import { createStep } from '../../../../../test/factories/step.js';
|
||||||
|
import getExecutionMock from '../../../../../test/mocks/rest/api/v1/executions/get-execution.js';
|
||||||
|
import app from '../../../../app.js';
|
||||||
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/executions/:executionId', () => {
|
||||||
|
let token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
token = (await createApiToken()).token;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the execution data', async () => {
|
||||||
|
const flow = await createFlow();
|
||||||
|
|
||||||
|
const stepOne = await createStep({
|
||||||
|
flowId: flow.id,
|
||||||
|
type: 'trigger',
|
||||||
|
});
|
||||||
|
|
||||||
|
const stepTwo = await createStep({
|
||||||
|
flowId: flow.id,
|
||||||
|
type: 'action',
|
||||||
|
});
|
||||||
|
|
||||||
|
const execution = await createExecution({
|
||||||
|
flowId: flow.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/executions/${execution.id}`)
|
||||||
|
.set('x-api-token', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = await getExecutionMock(execution, flow, [
|
||||||
|
stepOne,
|
||||||
|
stepTwo,
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(response.body).toStrictEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return not found response for not existing execution UUID', async () => {
|
||||||
|
const notExistingExcecutionUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
|
await request(app)
|
||||||
|
.get(`/api/v1/executions/${notExistingExcecutionUUID}`)
|
||||||
|
.set('x-api-token', token)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return bad request response for invalid UUID', async () => {
|
||||||
|
await request(app)
|
||||||
|
.get('/api/v1/executions/invalidExecutionUUID')
|
||||||
|
.set('x-api-token', token)
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import getExecutionsAction from '../../../controllers/api/v1/executions/get-executions.ee.js';
|
import getExecutionsAction from '../../../controllers/api/v1/executions/get-executions.ee.js';
|
||||||
|
import getExecutionAction from '../../../controllers/api/v1/executions/get-execution.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/', getExecutionsAction);
|
router.get('/', getExecutionsAction);
|
||||||
|
router.get('/:executionId', getExecutionAction);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
const getExecutionMock = async (execution, flow, steps) => {
|
||||||
|
const data = {
|
||||||
|
id: execution.id,
|
||||||
|
testRun: execution.testRun,
|
||||||
|
status: execution.status,
|
||||||
|
createdAt: execution.createdAt.getTime(),
|
||||||
|
updatedAt: execution.updatedAt.getTime(),
|
||||||
|
flow: {
|
||||||
|
id: flow.id,
|
||||||
|
name: flow.name,
|
||||||
|
active: flow.active,
|
||||||
|
status: flow.active ? 'published' : 'draft',
|
||||||
|
createdAt: flow.createdAt.getTime(),
|
||||||
|
updatedAt: flow.updatedAt.getTime(),
|
||||||
|
steps: steps.map((step) => ({
|
||||||
|
id: step.id,
|
||||||
|
type: step.type,
|
||||||
|
key: step.key,
|
||||||
|
name: step.name,
|
||||||
|
appKey: step.appKey,
|
||||||
|
iconUrl: step.iconUrl,
|
||||||
|
webhookUrl: step.webhookUrl,
|
||||||
|
status: step.status,
|
||||||
|
position: step.position,
|
||||||
|
parameters: step.parameters,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: data,
|
||||||
|
meta: {
|
||||||
|
count: 1,
|
||||||
|
currentPage: null,
|
||||||
|
isArray: false,
|
||||||
|
totalPages: null,
|
||||||
|
type: 'Execution',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getExecutionMock;
|
||||||
@@ -29,7 +29,7 @@ export default defineConfig({
|
|||||||
thresholds: {
|
thresholds: {
|
||||||
autoUpdate: true,
|
autoUpdate: true,
|
||||||
statements: 99.4,
|
statements: 99.4,
|
||||||
branches: 98.31,
|
branches: 98.32,
|
||||||
functions: 99.05,
|
functions: 99.05,
|
||||||
lines: 99.4,
|
lines: 99.4,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user