Merge pull request #3007 from Budibase/fix/3005

Fixing issues with filter step in automations breaking test flow
This commit is contained in:
Michael Drury 2021-10-15 14:03:52 +01:00 committed by GitHub
commit 5e16f65d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 11 deletions

View File

@ -103,7 +103,7 @@
<Detail size="S">{block?.name?.toUpperCase() || ""}</Detail> <Detail size="S">{block?.name?.toUpperCase() || ""}</Detail>
</div> </div>
</div> </div>
{#if testResult} {#if testResult && testResult[0]}
<span on:click={() => resultsModal.show()}> <span on:click={() => resultsModal.show()}>
<StatusLight <StatusLight
positive={isTrigger || testResult[0].outputs?.success} positive={isTrigger || testResult[0].outputs?.success}

View File

@ -10,6 +10,7 @@ const env = require("../environment")
const usage = require("../utilities/usageQuota") const usage = require("../utilities/usageQuota")
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
const STOPPED_STATUS = { success: false, status: "STOPPED" }
/** /**
* The automation orchestrator is a class responsible for executing automations. * The automation orchestrator is a class responsible for executing automations.
@ -68,7 +69,13 @@ class Orchestrator {
async execute() { async execute() {
let automation = this._automation let automation = this._automation
const app = await this.getApp() const app = await this.getApp()
let stopped = false
for (let step of automation.definition.steps) { for (let step of automation.definition.steps) {
// execution stopped, record state for that
if (stopped) {
this.updateExecutionOutput(step.id, step.stepId, {}, STOPPED_STATUS)
continue
}
let stepFn = await this.getStepFunctionality(step.stepId) let stepFn = await this.getStepFunctionality(step.stepId)
step.inputs = await processObject(step.inputs, this._context) step.inputs = await processObject(step.inputs, this._context)
step.inputs = automationUtils.cleanInputValues( step.inputs = automationUtils.cleanInputValues(
@ -86,10 +93,17 @@ class Orchestrator {
context: this._context, context: this._context,
}) })
}) })
if (step.stepId === FILTER_STEP_ID && !outputs.success) {
break
}
this._context.steps.push(outputs) this._context.steps.push(outputs)
// if filter causes us to stop execution don't break the loop, set a var
// so that we can finish iterating through the steps and record that it stopped
if (step.stepId === FILTER_STEP_ID && !outputs.success) {
stopped = true
this.updateExecutionOutput(step.id, step.stepId, step.inputs, {
...outputs,
...STOPPED_STATUS,
})
continue
}
this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs) this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs)
} catch (err) { } catch (err) {
console.error(`Automation error - ${step.stepId} - ${err}`) console.error(`Automation error - ${step.stepId} - ${err}`)
@ -99,7 +113,7 @@ class Orchestrator {
// Increment quota for automation runs // Increment quota for automation runs
if (!env.SELF_HOSTED && !isDevAppID(this._appId)) { if (!env.SELF_HOSTED && !isDevAppID(this._appId)) {
usage.update(usage.Properties.AUTOMATION, 1) await usage.update(usage.Properties.AUTOMATION, 1)
} }
return this.executionOutput return this.executionOutput
} }

View File

@ -27,7 +27,7 @@ describe("MongoDB Integration", () => {
const body = { const body = {
name: "Hello" name: "Hello"
} }
const response = await config.integration.create({ await config.integration.create({
index: indexName, index: indexName,
json: body, json: body,
extra: { collection: 'testCollection', actionTypes: 'insertOne'} extra: { collection: 'testCollection', actionTypes: 'insertOne'}
@ -54,7 +54,7 @@ describe("MongoDB Integration", () => {
}, },
extra: { collection: 'testCollection', actionTypes: 'deleteOne'} extra: { collection: 'testCollection', actionTypes: 'deleteOne'}
} }
const response = await config.integration.delete(query) await config.integration.delete(query)
expect(config.integration.client.deleteOne).toHaveBeenCalledWith(query.json) expect(config.integration.client.deleteOne).toHaveBeenCalledWith(query.json)
}) })
@ -65,7 +65,7 @@ describe("MongoDB Integration", () => {
}, },
extra: { collection: 'testCollection', actionTypes: 'updateOne'} extra: { collection: 'testCollection', actionTypes: 'updateOne'}
} }
const response = await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalledWith(query.json) expect(config.integration.client.updateOne).toHaveBeenCalledWith(query.json)
}) })
@ -75,10 +75,14 @@ describe("MongoDB Integration", () => {
const query = { const query = {
extra: { collection: 'testCollection', actionTypes: 'deleteOne'} extra: { collection: 'testCollection', actionTypes: 'deleteOne'}
} }
// Weird, need to do an IIFE for jest to recognize that it throws
expect(() => config.integration.read(query)()).toThrow(expect.any(Object))
let error = null
try {
await config.integration.read(query)
} catch (err) {
error = err
}
expect(error).toBeDefined()
restore() restore()
}) })
}) })