tests: Implement tests for ExecutionStep model

This commit is contained in:
Faruk AYDIN
2024-10-09 13:06:43 +02:00
parent f24ff606ac
commit f6490990de
3 changed files with 229 additions and 12 deletions

View File

@@ -47,21 +47,31 @@ class ExecutionStep extends Base {
return this.status === 'failure';
}
async isNormalSucceededRun() {
const execution = await this.$relatedQuery('execution');
return !execution.testRun && !this.isFailed;
}
async updateUsageData() {
const execution = await this.$relatedQuery('execution');
const flow = await execution.$relatedQuery('flow');
const user = await flow.$relatedQuery('user');
const usageData = await user.$relatedQuery('currentUsageData');
await usageData.increaseConsumedTaskCountByOne();
}
async increaseUsageCount() {
if (appConfig.isCloud && this.isNormalSucceededRun()) {
await this.updateUsageData();
}
}
async $afterInsert(queryContext) {
await super.$afterInsert(queryContext);
Telemetry.executionStepCreated(this);
if (appConfig.isCloud) {
const execution = await this.$relatedQuery('execution');
if (!execution.testRun && !this.isFailed) {
const flow = await execution.$relatedQuery('flow');
const user = await flow.$relatedQuery('user');
const usageData = await user.$relatedQuery('currentUsageData');
await usageData.increaseConsumedTaskCountByOne();
}
}
await this.increaseUsageCount();
}
}