Fix loops being given empty strings.
This commit is contained in:
parent
406c60c973
commit
4092f4c3e1
|
@ -7,6 +7,8 @@ import {
|
||||||
CreateRowStepOutputs,
|
CreateRowStepOutputs,
|
||||||
FieldType,
|
FieldType,
|
||||||
FilterCondition,
|
FilterCondition,
|
||||||
|
AutomationStatus,
|
||||||
|
AutomationStepStatus,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
@ -560,5 +562,25 @@ describe("Attempt to run a basic loop automation", () => {
|
||||||
status: "stopped",
|
status: "stopped",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should not fail if queryRows returns nothing", async () => {
|
||||||
|
const table = await config.api.table.save(basicTable())
|
||||||
|
const results = await createAutomationBuilder(config)
|
||||||
|
.onAppAction()
|
||||||
|
.queryRows({
|
||||||
|
tableId: table._id!,
|
||||||
|
})
|
||||||
|
.loop({
|
||||||
|
option: LoopStepType.ARRAY,
|
||||||
|
binding: "{{ steps.1.rows }}",
|
||||||
|
})
|
||||||
|
.serverLog({ text: "Message {{loop.currentItem}}" })
|
||||||
|
.test({ fields: {} })
|
||||||
|
|
||||||
|
expect(results.steps[1].outputs.success).toBe(true)
|
||||||
|
expect(results.steps[1].outputs.status).toBe(
|
||||||
|
AutomationStepStatus.NO_ITERATIONS
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -68,7 +68,11 @@ function getLoopIterable(step: LoopStep): any[] {
|
||||||
let input = step.inputs.binding
|
let input = step.inputs.binding
|
||||||
|
|
||||||
if (option === LoopStepType.ARRAY && typeof input === "string") {
|
if (option === LoopStepType.ARRAY && typeof input === "string") {
|
||||||
input = JSON.parse(input)
|
if (input === "") {
|
||||||
|
input = []
|
||||||
|
} else {
|
||||||
|
input = JSON.parse(input)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option === LoopStepType.STRING && Array.isArray(input)) {
|
if (option === LoopStepType.STRING && Array.isArray(input)) {
|
||||||
|
@ -492,7 +496,7 @@ class Orchestrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
const status =
|
const status =
|
||||||
iterations === 0 ? AutomationStatus.NO_CONDITION_MET : undefined
|
iterations === 0 ? AutomationStepStatus.NO_ITERATIONS : undefined
|
||||||
return stepSuccess(stepToLoop, { status, iterations, items })
|
return stepSuccess(stepToLoop, { status, iterations, items })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue