Rename automation result helper.
This commit is contained in:
parent
3a956ed309
commit
e16c3fc7a9
|
@ -1,6 +1,6 @@
|
|||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
import { captureAutomationRuns } from "../utilities"
|
||||
import { captureAutomationResults } from "../utilities"
|
||||
|
||||
describe("cron trigger", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
@ -14,14 +14,14 @@ describe("cron trigger", () => {
|
|||
})
|
||||
|
||||
it("should queue a Bull cron job", async () => {
|
||||
await createAutomationBuilder(config)
|
||||
const { automation } = await createAutomationBuilder(config)
|
||||
.onCron({ cron: "* * * * *" })
|
||||
.serverLog({
|
||||
text: "Hello, world!",
|
||||
})
|
||||
.save()
|
||||
|
||||
const jobs = await captureAutomationRuns(() =>
|
||||
const jobs = await captureAutomationResults(automation, () =>
|
||||
config.api.application.publish()
|
||||
)
|
||||
expect(jobs).toHaveLength(1)
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
import { Table } from "@budibase/types"
|
||||
import { Automation, Table } from "@budibase/types"
|
||||
import { basicTable } from "../../../tests/utilities/structures"
|
||||
import { captureAutomationRuns } from "../utilities"
|
||||
import { captureAutomationResults } from "../utilities"
|
||||
|
||||
describe("row saved trigger", () => {
|
||||
const config = new TestConfiguration()
|
||||
let table: Table
|
||||
let automation: Automation
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.init()
|
||||
table = await config.api.table.save(basicTable())
|
||||
await createAutomationBuilder(config)
|
||||
automation = await createAutomationBuilder(config)
|
||||
.onRowSaved({ tableId: table._id! })
|
||||
.serverLog({ text: "Row created!" })
|
||||
.save()
|
||||
.then(({ automation }) => automation)
|
||||
|
||||
await config.api.application.publish()
|
||||
})
|
||||
|
@ -24,12 +26,12 @@ describe("row saved trigger", () => {
|
|||
})
|
||||
|
||||
it("should queue a Bull job when a row is created", async () => {
|
||||
const jobs = await captureAutomationRuns(() =>
|
||||
const results = await captureAutomationResults(automation, () =>
|
||||
config.withProdApp(() => config.api.row.save(table._id!, { name: "foo" }))
|
||||
)
|
||||
|
||||
expect(jobs).toHaveLength(1)
|
||||
expect(jobs[0].data.event).toEqual(
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].data.event).toEqual(
|
||||
expect.objectContaining({
|
||||
tableId: table._id!,
|
||||
row: expect.objectContaining({ name: "foo" }),
|
||||
|
@ -41,12 +43,12 @@ describe("row saved trigger", () => {
|
|||
const otherTable = await config.api.table.save(basicTable())
|
||||
await config.api.application.publish()
|
||||
|
||||
const jobs = await captureAutomationRuns(() =>
|
||||
const results = await captureAutomationResults(automation, () =>
|
||||
config.withProdApp(() =>
|
||||
config.api.row.save(otherTable._id!, { name: "foo" })
|
||||
)
|
||||
)
|
||||
|
||||
expect(jobs).toBeEmpty()
|
||||
expect(results).toBeEmpty()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -4,6 +4,7 @@ import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
|||
import emitter from "../../../events/index"
|
||||
import env from "../../../environment"
|
||||
import {
|
||||
Automation,
|
||||
AutomationActionStepId,
|
||||
AutomationData,
|
||||
Datasource,
|
||||
|
@ -74,7 +75,7 @@ export async function runStep(
|
|||
* Capture all automation runs that occur during the execution of a function.
|
||||
* This function will wait for all messages to be processed before returning.
|
||||
*/
|
||||
export async function captureAutomationRuns(
|
||||
export async function captureAllAutomationResults(
|
||||
f: () => Promise<unknown>
|
||||
): Promise<Job<AutomationData>[]> {
|
||||
const runs: Job<AutomationData>[] = []
|
||||
|
@ -108,6 +109,18 @@ export async function captureAutomationRuns(
|
|||
return runs
|
||||
}
|
||||
|
||||
export async function captureAutomationResults(
|
||||
automation: Automation | string,
|
||||
f: () => Promise<unknown>
|
||||
) {
|
||||
const results = await captureAllAutomationResults(f)
|
||||
return results.filter(
|
||||
r =>
|
||||
r.data.automation._id ===
|
||||
(typeof automation === "string" ? automation : automation._id)
|
||||
)
|
||||
}
|
||||
|
||||
export async function saveTestQuery(
|
||||
config: TestConfiguration,
|
||||
client: Knex,
|
||||
|
|
Loading…
Reference in New Issue