diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index 673359699a..2e7914f60b 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -99,7 +99,7 @@ export async function destroy(ctx: UserCtx) { if ( automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION ) { - ctx.throw("Row actions cannot be renamed", 403) + ctx.throw("Row actions cannot be deleted", 403) } ctx.body = await sdk.automations.remove(automationId, ctx.params.rev) diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index f0c3d6e1c5..a82bc68465 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -425,6 +425,19 @@ describe("/automations", () => { expect(events.automation.deleted).toHaveBeenCalledTimes(1) }) + it("cannot delete a row action automation", async () => { + const automation = await config.createAutomation( + setup.structures.rowActionAutomation() + ) + await request + .delete(`/api/automations/${automation._id}/${automation._rev}`) + .set(config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(403, { message: "Row actions cannot be deleted", status: 403 }) + + expect(events.automation.deleted).not.toHaveBeenCalled() + }) + it("should apply authorization to endpoint", async () => { const automation = await config.createAutomation() await checkBuilderEndpoint({ diff --git a/packages/server/src/sdk/app/automations/tests/index.spec.ts b/packages/server/src/sdk/app/automations/tests/index.spec.ts index 124a5d9276..868dfb30ac 100644 --- a/packages/server/src/sdk/app/automations/tests/index.spec.ts +++ b/packages/server/src/sdk/app/automations/tests/index.spec.ts @@ -1,5 +1,6 @@ import { sample } from "lodash/fp" -import { Automation } from "@budibase/types" +import { Automation, AutomationTriggerStepId } from "@budibase/types" +import { generator } from "@budibase/backend-core/tests" import automationSdk from "../" import { structures } from "../../../../api/routes/tests/utilities" import TestConfiguration from "../../../../tests/utilities/TestConfiguration" @@ -12,6 +13,38 @@ describe("automation sdk", () => { }) describe("update", () => { + it("can rename existing automations", async () => { + await config.doInContext(config.getAppId(), async () => { + const automation = structures.newAutomation() + + const response = await automationSdk.create(automation) + + const newName = generator.guid() + const update = { ...response, name: newName } + const result = await automationSdk.update(update) + expect(result.name).toEqual(newName) + }) + }) + + it("cannot rename row action automations", async () => { + await config.doInContext(config.getAppId(), async () => { + const automation = structures.newAutomation({ + trigger: { + ...structures.automationTrigger(), + stepId: AutomationTriggerStepId.ROW_ACTION, + }, + }) + + const response = await automationSdk.create(automation) + + const newName = generator.guid() + const update = { ...response, name: newName } + await expect(automationSdk.update(update)).rejects.toThrow( + "Row actions cannot be renamed" + ) + }) + }) + it.each([ ["trigger", (a: Automation) => a.definition.trigger], ["step", (a: Automation) => a.definition.steps[0]], diff --git a/packages/server/src/tests/utilities/structures.ts b/packages/server/src/tests/utilities/structures.ts index 970df2e2c9..16ab049eb4 100644 --- a/packages/server/src/tests/utilities/structures.ts +++ b/packages/server/src/tests/utilities/structures.ts @@ -158,7 +158,10 @@ export function automationTrigger( } } -export function newAutomation({ steps, trigger }: any = {}) { +export function newAutomation({ + steps, + trigger, +}: { steps?: AutomationStep[]; trigger?: AutomationTrigger } = {}) { const automation = basicAutomation() if (trigger) { @@ -176,6 +179,16 @@ export function newAutomation({ steps, trigger }: any = {}) { return automation } +export function rowActionAutomation() { + const automation = newAutomation({ + trigger: { + ...automationTrigger(), + stepId: AutomationTriggerStepId.ROW_ACTION, + }, + }) + return automation +} + export function basicAutomation(appId?: string): Automation { return { name: "My Automation",