Merge pull request #15516 from Budibase/remove-runstep-forever

Remove runStep from the codebase.
This commit is contained in:
Sam Rose 2025-02-11 15:07:45 +00:00 committed by GitHub
commit 634c730b85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 75 deletions

View File

@ -6,6 +6,7 @@ import {
} from "../../../integrations/tests/utils"
import { Knex } from "knex"
import { generator } from "@budibase/backend-core/tests"
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
const descriptions = datasourceDescribe({
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
@ -41,39 +42,34 @@ if (descriptions.length) {
})
it("should be able to execute a query", async () => {
let res = await setup.runStep(
config,
setup.actions.EXECUTE_QUERY.stepId,
{
query: { queryId: query._id },
}
)
expect(res.response).toEqual([{ a: "string", b: 1 }])
expect(res.success).toEqual(true)
const { steps } = await createAutomationBuilder(config)
.onAppAction()
.executeQuery({ query: { queryId: query._id! } })
.test({ fields: {} })
expect(steps[0].outputs.response).toEqual([{ a: "string", b: 1 }])
expect(steps[0].outputs.success).toEqual(true)
})
it("should handle a null query value", async () => {
let res = await setup.runStep(
config,
setup.actions.EXECUTE_QUERY.stepId,
{
query: null,
}
)
expect(res.response.message).toEqual("Invalid inputs")
expect(res.success).toEqual(false)
const { steps } = await createAutomationBuilder(config)
.onAppAction()
// @ts-expect-error - intentionally passing null
.executeQuery({ query: { queryId: null } })
.test({ fields: {} })
expect(steps[0].outputs.response).toStartWith("Error:")
expect(steps[0].outputs.success).toEqual(false)
})
it("should handle an error executing a query", async () => {
let res = await setup.runStep(
config,
setup.actions.EXECUTE_QUERY.stepId,
{
query: { queryId: "wrong_id" },
}
)
expect(res.response).toBeDefined()
expect(res.success).toEqual(false)
const { steps } = await createAutomationBuilder(config)
.onAppAction()
.executeQuery({ query: { queryId: "wrong_id" } })
.test({ fields: {} })
expect(steps[0].outputs.response).toStartWith("Error:")
expect(steps[0].outputs.success).toEqual(false)
})
}
)

View File

@ -19,7 +19,7 @@ function generateResponse(to: string, from: string) {
}
}
import * as setup from "../utilities"
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
describe("test the outgoing webhook action", () => {
const config = new TestConfiguration()
@ -60,13 +60,14 @@ describe("test the outgoing webhook action", () => {
...invite,
}
let resp = generateResponse(inputs.to, inputs.from)
const res = await setup.runStep(
config,
setup.actions.SEND_EMAIL_SMTP.stepId,
inputs
)
expect(res.response).toEqual(resp)
expect(res.success).toEqual(true)
const { steps } = await createAutomationBuilder(config)
.onAppAction()
.sendSmtpEmail(inputs)
.test({ fields: {} })
expect(steps[0].outputs.response).toEqual(resp)
expect(steps[0].outputs.success).toEqual(true)
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledTimes(1)
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledWith({
to: "user1@example.com",
@ -75,7 +76,11 @@ describe("test the outgoing webhook action", () => {
contents: "testing",
cc: "cc",
bcc: "bcc",
invite,
invite: {
...invite,
startTime: invite.startTime.toISOString(),
endTime: invite.endTime.toISOString(),
},
automation: true,
attachments: [
{ url: "attachment1", filename: "attachment1.txt" },

View File

@ -1,14 +1,7 @@
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import { context } from "@budibase/backend-core"
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
import emitter from "../../../events/index"
import { BUILTIN_ACTION_DEFINITIONS } from "../../actions"
import env from "../../../environment"
import {
Automation,
AutomationActionStepId,
AutomationData,
Datasource,
} from "@budibase/types"
import { Automation, AutomationData, Datasource } from "@budibase/types"
import { Knex } from "knex"
import { getQueue } from "../.."
import { Job } from "bull"
@ -41,36 +34,6 @@ export async function runInProd(fn: any) {
}
}
export async function runStep(
config: TestConfiguration,
stepId: string,
inputs: any,
stepContext?: any
) {
async function run() {
let step = await getAction(stepId as AutomationActionStepId)
expect(step).toBeDefined()
if (!step) {
throw new Error("No step found")
}
return step({
context: stepContext || {},
inputs,
appId: config ? config.getAppId() : "",
// don't really need an API key, mocked out usage quota, not being tested here
apiKey,
emitter,
})
}
if (config.appId) {
return context.doInContext(config?.appId, async () => {
return run()
})
} else {
return run()
}
}
/**
* Capture all automation runs that occur during the execution of a function.
* This function will wait for all messages to be processed before returning.