refactor: Implement test run helper to work with services

This commit is contained in:
Faruk AYDIN
2022-10-14 20:18:58 +02:00
parent 56a9aeece7
commit 628f872180
11 changed files with 262 additions and 119 deletions

View File

@@ -0,0 +1,55 @@
import Step from '../models/step';
import Flow from '../models/flow';
import Execution from '../models/execution';
import ExecutionStep from '../models/execution-step';
import computeParameters from '../helpers/compute-parameters';
import globalVariable from '../helpers/global-variable';
type ProcessActionOptions = {
flowId: string;
executionId: string;
stepId: string;
};
export const processAction = async (options: ProcessActionOptions) => {
const { flowId, stepId, executionId } = options;
const step = await Step.query().findById(stepId).throwIfNotFound();
const execution = await Execution.query()
.findById(executionId)
.throwIfNotFound();
const $ = await globalVariable({
flow: await Flow.query().findById(flowId).throwIfNotFound(),
app: await step.getApp(),
step: step,
connection: await step.$relatedQuery('connection'),
execution: execution,
});
const priorExecutionSteps = await ExecutionStep.query().where({
execution_id: $.execution.id,
});
const computedParameters = computeParameters(
$.step.parameters,
priorExecutionSteps
);
const actionCommand = await step.getActionCommand();
$.step.parameters = computedParameters;
const actionOutput = await actionCommand.run($);
const executionStep = await execution
.$relatedQuery('executionSteps')
.insertAndFetch({
stepId: $.step.id,
status: actionOutput.error ? 'failure' : 'success',
dataIn: computedParameters,
dataOut: actionOutput.error ? null : actionOutput.data.raw,
errorDetails: actionOutput.error,
});
return { flowId, stepId, executionId, executionStep };
};