1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Fix case where if a binding returned an int it would throw an error.

This commit is contained in:
Sam Rose 2024-01-30 11:06:09 +00:00
parent 72d63d0c00
commit b3c949b091
No known key found for this signature in database
2 changed files with 12 additions and 6 deletions

View file

@ -44,4 +44,12 @@ describe("Attempt to run a basic loop automation", () => {
})
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)
})
})

View file

@ -43,20 +43,18 @@ const CRON_STEP_ID = triggerDefs.CRON.stepId
const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
function getLoopIterations(loopStep: LoopStep) {
let binding = loopStep.inputs.binding
const binding = loopStep.inputs.binding
if (!binding) {
return 0
}
try {
if (typeof binding === "string") {
binding = JSON.parse(binding)
const json = typeof binding === "string" ? JSON.parse(binding) : binding
if (Array.isArray(json)) {
return json.length
}
} catch (err) {
// ignore error - wasn't able to parse
}
if (Array.isArray(binding)) {
return binding.length
}
if (typeof binding === "string") {
return automationUtils.stringSplit(binding).length
}