Merge pull request #2055 from automatisch/rest-test-step

feat: Implement rest api endpoint to test step
This commit is contained in:
Ömer Faruk Aydın
2024-09-02 15:22:10 +03:00
committed by GitHub
9 changed files with 303 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import Telemetry from '../helpers/telemetry/index.js';
import appConfig from '../config/app.js';
import globalVariable from '../helpers/global-variable.js';
import computeParameters from '../helpers/compute-parameters.js';
import testRun from '../services/test-run.js';
class Step extends Base {
static tableName = 'steps';
@@ -59,6 +60,17 @@ class Step extends Base {
to: 'connections.id',
},
},
lastExecutionStep: {
relation: Base.HasOneRelation,
modelClass: ExecutionStep,
join: {
from: 'steps.id',
to: 'execution_steps.step_id',
},
filter(builder) {
builder.orderBy('created_at', 'desc').limit(1).first();
},
},
executionSteps: {
relation: Base.HasManyRelation,
modelClass: ExecutionStep,
@@ -145,6 +157,16 @@ class Step extends Base {
return await App.findOneByKey(this.appKey);
}
async test() {
await testRun({ stepId: this.id });
const updatedStep = await this.$query()
.withGraphFetched('lastExecutionStep')
.patchAndFetch({ status: 'completed' });
return updatedStep;
}
async getLastExecutionStep() {
const lastExecutionStep = await this.$relatedQuery('executionSteps')
.orderBy('created_at', 'desc')