Merge pull request #15535 from Budibase/app-action-tests
App action tests
This commit is contained in:
commit
e80db7b492
|
@ -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,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
|
@ -15,6 +15,8 @@ import {
|
||||||
isDidNotTriggerResponse,
|
isDidNotTriggerResponse,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
TestAutomationRequest,
|
TestAutomationRequest,
|
||||||
|
TriggerAutomationRequest,
|
||||||
|
TriggerAutomationResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
import { automations } from "@budibase/shared-core"
|
import { automations } from "@budibase/shared-core"
|
||||||
|
@ -207,6 +209,15 @@ class AutomationRunner<TStep extends AutomationTriggerStepId> {
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async trigger(
|
||||||
|
request: TriggerAutomationRequest
|
||||||
|
): Promise<TriggerAutomationResponse> {
|
||||||
|
return await this.config.api.automation.trigger(
|
||||||
|
this.automation._id!,
|
||||||
|
request
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAutomationBuilder(config: TestConfiguration) {
|
export function createAutomationBuilder(config: TestConfiguration) {
|
||||||
|
|
Loading…
Reference in New Issue