- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
92 lines
3.5 KiB
TypeScript
92 lines
3.5 KiB
TypeScript
import { FlowAction, FlowRunStatus, LoopStepOutput } from '@activepieces/shared'
|
|
import { FlowExecutorContext } from '../../src/lib/handler/context/flow-execution-context'
|
|
import { flowExecutor } from '../../src/lib/handler/flow-executor'
|
|
import { buildCodeAction, buildSimpleLoopAction, generateMockEngineConstants } from './test-helper'
|
|
|
|
|
|
describe('flow with looping', () => {
|
|
|
|
it('should execute iterations', async () => {
|
|
const codeAction = buildCodeAction({
|
|
name: 'echo_step',
|
|
input: {
|
|
'index': '{{loop.index}}',
|
|
},
|
|
})
|
|
const result = await flowExecutor.execute({
|
|
action: buildSimpleLoopAction({
|
|
name: 'loop',
|
|
loopItems: '{{ [4,5,6] }}',
|
|
firstLoopAction: codeAction,
|
|
}),
|
|
executionState: FlowExecutorContext.empty(),
|
|
constants: generateMockEngineConstants(),
|
|
})
|
|
|
|
const loopOut = result.steps.loop as LoopStepOutput
|
|
expect(result.verdict.status).toBe(FlowRunStatus.RUNNING)
|
|
expect(loopOut.output?.iterations.length).toBe(3)
|
|
expect(loopOut.output?.index).toBe(3)
|
|
expect(loopOut.output?.item).toBe(6)
|
|
})
|
|
|
|
it('should execute iterations and fail on first iteration', async () => {
|
|
const generateArray = buildCodeAction({
|
|
name: 'echo_step',
|
|
input: {
|
|
'array': '{{ [4,5,6] }}',
|
|
},
|
|
nextAction: buildSimpleLoopAction({
|
|
name: 'loop',
|
|
loopItems: '{{ echo_step.array }}',
|
|
firstLoopAction: buildCodeAction({
|
|
name: 'runtime',
|
|
input: {},
|
|
}),
|
|
}),
|
|
})
|
|
const result = await flowExecutor.execute({
|
|
action: generateArray,
|
|
executionState: FlowExecutorContext.empty(),
|
|
constants: generateMockEngineConstants(),
|
|
})
|
|
|
|
const loopOut = result.steps.loop as LoopStepOutput
|
|
expect(result.verdict.status).toBe(FlowRunStatus.FAILED)
|
|
expect(loopOut.output?.iterations.length).toBe(1)
|
|
expect(loopOut.output?.index).toBe(1)
|
|
expect(loopOut.output?.item).toBe(4)
|
|
})
|
|
|
|
it('should skip loop', async () => {
|
|
const result = await flowExecutor.execute({
|
|
action: buildSimpleLoopAction({ name: 'loop', loopItems: '{{ [4,5,6] }}', skip: true }), executionState: FlowExecutorContext.empty(), constants: generateMockEngineConstants(),
|
|
})
|
|
expect(result.verdict.status).toBe(FlowRunStatus.RUNNING)
|
|
expect(result.steps.loop).toBeUndefined()
|
|
})
|
|
|
|
it('should skip loop in flow', async () => {
|
|
const flow: FlowAction = {
|
|
...buildSimpleLoopAction({ name: 'loop', loopItems: '{{ [4,5,6] }}', skip: true }),
|
|
nextAction: {
|
|
...buildCodeAction({
|
|
name: 'echo_step',
|
|
skip: false,
|
|
input: {
|
|
'key': '{{ 1 + 2 }}',
|
|
},
|
|
}),
|
|
nextAction: undefined,
|
|
},
|
|
}
|
|
const result = await flowExecutor.execute({
|
|
action: flow, executionState: FlowExecutorContext.empty(), constants: generateMockEngineConstants(),
|
|
})
|
|
expect(result.verdict.status).toBe(FlowRunStatus.RUNNING)
|
|
expect(result.steps.loop).toBeUndefined()
|
|
expect(result.steps.echo_step.output).toEqual({ 'key': 3 })
|
|
})
|
|
|
|
})
|