From 1cb48c776073334491b8594c5c66e08268917c95 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Mon, 4 Mar 2024 16:12:02 +0100 Subject: [PATCH] refactor: Add steps to get execution tests --- .../api/v1/executions/get-execution.test.js | 27 +++++++++++++++++-- .../rest/api/v1/executions/get-execution.js | 13 ++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/controllers/api/v1/executions/get-execution.test.js b/packages/backend/src/controllers/api/v1/executions/get-execution.test.js index 47473d90..edf59644 100644 --- a/packages/backend/src/controllers/api/v1/executions/get-execution.test.js +++ b/packages/backend/src/controllers/api/v1/executions/get-execution.test.js @@ -5,6 +5,7 @@ import app from '../../../../app.js'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id'; import { createUser } from '../../../../../test/factories/user'; import { createFlow } from '../../../../../test/factories/flow.js'; +import { createStep } from '../../../../../test/factories/step.js'; import { createExecution } from '../../../../../test/factories/execution.js'; import { createPermission } from '../../../../../test/factories/permission'; import getExecutionMock from '../../../../../test/mocks/rest/api/v1/executions/get-execution'; @@ -24,6 +25,16 @@ describe('GET /api/v1/executions/:executionId', () => { userId: currentUser.id, }); + const stepOne = await createStep({ + flowId: currentUserFlow.id, + type: 'trigger', + }); + + const stepTwo = await createStep({ + flowId: currentUserFlow.id, + type: 'action', + }); + const currentUserExecution = await createExecution({ flowId: currentUserFlow.id, }); @@ -42,7 +53,8 @@ describe('GET /api/v1/executions/:executionId', () => { const expectedPayload = await getExecutionMock( currentUserExecution, - currentUserFlow + currentUserFlow, + [stepOne, stepTwo] ); expect(response.body).toEqual(expectedPayload); @@ -55,6 +67,16 @@ describe('GET /api/v1/executions/:executionId', () => { userId: anotherUser.id, }); + const stepOne = await createStep({ + flowId: anotherUserFlow.id, + type: 'trigger', + }); + + const stepTwo = await createStep({ + flowId: anotherUserFlow.id, + type: 'action', + }); + const anotherUserExecution = await createExecution({ flowId: anotherUserFlow.id, }); @@ -73,7 +95,8 @@ describe('GET /api/v1/executions/:executionId', () => { const expectedPayload = await getExecutionMock( anotherUserExecution, - anotherUserFlow + anotherUserFlow, + [stepOne, stepTwo] ); expect(response.body).toEqual(expectedPayload); 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 bf823ded..5346ea54 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 @@ -1,4 +1,4 @@ -const getExecutionMock = async (execution, flow) => { +const getExecutionMock = async (execution, flow, steps) => { const data = { id: execution.id, testRun: execution.testRun, @@ -9,6 +9,17 @@ const getExecutionMock = async (execution, flow) => { name: flow.name, active: flow.active, status: flow.active ? 'published' : 'draft', + steps: steps.map((step) => ({ + id: step.id, + type: step.type, + key: step.key, + appKey: step.appKey, + iconUrl: step.iconUrl, + webhookUrl: step.webhookUrl, + status: step.status, + position: step.position, + parameters: step.parameters, + })), }, };