Merge pull request #15535 from Budibase/app-action-tests

App action tests
This commit is contained in:
Sam Rose 2025-02-12 15:08:30 +00:00 committed by GitHub
commit e80db7b492
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import { captureAutomationResults } from "../utilities"
import { Automation } from "@budibase/types"
describe("app action trigger", () => {
const config = new TestConfiguration()
let automation: Automation
beforeAll(async () => {
await config.init()
automation = await createAutomationBuilder(config)
.onAppAction()
.serverLog({
text: "App action triggered",
})
.save()
.then(({ automation }) => automation)
await config.api.application.publish()
})
afterAll(() => {
config.end()
})
it("should trigger when the app action is performed", async () => {
const jobs = await captureAutomationResults(automation, async () => {
await config.withProdApp(async () => {
await config.api.automation.trigger(automation._id!, {
fields: {},
timeout: 1000,
})
})
})
expect(jobs).toHaveLength(1)
expect(jobs[0].data.event).toEqual(
expect.objectContaining({
fields: {},
timeout: 1000,
})
)
})
})

View File

@ -15,6 +15,8 @@ import {
isDidNotTriggerResponse,
SearchFilters,
TestAutomationRequest,
TriggerAutomationRequest,
TriggerAutomationResponse,
} from "@budibase/types"
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import { automations } from "@budibase/shared-core"
@ -207,6 +209,15 @@ class AutomationRunner<TStep extends AutomationTriggerStepId> {
return response
}
async trigger(
request: TriggerAutomationRequest
): Promise<TriggerAutomationResponse> {
return await this.config.api.automation.trigger(
this.automation._id!,
request
)
}
}
export function createAutomationBuilder(config: TestConfiguration) {