Fix type errors.
This commit is contained in:
parent
d4a55b743d
commit
378cdbe163
|
@ -485,6 +485,36 @@ describe("/automations", () => {
|
||||||
expect(events.automation.created).not.toHaveBeenCalled()
|
expect(events.automation.created).not.toHaveBeenCalled()
|
||||||
expect(events.automation.triggerUpdated).not.toHaveBeenCalled()
|
expect(events.automation.triggerUpdated).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can update an input field", async () => {
|
||||||
|
const { automation } = await createAutomationBuilder(config)
|
||||||
|
.onRowDeleted({ tableId: "tableId" })
|
||||||
|
.serverLog({ text: "test" })
|
||||||
|
.save()
|
||||||
|
|
||||||
|
automation.definition.trigger.inputs.tableId = "newTableId"
|
||||||
|
const { automation: updatedAutomation } =
|
||||||
|
await config.api.automation.update(automation)
|
||||||
|
|
||||||
|
expect(updatedAutomation.definition.trigger.inputs.tableId).toEqual(
|
||||||
|
"newTableId"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("cannot update a readonly field", async () => {
|
||||||
|
const { automation } = await createAutomationBuilder(config)
|
||||||
|
.onRowAction({ tableId: "tableId" })
|
||||||
|
.serverLog({ text: "test" })
|
||||||
|
.save()
|
||||||
|
|
||||||
|
automation.definition.trigger.inputs.tableId = "newTableId"
|
||||||
|
await config.api.automation.update(automation, {
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message: "Field tableId is readonly and it cannot be modified",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
|
|
|
@ -63,6 +63,7 @@ class TriggerBuilder {
|
||||||
onRowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
onRowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
||||||
onWebhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
onWebhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
||||||
onCron = this.trigger(AutomationTriggerStepId.CRON)
|
onCron = this.trigger(AutomationTriggerStepId.CRON)
|
||||||
|
onRowAction = this.trigger(AutomationTriggerStepId.ROW_ACTION)
|
||||||
}
|
}
|
||||||
|
|
||||||
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
||||||
|
|
|
@ -40,7 +40,8 @@ function cleanAutomationInputs(automation: Automation) {
|
||||||
if (step == null) {
|
if (step == null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let inputName of Object.keys(step.inputs)) {
|
for (const key of Object.keys(step.inputs)) {
|
||||||
|
const inputName = key as keyof typeof step.inputs
|
||||||
if (!step.inputs[inputName] || step.inputs[inputName] === "") {
|
if (!step.inputs[inputName] || step.inputs[inputName] === "") {
|
||||||
delete step.inputs[inputName]
|
delete step.inputs[inputName]
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,8 @@ function guardInvalidUpdatesAndThrow(
|
||||||
const readonlyFields = Object.keys(
|
const readonlyFields = Object.keys(
|
||||||
step.schema.inputs.properties || {}
|
step.schema.inputs.properties || {}
|
||||||
).filter(k => step.schema.inputs.properties[k].readonly)
|
).filter(k => step.schema.inputs.properties[k].readonly)
|
||||||
readonlyFields.forEach(readonlyField => {
|
readonlyFields.forEach(key => {
|
||||||
|
const readonlyField = key as keyof typeof step.inputs
|
||||||
const oldStep = oldStepDefinitions.find(i => i.id === step.id)
|
const oldStep = oldStepDefinitions.find(i => i.id === step.id)
|
||||||
if (step.inputs[readonlyField] !== oldStep?.inputs[readonlyField]) {
|
if (step.inputs[readonlyField] !== oldStep?.inputs[readonlyField]) {
|
||||||
throw new HTTPError(
|
throw new HTTPError(
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
import { sample } from "lodash/fp"
|
|
||||||
import { Automation } from "@budibase/types"
|
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
|
||||||
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
|
||||||
import automationSdk from "../"
|
|
||||||
import { structures } from "../../../../api/routes/tests/utilities"
|
|
||||||
|
|
||||||
describe("automation sdk", () => {
|
|
||||||
const config = new TestConfiguration()
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await config.init()
|
|
||||||
})
|
|
||||||
|
|
||||||
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.each([
|
|
||||||
["trigger", (a: Automation) => a.definition.trigger],
|
|
||||||
["step", (a: Automation) => a.definition.steps[0]],
|
|
||||||
])("can update input fields (for a %s)", async (_, getStep) => {
|
|
||||||
await config.doInContext(config.getAppId(), async () => {
|
|
||||||
const automation = structures.newAutomation()
|
|
||||||
|
|
||||||
const keyToUse = sample(Object.keys(getStep(automation).inputs))!
|
|
||||||
getStep(automation).inputs[keyToUse] = "anyValue"
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
|
||||||
|
|
||||||
const update = { ...response }
|
|
||||||
getStep(update).inputs[keyToUse] = "anyUpdatedValue"
|
|
||||||
const result = await automationSdk.update(update)
|
|
||||||
expect(getStep(result).inputs[keyToUse]).toEqual("anyUpdatedValue")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
["trigger", (a: Automation) => a.definition.trigger],
|
|
||||||
["step", (a: Automation) => a.definition.steps[0]],
|
|
||||||
])("cannot update readonly fields (for a %s)", async (_, getStep) => {
|
|
||||||
await config.doInContext(config.getAppId(), async () => {
|
|
||||||
const automation = structures.newAutomation()
|
|
||||||
getStep(automation).schema.inputs.properties["readonlyProperty"] = {
|
|
||||||
readonly: true,
|
|
||||||
}
|
|
||||||
getStep(automation).inputs["readonlyProperty"] = "anyValue"
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
|
||||||
|
|
||||||
const update = { ...response }
|
|
||||||
getStep(update).inputs["readonlyProperty"] = "anyUpdatedValue"
|
|
||||||
await expect(automationSdk.update(update)).rejects.toThrow(
|
|
||||||
"Field readonlyProperty is readonly and it cannot be modified"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -35,6 +35,8 @@ import {
|
||||||
WebhookActionType,
|
WebhookActionType,
|
||||||
BuiltinPermissionID,
|
BuiltinPermissionID,
|
||||||
DeepPartial,
|
DeepPartial,
|
||||||
|
FilterCondition,
|
||||||
|
AutomationTriggerResult,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { LoopInput } from "../../definitions/automations"
|
import { LoopInput } from "../../definitions/automations"
|
||||||
import { merge } from "lodash"
|
import { merge } from "lodash"
|
||||||
|
@ -372,7 +374,11 @@ export function filterAutomation(opts?: DeepPartial<Automation>): Automation {
|
||||||
type: AutomationStepType.ACTION,
|
type: AutomationStepType.ACTION,
|
||||||
internal: true,
|
internal: true,
|
||||||
stepId: AutomationActionStepId.FILTER,
|
stepId: AutomationActionStepId.FILTER,
|
||||||
inputs: { field: "name", value: "test", condition: "EQ" },
|
inputs: {
|
||||||
|
field: "name",
|
||||||
|
value: "test",
|
||||||
|
condition: FilterCondition.EQUAL,
|
||||||
|
},
|
||||||
schema: BUILTIN_ACTION_DEFINITIONS.EXECUTE_SCRIPT.schema,
|
schema: BUILTIN_ACTION_DEFINITIONS.EXECUTE_SCRIPT.schema,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -437,15 +443,24 @@ export function updateRowAutomationWithFilters(
|
||||||
export function basicAutomationResults(
|
export function basicAutomationResults(
|
||||||
automationId: string
|
automationId: string
|
||||||
): AutomationResults {
|
): AutomationResults {
|
||||||
|
const trigger: AutomationTriggerResult = {
|
||||||
|
id: "trigger",
|
||||||
|
stepId: AutomationTriggerStepId.APP,
|
||||||
|
outputs: {},
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
automationId,
|
automationId,
|
||||||
status: AutomationStatus.SUCCESS,
|
status: AutomationStatus.SUCCESS,
|
||||||
trigger: "trigger" as any,
|
trigger,
|
||||||
steps: [
|
steps: [
|
||||||
|
trigger,
|
||||||
{
|
{
|
||||||
|
id: "step1",
|
||||||
stepId: AutomationActionStepId.SERVER_LOG,
|
stepId: AutomationActionStepId.SERVER_LOG,
|
||||||
inputs: {},
|
inputs: {},
|
||||||
outputs: {},
|
outputs: {
|
||||||
|
success: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue