Adding test cases as per PR comments.
This commit is contained in:
parent
27b472b662
commit
b38399cb74
|
@ -0,0 +1,45 @@
|
|||
import * as automation from "../index"
|
||||
import * as triggers from "../triggers"
|
||||
import { loopAutomation } from "../../tests/utilities/structures"
|
||||
import { context } from "@budibase/backend-core"
|
||||
import * as setup from "./utilities"
|
||||
|
||||
describe("Attempt to run a basic loop automation", () => {
|
||||
let config = setup.getConfig(),
|
||||
table: any,
|
||||
row: any
|
||||
|
||||
beforeEach(async () => {
|
||||
await automation.init()
|
||||
await config.init()
|
||||
table = await config.createTable()
|
||||
row = await config.createRow()
|
||||
})
|
||||
|
||||
afterAll(setup.afterAll)
|
||||
|
||||
async function runLoop(loopOpts?: any) {
|
||||
const appId = config.getAppId()
|
||||
return await context.doInAppContext(appId, async () => {
|
||||
const params = { fields: { appId } }
|
||||
return await triggers.externalTrigger(
|
||||
loopAutomation(table._id, loopOpts),
|
||||
params,
|
||||
{ getResponses: true }
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
it("attempt to run a basic loop", async () => {
|
||||
const resp = await runLoop()
|
||||
expect(resp.steps[2].outputs.iterations).toBe(1)
|
||||
})
|
||||
|
||||
it("test a loop with a string", async () => {
|
||||
const resp = await runLoop({
|
||||
type: "String",
|
||||
binding: "a,b,c",
|
||||
})
|
||||
expect(resp.steps[2].outputs.iterations).toBe(3)
|
||||
})
|
||||
})
|
|
@ -109,8 +109,13 @@ export async function externalTrigger(
|
|||
}
|
||||
params.fields = coercedFields
|
||||
}
|
||||
const data = { automation, event: params }
|
||||
const data: Record<string, any> = { automation, event: params }
|
||||
if (getResponses) {
|
||||
data.event = {
|
||||
...data.event,
|
||||
appId: context.getAppId(),
|
||||
automation,
|
||||
}
|
||||
return utils.processEvent({ data })
|
||||
} else {
|
||||
return automationQueue.add(data, JOB_OPTS)
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import { roles, permissions } from "@budibase/backend-core"
|
||||
import { permissions, roles } from "@budibase/backend-core"
|
||||
import { createHomeScreen } from "../../constants/screens"
|
||||
import { EMPTY_LAYOUT } from "../../constants/layouts"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } from "../../automations"
|
||||
import { ACTION_DEFINITIONS, TRIGGER_DEFINITIONS } from "../../automations"
|
||||
import {
|
||||
Automation,
|
||||
AutomationActionStepId,
|
||||
AutomationTriggerStepId,
|
||||
} from "@budibase/types"
|
||||
|
||||
const { v4: uuidv4 } = require("uuid")
|
||||
|
||||
export const TENANT_ID = "default"
|
||||
|
@ -116,6 +122,63 @@ export function basicAutomation() {
|
|||
}
|
||||
}
|
||||
|
||||
export function loopAutomation(tableId: string, loopOpts?: any): Automation {
|
||||
if (!loopOpts) {
|
||||
loopOpts = {
|
||||
option: "Array",
|
||||
binding: "{{ steps.1.rows }}",
|
||||
}
|
||||
}
|
||||
const automation: any = {
|
||||
name: "looping",
|
||||
type: "automation",
|
||||
definition: {
|
||||
steps: [
|
||||
{
|
||||
id: "b",
|
||||
type: "ACTION",
|
||||
stepId: AutomationActionStepId.QUERY_ROWS,
|
||||
internal: true,
|
||||
inputs: {
|
||||
tableId,
|
||||
},
|
||||
schema: ACTION_DEFINITIONS.QUERY_ROWS.schema,
|
||||
},
|
||||
{
|
||||
id: "c",
|
||||
type: "ACTION",
|
||||
stepId: AutomationActionStepId.LOOP,
|
||||
internal: true,
|
||||
inputs: loopOpts,
|
||||
blockToLoop: "d",
|
||||
schema: ACTION_DEFINITIONS.LOOP.schema,
|
||||
},
|
||||
{
|
||||
id: "d",
|
||||
type: "ACTION",
|
||||
internal: true,
|
||||
stepId: AutomationActionStepId.SERVER_LOG,
|
||||
inputs: {
|
||||
text: "log statement",
|
||||
},
|
||||
schema: ACTION_DEFINITIONS.SERVER_LOG.schema,
|
||||
},
|
||||
],
|
||||
trigger: {
|
||||
id: "a",
|
||||
type: "TRIGGER",
|
||||
event: "row:save",
|
||||
stepId: AutomationTriggerStepId.ROW_SAVED,
|
||||
inputs: {
|
||||
tableId,
|
||||
},
|
||||
schema: TRIGGER_DEFINITIONS.ROW_SAVED.schema,
|
||||
},
|
||||
},
|
||||
}
|
||||
return automation as Automation
|
||||
}
|
||||
|
||||
export function basicRow(tableId: string) {
|
||||
return {
|
||||
name: "Test Contact",
|
||||
|
|
|
@ -50,6 +50,7 @@ export interface AutomationStepSchema {
|
|||
internal?: boolean
|
||||
deprecated?: boolean
|
||||
stepId: AutomationTriggerStepId | AutomationActionStepId
|
||||
blockToLoop?: string
|
||||
inputs: {
|
||||
[key: string]: any
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue