-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15184 from Budibase/fix/automation-webhook-improv…
…ements Automation webhook binding fixes
- Loading branch information
Showing
11 changed files
with
232 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/server/src/automations/tests/scenarios/webhook.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as automation from "../../index" | ||
import * as setup from "../utilities" | ||
import { Table, Webhook, WebhookActionType } from "@budibase/types" | ||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder" | ||
import { mocks } from "@budibase/backend-core/tests" | ||
|
||
mocks.licenses.useSyncAutomations() | ||
|
||
describe("Branching automations", () => { | ||
let config = setup.getConfig(), | ||
table: Table, | ||
webhook: Webhook | ||
|
||
async function createWebhookAutomation(testName: string) { | ||
const builder = createAutomationBuilder({ | ||
name: testName, | ||
}) | ||
const automation = await builder | ||
.webhook({ fields: { parameter: "string" } }) | ||
.createRow({ | ||
row: { tableId: table._id!, name: "{{ trigger.parameter }}" }, | ||
}) | ||
.collect({ collection: `{{ trigger.parameter }}` }) | ||
.save() | ||
|
||
webhook = await config.api.webhook.save({ | ||
name: "hook", | ||
live: true, | ||
action: { | ||
type: WebhookActionType.AUTOMATION, | ||
target: automation._id!, | ||
}, | ||
bodySchema: {}, | ||
}) | ||
await config.api.webhook.buildSchema(config.getAppId(), webhook._id!, { | ||
parameter: "string", | ||
}) | ||
await config.publish() | ||
return { webhook, automation } | ||
} | ||
|
||
beforeEach(async () => { | ||
await automation.init() | ||
await config.init() | ||
table = await config.createTable() | ||
}) | ||
|
||
afterAll(setup.afterAll) | ||
|
||
it("should run the webhook automation - checking for parameters", async () => { | ||
const { webhook } = await createWebhookAutomation( | ||
"Check a basic webhook works as expected" | ||
) | ||
const res = await config.api.webhook.trigger( | ||
config.getProdAppId(), | ||
webhook._id!, | ||
{ | ||
parameter: "testing", | ||
} | ||
) | ||
expect(typeof res).toBe("object") | ||
const collectedInfo = res as Record<string, any> | ||
expect(collectedInfo.value).toEqual("testing") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Expectations, TestAPI } from "./base" | ||
import { | ||
BuildWebhookSchemaResponse, | ||
SaveWebhookResponse, | ||
TriggerWebhookResponse, | ||
Webhook, | ||
} from "@budibase/types" | ||
|
||
export class WebhookAPI extends TestAPI { | ||
save = async (webhook: Webhook, expectations?: Expectations) => { | ||
const resp = await this._put<SaveWebhookResponse>("/api/webhooks", { | ||
body: webhook, | ||
expectations: { | ||
status: 200, | ||
...expectations, | ||
}, | ||
}) | ||
return resp.webhook | ||
} | ||
|
||
buildSchema = async ( | ||
appId: string, | ||
webhookId: string, | ||
fields: Record<string, any>, | ||
expectations?: Expectations | ||
) => { | ||
const resp = await this._post<BuildWebhookSchemaResponse>( | ||
`/api/webhooks/schema/${appId}/${webhookId}`, | ||
{ | ||
body: fields, | ||
expectations: { | ||
status: 200, | ||
...expectations, | ||
}, | ||
} | ||
) | ||
return resp.id | ||
} | ||
|
||
trigger = async ( | ||
appId: string, | ||
webhookId: string, | ||
fields: Record<string, any>, | ||
expectations?: Expectations | ||
) => { | ||
const resp = await this._post<TriggerWebhookResponse>( | ||
`/api/webhooks/trigger/${appId}/${webhookId}`, | ||
{ | ||
body: fields, | ||
expectations: { | ||
status: 200, | ||
...expectations, | ||
}, | ||
} | ||
) | ||
return resp | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { Automation, AutomationTriggerStepId } from "@budibase/types" | ||
|
||
export function isRowAction(automation: Automation) { | ||
const result = | ||
return ( | ||
automation.definition.trigger?.stepId === AutomationTriggerStepId.ROW_ACTION | ||
return result | ||
) | ||
} | ||
|
||
export function isWebhookAction(automation: Automation) { | ||
return ( | ||
automation.definition.trigger?.stepId === AutomationTriggerStepId.WEBHOOK | ||
) | ||
} | ||
|
||
export function isAppAction(automation: Automation) { | ||
const result = | ||
automation.definition.trigger?.stepId === AutomationTriggerStepId.APP | ||
return result | ||
return automation.definition.trigger?.stepId === AutomationTriggerStepId.APP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.