Some further work on automation webhook testing.

This commit is contained in:
mike12345567 2024-12-13 13:59:29 +00:00
parent 715399b755
commit 80bd561bba
4 changed files with 54 additions and 2 deletions

View File

@ -17,6 +17,7 @@ describe("Branching automations", () => {
.createRow({ .createRow({
row: { tableId: table._id!, name: "{{ trigger.parameter }}" }, row: { tableId: table._id!, name: "{{ trigger.parameter }}" },
}) })
.collect({ collection: `{{ trigger.parameter }}` })
.save() .save()
webhook = await config.api.webhook.save({ webhook = await config.api.webhook.save({
@ -28,6 +29,10 @@ describe("Branching automations", () => {
}, },
bodySchema: {}, bodySchema: {},
}) })
await config.api.webhook.buildSchema(config.getAppId(), webhook._id!, {
parameter: "string",
})
return { webhook, automation }
} }
beforeEach(async () => { beforeEach(async () => {
@ -38,5 +43,16 @@ describe("Branching automations", () => {
afterAll(setup.afterAll) afterAll(setup.afterAll)
it("should run the webhook automation", async () => {}) 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.getAppId(),
webhook._id!,
{
parameter: "testing",
}
)
})
}) })

View File

@ -17,6 +17,7 @@ import {
BashStepInputs, BashStepInputs,
Branch, Branch,
BranchStepInputs, BranchStepInputs,
CollectStepInputs,
CreateRowStepInputs, CreateRowStepInputs,
CronTriggerOutputs, CronTriggerOutputs,
DeleteRowStepInputs, DeleteRowStepInputs,
@ -182,6 +183,7 @@ class BaseStepBuilder {
opts opts
) )
} }
loop( loop(
inputs: LoopStepInputs, inputs: LoopStepInputs,
opts?: { stepName?: string; stepId?: string } opts?: { stepName?: string; stepId?: string }
@ -249,7 +251,20 @@ class BaseStepBuilder {
opts opts
) )
} }
collect(
input: CollectStepInputs,
opts?: { stepName?: string; stepId?: string }
): this {
return this.step(
AutomationActionStepId.COLLECT,
BUILTIN_ACTION_DEFINITIONS.COLLECT,
input,
opts
)
}
} }
class StepBuilder extends BaseStepBuilder { class StepBuilder extends BaseStepBuilder {
build(): AutomationStep[] { build(): AutomationStep[] {
return this.steps return this.steps

View File

@ -1,5 +1,6 @@
import { Expectations, TestAPI } from "./base" import { Expectations, TestAPI } from "./base"
import { import {
BuildWebhookSchemaResponse,
SaveWebhookResponse, SaveWebhookResponse,
TriggerWebhookResponse, TriggerWebhookResponse,
Webhook, Webhook,
@ -17,6 +18,25 @@ export class WebhookAPI extends TestAPI {
return resp.webhook 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 ( trigger = async (
appId: string, appId: string,
webhookId: string, webhookId: string,
@ -33,6 +53,6 @@ export class WebhookAPI extends TestAPI {
}, },
} }
) )
return resp?.message return resp
} }
} }

View File

@ -150,6 +150,7 @@ export type OpenAIStepInputs = {
prompt: string prompt: string
model: Model model: Model
} }
export enum Model { export enum Model {
GPT_35_TURBO = "gpt-3.5-turbo", GPT_35_TURBO = "gpt-3.5-turbo",
// will only work with api keys that have access to the GPT4 API // will only work with api keys that have access to the GPT4 API