Merge pull request #15516 from Budibase/remove-runstep-forever
Remove runStep from the codebase.
This commit is contained in:
commit
634c730b85
|
@ -6,6 +6,7 @@ import {
|
||||||
} from "../../../integrations/tests/utils"
|
} from "../../../integrations/tests/utils"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({
|
const descriptions = datasourceDescribe({
|
||||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||||
|
@ -41,39 +42,34 @@ if (descriptions.length) {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to execute a query", async () => {
|
it("should be able to execute a query", async () => {
|
||||||
let res = await setup.runStep(
|
const { steps } = await createAutomationBuilder(config)
|
||||||
config,
|
.onAppAction()
|
||||||
setup.actions.EXECUTE_QUERY.stepId,
|
.executeQuery({ query: { queryId: query._id! } })
|
||||||
{
|
.test({ fields: {} })
|
||||||
query: { queryId: query._id },
|
|
||||||
}
|
expect(steps[0].outputs.response).toEqual([{ a: "string", b: 1 }])
|
||||||
)
|
expect(steps[0].outputs.success).toEqual(true)
|
||||||
expect(res.response).toEqual([{ a: "string", b: 1 }])
|
|
||||||
expect(res.success).toEqual(true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle a null query value", async () => {
|
it("should handle a null query value", async () => {
|
||||||
let res = await setup.runStep(
|
const { steps } = await createAutomationBuilder(config)
|
||||||
config,
|
.onAppAction()
|
||||||
setup.actions.EXECUTE_QUERY.stepId,
|
// @ts-expect-error - intentionally passing null
|
||||||
{
|
.executeQuery({ query: { queryId: null } })
|
||||||
query: null,
|
.test({ fields: {} })
|
||||||
}
|
|
||||||
)
|
expect(steps[0].outputs.response).toStartWith("Error:")
|
||||||
expect(res.response.message).toEqual("Invalid inputs")
|
expect(steps[0].outputs.success).toEqual(false)
|
||||||
expect(res.success).toEqual(false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle an error executing a query", async () => {
|
it("should handle an error executing a query", async () => {
|
||||||
let res = await setup.runStep(
|
const { steps } = await createAutomationBuilder(config)
|
||||||
config,
|
.onAppAction()
|
||||||
setup.actions.EXECUTE_QUERY.stepId,
|
.executeQuery({ query: { queryId: "wrong_id" } })
|
||||||
{
|
.test({ fields: {} })
|
||||||
query: { queryId: "wrong_id" },
|
|
||||||
}
|
expect(steps[0].outputs.response).toStartWith("Error:")
|
||||||
)
|
expect(steps[0].outputs.success).toEqual(false)
|
||||||
expect(res.response).toBeDefined()
|
|
||||||
expect(res.success).toEqual(false)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -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", () => {
|
describe("test the outgoing webhook action", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
@ -60,13 +60,14 @@ describe("test the outgoing webhook action", () => {
|
||||||
...invite,
|
...invite,
|
||||||
}
|
}
|
||||||
let resp = generateResponse(inputs.to, inputs.from)
|
let resp = generateResponse(inputs.to, inputs.from)
|
||||||
const res = await setup.runStep(
|
|
||||||
config,
|
const { steps } = await createAutomationBuilder(config)
|
||||||
setup.actions.SEND_EMAIL_SMTP.stepId,
|
.onAppAction()
|
||||||
inputs
|
.sendSmtpEmail(inputs)
|
||||||
)
|
.test({ fields: {} })
|
||||||
expect(res.response).toEqual(resp)
|
|
||||||
expect(res.success).toEqual(true)
|
expect(steps[0].outputs.response).toEqual(resp)
|
||||||
|
expect(steps[0].outputs.success).toEqual(true)
|
||||||
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledTimes(1)
|
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledTimes(1)
|
||||||
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledWith({
|
expect(workerRequests.sendSmtpEmail).toHaveBeenCalledWith({
|
||||||
to: "user1@example.com",
|
to: "user1@example.com",
|
||||||
|
@ -75,7 +76,11 @@ describe("test the outgoing webhook action", () => {
|
||||||
contents: "testing",
|
contents: "testing",
|
||||||
cc: "cc",
|
cc: "cc",
|
||||||
bcc: "bcc",
|
bcc: "bcc",
|
||||||
invite,
|
invite: {
|
||||||
|
...invite,
|
||||||
|
startTime: invite.startTime.toISOString(),
|
||||||
|
endTime: invite.endTime.toISOString(),
|
||||||
|
},
|
||||||
automation: true,
|
automation: true,
|
||||||
attachments: [
|
attachments: [
|
||||||
{ url: "attachment1", filename: "attachment1.txt" },
|
{ url: "attachment1", filename: "attachment1.txt" },
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
import { context } from "@budibase/backend-core"
|
import { BUILTIN_ACTION_DEFINITIONS } from "../../actions"
|
||||||
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
|
||||||
import emitter from "../../../events/index"
|
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import {
|
import { Automation, AutomationData, Datasource } from "@budibase/types"
|
||||||
Automation,
|
|
||||||
AutomationActionStepId,
|
|
||||||
AutomationData,
|
|
||||||
Datasource,
|
|
||||||
} from "@budibase/types"
|
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
import { getQueue } from "../.."
|
import { getQueue } from "../.."
|
||||||
import { Job } from "bull"
|
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.
|
* Capture all automation runs that occur during the execution of a function.
|
||||||
* This function will wait for all messages to be processed before returning.
|
* This function will wait for all messages to be processed before returning.
|
||||||
|
|
Loading…
Reference in New Issue