Merge pull request #1693 from automatisch/refactor-get-executions-tests

refactor: Add steps to get execution tests
This commit is contained in:
Ömer Faruk Aydın
2024-03-04 16:23:09 +01:00
committed by GitHub
2 changed files with 37 additions and 3 deletions

View File

@@ -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);

View File

@@ -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,
})),
},
};