From 80bd561bbaee8dfd804384e527b42ca5e972bbf7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 13 Dec 2024 13:59:29 +0000 Subject: [PATCH] Some further work on automation webhook testing. --- .../tests/scenarios/webhook.spec.ts | 18 ++++++++++++++- .../tests/utilities/AutomationTestBuilder.ts | 15 +++++++++++++ .../server/src/tests/utilities/api/webhook.ts | 22 ++++++++++++++++++- .../app/automation/StepInputsOutputs.ts | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/server/src/automations/tests/scenarios/webhook.spec.ts b/packages/server/src/automations/tests/scenarios/webhook.spec.ts index 78648d80d4..427f87ceb2 100644 --- a/packages/server/src/automations/tests/scenarios/webhook.spec.ts +++ b/packages/server/src/automations/tests/scenarios/webhook.spec.ts @@ -17,6 +17,7 @@ describe("Branching automations", () => { .createRow({ row: { tableId: table._id!, name: "{{ trigger.parameter }}" }, }) + .collect({ collection: `{{ trigger.parameter }}` }) .save() webhook = await config.api.webhook.save({ @@ -28,6 +29,10 @@ describe("Branching automations", () => { }, bodySchema: {}, }) + await config.api.webhook.buildSchema(config.getAppId(), webhook._id!, { + parameter: "string", + }) + return { webhook, automation } } beforeEach(async () => { @@ -38,5 +43,16 @@ describe("Branching automations", () => { 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", + } + ) + }) }) diff --git a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts index dbde178603..acc35a0eeb 100644 --- a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts +++ b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts @@ -17,6 +17,7 @@ import { BashStepInputs, Branch, BranchStepInputs, + CollectStepInputs, CreateRowStepInputs, CronTriggerOutputs, DeleteRowStepInputs, @@ -182,6 +183,7 @@ class BaseStepBuilder { opts ) } + loop( inputs: LoopStepInputs, opts?: { stepName?: string; stepId?: string } @@ -249,7 +251,20 @@ class BaseStepBuilder { 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 { build(): AutomationStep[] { return this.steps diff --git a/packages/server/src/tests/utilities/api/webhook.ts b/packages/server/src/tests/utilities/api/webhook.ts index 9690c48bb6..b4a1570a65 100644 --- a/packages/server/src/tests/utilities/api/webhook.ts +++ b/packages/server/src/tests/utilities/api/webhook.ts @@ -1,5 +1,6 @@ import { Expectations, TestAPI } from "./base" import { + BuildWebhookSchemaResponse, SaveWebhookResponse, TriggerWebhookResponse, Webhook, @@ -17,6 +18,25 @@ export class WebhookAPI extends TestAPI { return resp.webhook } + buildSchema = async ( + appId: string, + webhookId: string, + fields: Record, + expectations?: Expectations + ) => { + const resp = await this._post( + `/api/webhooks/schema/${appId}/${webhookId}`, + { + body: fields, + expectations: { + status: 200, + ...expectations, + }, + } + ) + return resp.id + } + trigger = async ( appId: string, webhookId: string, @@ -33,6 +53,6 @@ export class WebhookAPI extends TestAPI { }, } ) - return resp?.message + return resp } } diff --git a/packages/types/src/documents/app/automation/StepInputsOutputs.ts b/packages/types/src/documents/app/automation/StepInputsOutputs.ts index 2d87bae65d..6f7223300d 100644 --- a/packages/types/src/documents/app/automation/StepInputsOutputs.ts +++ b/packages/types/src/documents/app/automation/StepInputsOutputs.ts @@ -150,6 +150,7 @@ export type OpenAIStepInputs = { prompt: string model: Model } + export enum Model { GPT_35_TURBO = "gpt-3.5-turbo", // will only work with api keys that have access to the GPT4 API