Fix case where if a binding returned an int it would throw an error.
This commit is contained in:
parent
72d63d0c00
commit
b3c949b091
|
@ -44,4 +44,12 @@ describe("Attempt to run a basic loop automation", () => {
|
||||||
})
|
})
|
||||||
expect(resp.steps[2].outputs.iterations).toBe(3)
|
expect(resp.steps[2].outputs.iterations).toBe(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("test a loop with a binding that returns an integer", async () => {
|
||||||
|
const resp = await runLoop({
|
||||||
|
option: LoopStepType.ARRAY,
|
||||||
|
binding: "{{ 1 }}",
|
||||||
|
})
|
||||||
|
expect(resp.steps[2].outputs.iterations).toBe(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -43,20 +43,18 @@ const CRON_STEP_ID = triggerDefs.CRON.stepId
|
||||||
const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
|
const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
|
||||||
|
|
||||||
function getLoopIterations(loopStep: LoopStep) {
|
function getLoopIterations(loopStep: LoopStep) {
|
||||||
let binding = loopStep.inputs.binding
|
const binding = loopStep.inputs.binding
|
||||||
if (!binding) {
|
if (!binding) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (typeof binding === "string") {
|
const json = typeof binding === "string" ? JSON.parse(binding) : binding
|
||||||
binding = JSON.parse(binding)
|
if (Array.isArray(json)) {
|
||||||
|
return json.length
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// ignore error - wasn't able to parse
|
// ignore error - wasn't able to parse
|
||||||
}
|
}
|
||||||
if (Array.isArray(binding)) {
|
|
||||||
return binding.length
|
|
||||||
}
|
|
||||||
if (typeof binding === "string") {
|
if (typeof binding === "string") {
|
||||||
return automationUtils.stringSplit(binding).length
|
return automationUtils.stringSplit(binding).length
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue