From 9a0aef9d9b98b176509399e63263d66becc3b642 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 19 Mar 2025 17:09:36 +0100 Subject: [PATCH] feat: Use status directly from executions --- .../api/v1/executions/get-executions.js | 9 --------- .../models/__snapshots__/execution.test.js.snap | 7 +++++++ packages/backend/src/models/execution.js | 1 + packages/backend/src/serializers/execution.js | 1 + .../backend/src/serializers/execution.test.js | 15 +-------------- packages/backend/test/factories/execution.js | 1 + .../mocks/rest/api/v1/executions/get-execution.js | 1 + 7 files changed, 12 insertions(+), 23 deletions(-) diff --git a/packages/backend/src/controllers/api/v1/executions/get-executions.js b/packages/backend/src/controllers/api/v1/executions/get-executions.js index bb4ca70e..7d86c789 100644 --- a/packages/backend/src/controllers/api/v1/executions/get-executions.js +++ b/packages/backend/src/controllers/api/v1/executions/get-executions.js @@ -14,14 +14,5 @@ export default async (request, response) => { const executions = await paginateRest(executionsQuery, request.query.page); - for (const execution of executions.records) { - const executionSteps = await execution.$relatedQuery('executionSteps'); - const status = executionSteps.some((step) => step.status === 'failure') - ? 'failure' - : 'success'; - - execution.status = status; - } - renderObject(response, executions); }; diff --git a/packages/backend/src/models/__snapshots__/execution.test.js.snap b/packages/backend/src/models/__snapshots__/execution.test.js.snap index ba4d99cd..9b8ab3f9 100644 --- a/packages/backend/src/models/__snapshots__/execution.test.js.snap +++ b/packages/backend/src/models/__snapshots__/execution.test.js.snap @@ -20,6 +20,13 @@ exports[`Execution model > jsonSchema should have correct validations 1`] = ` "internalId": { "type": "string", }, + "status": { + "enum": [ + "success", + "failure", + ], + "type": "string", + }, "testRun": { "default": false, "type": "boolean", diff --git a/packages/backend/src/models/execution.js b/packages/backend/src/models/execution.js index 9b219700..c8481366 100644 --- a/packages/backend/src/models/execution.js +++ b/packages/backend/src/models/execution.js @@ -14,6 +14,7 @@ class Execution extends Base { flowId: { type: 'string', format: 'uuid' }, testRun: { type: 'boolean', default: false }, internalId: { type: 'string' }, + status: { type: 'string', enum: ['success', 'failure'] }, deletedAt: { type: 'string' }, createdAt: { type: 'string' }, updatedAt: { type: 'string' }, diff --git a/packages/backend/src/serializers/execution.js b/packages/backend/src/serializers/execution.js index db57d159..d008707f 100644 --- a/packages/backend/src/serializers/execution.js +++ b/packages/backend/src/serializers/execution.js @@ -4,6 +4,7 @@ const executionSerializer = (execution) => { let executionData = { id: execution.id, testRun: execution.testRun, + status: execution.status, createdAt: execution.createdAt.getTime(), updatedAt: execution.updatedAt.getTime(), }; diff --git a/packages/backend/src/serializers/execution.test.js b/packages/backend/src/serializers/execution.test.js index 0e28e775..f4a7537b 100644 --- a/packages/backend/src/serializers/execution.test.js +++ b/packages/backend/src/serializers/execution.test.js @@ -19,6 +19,7 @@ describe('executionSerializer', () => { const expectedPayload = { id: execution.id, testRun: execution.testRun, + status: execution.status, createdAt: execution.createdAt.getTime(), updatedAt: execution.updatedAt.getTime(), }; @@ -26,20 +27,6 @@ describe('executionSerializer', () => { expect(executionSerializer(execution)).toStrictEqual(expectedPayload); }); - it('should return the execution data with status', async () => { - execution.status = 'success'; - - const expectedPayload = { - id: execution.id, - testRun: execution.testRun, - createdAt: execution.createdAt.getTime(), - updatedAt: execution.updatedAt.getTime(), - status: 'success', - }; - - expect(executionSerializer(execution)).toStrictEqual(expectedPayload); - }); - it('should return the execution data with the flow', async () => { execution.flow = flow; diff --git a/packages/backend/test/factories/execution.js b/packages/backend/test/factories/execution.js index 22ad2b7d..2d84009a 100644 --- a/packages/backend/test/factories/execution.js +++ b/packages/backend/test/factories/execution.js @@ -4,6 +4,7 @@ import { createFlow } from './flow'; export const createExecution = async (params = {}) => { params.flowId = params?.flowId || (await createFlow()).id; params.testRun = params?.testRun || false; + params.status = params?.status || 'success'; const execution = await Execution.query().insertAndFetch(params); diff --git a/packages/backend/test/mocks/rest/api/v1/executions/get-execution.js b/packages/backend/test/mocks/rest/api/v1/executions/get-execution.js index 61feddd8..667b8940 100644 --- a/packages/backend/test/mocks/rest/api/v1/executions/get-execution.js +++ b/packages/backend/test/mocks/rest/api/v1/executions/get-execution.js @@ -2,6 +2,7 @@ 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: {