Add tests
This commit is contained in:
parent
d9029da533
commit
8678db18e2
|
@ -99,7 +99,7 @@ export async function destroy(ctx: UserCtx<void, DeleteAutomationResponse>) {
|
||||||
if (
|
if (
|
||||||
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
|
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)
|
ctx.body = await sdk.automations.remove(automationId, ctx.params.rev)
|
||||||
|
|
|
@ -425,6 +425,19 @@ describe("/automations", () => {
|
||||||
expect(events.automation.deleted).toHaveBeenCalledTimes(1)
|
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 () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
const automation = await config.createAutomation()
|
const automation = await config.createAutomation()
|
||||||
await checkBuilderEndpoint({
|
await checkBuilderEndpoint({
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { sample } from "lodash/fp"
|
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 automationSdk from "../"
|
||||||
import { structures } from "../../../../api/routes/tests/utilities"
|
import { structures } from "../../../../api/routes/tests/utilities"
|
||||||
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
||||||
|
@ -12,6 +13,38 @@ describe("automation sdk", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
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([
|
it.each([
|
||||||
["trigger", (a: Automation) => a.definition.trigger],
|
["trigger", (a: Automation) => a.definition.trigger],
|
||||||
["step", (a: Automation) => a.definition.steps[0]],
|
["step", (a: Automation) => a.definition.steps[0]],
|
||||||
|
|
|
@ -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()
|
const automation = basicAutomation()
|
||||||
|
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
|
@ -176,6 +179,16 @@ export function newAutomation({ steps, trigger }: any = {}) {
|
||||||
return automation
|
return automation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rowActionAutomation() {
|
||||||
|
const automation = newAutomation({
|
||||||
|
trigger: {
|
||||||
|
...automationTrigger(),
|
||||||
|
stepId: AutomationTriggerStepId.ROW_ACTION,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return automation
|
||||||
|
}
|
||||||
|
|
||||||
export function basicAutomation(appId?: string): Automation {
|
export function basicAutomation(appId?: string): Automation {
|
||||||
return {
|
return {
|
||||||
name: "My Automation",
|
name: "My Automation",
|
||||||
|
|
Loading…
Reference in New Issue