From e99a7672a774f96e7f5a6d32cd56c0da714ffb62 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 5 Jan 2024 16:12:31 +0000 Subject: [PATCH] test and pr comments --- .../builderStore/store/automation/index.js | 1 - .../FlowChart/ActionModal.svelte | 2 +- packages/server/src/automations/actions.ts | 1 - .../src/automations/tests/trigger.spec.ts | 33 +++++++++++++++ .../server/src/tests/utilities/structures.ts | 40 ++++++++++++++++++- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 packages/server/src/automations/tests/trigger.spec.ts diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index aecdff0246..af83f73dc6 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -155,7 +155,6 @@ const automationActions = store => ({ await store.actions.save(newAutomation) }, test: async (automation, testData) => { - console.log(testData) const result = await API.testAutomation({ automationId: automation?._id, testData, diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte index c335329844..0c97853dd6 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte @@ -19,7 +19,7 @@ export let lastStep let syncAutomationsEnabled = $licensing.syncAutomationsEnabled - let triggerAutomationsEnabled = true + let triggerAutomationsEnabled = $licensing.triggerAutomationsEnabled let collectBlockAllowedSteps = [TriggerStepID.APP, TriggerStepID.WEBHOOK] let selectedAction let actionVal diff --git a/packages/server/src/automations/actions.ts b/packages/server/src/automations/actions.ts index 2fb08f754f..a3997ad21c 100644 --- a/packages/server/src/automations/actions.ts +++ b/packages/server/src/automations/actions.ts @@ -105,7 +105,6 @@ export async function getActionDefinitions() { /* istanbul ignore next */ export async function getAction(stepId: string) { - console.log(stepId) if (ACTION_IMPLS[stepId] != null) { return ACTION_IMPLS[stepId] } diff --git a/packages/server/src/automations/tests/trigger.spec.ts b/packages/server/src/automations/tests/trigger.spec.ts new file mode 100644 index 0000000000..e8a2cc9345 --- /dev/null +++ b/packages/server/src/automations/tests/trigger.spec.ts @@ -0,0 +1,33 @@ +jest.spyOn(global.console, "error") + +import * as setup from "./utilities" +import * as automation from "../index" + +describe("Test triggering an automation from another automation", () => { + let config = setup.getConfig() + + beforeAll(async () => { + await automation.init() + await config.init() + }) + + afterAll(async () => { + await automation.shutdown() + setup.afterAll() + }) + + it("should trigger an other server log automation", async () => { + let newAutomation = await config.createAutomation() + + const inputs: any = { automationId: newAutomation._id, timeout: 12000 } + const res = await setup.runStep(setup.actions.TRIGGER.stepId, inputs) + // Check if the SERVER_LOG step was successful + expect(res.value[1].outputs.success).toBe(true) + }) + + it("should fail gracefully if the automation id is incorrect", async () => { + const inputs: any = { automationId: null, timeout: 12000 } + const res = await setup.runStep(setup.actions.TRIGGER.stepId, inputs) + expect(res.success).toBe(false) + }) +}) diff --git a/packages/server/src/tests/utilities/structures.ts b/packages/server/src/tests/utilities/structures.ts index 83be8b6d58..ce08011e76 100644 --- a/packages/server/src/tests/utilities/structures.ts +++ b/packages/server/src/tests/utilities/structures.ts @@ -146,7 +146,45 @@ export function basicAutomation(appId?: string): Automation { }, }, }, - steps: [], + steps: [ + { + stepId: AutomationActionStepId.SERVER_LOG, + name: "Backend log", + tagline: "Console log a value in the backend", + icon: "Monitoring", + description: "Logs the given text to the server (using console.log)", + internal: true, + features: { + LOOPING: true, + }, + inputs: { + text: "sdfsdf", + }, + schema: { + inputs: { + properties: { + text: { + type: "string", + title: "Text to log", + }, + }, + required: ["text"], + }, + outputs: { + properties: { + success: { + description: "Whether the action was successful", + }, + message: { + description: "What was output", + }, + }, + required: ["success", "message"], + }, + }, + id: "y8lkZbeSe", + }, + ], }, type: "automation", appId: appId!,