Add extra tests
This commit is contained in:
parent
f91ec1de21
commit
08a6ac3919
|
@ -1,4 +1,4 @@
|
||||||
import _ from "lodash/fp"
|
import { sample } from "lodash/fp"
|
||||||
import { Automation } from "@budibase/types"
|
import { Automation } from "@budibase/types"
|
||||||
import automationSdk from "../"
|
import automationSdk from "../"
|
||||||
import { structures } from "../../../../api/routes/tests/utilities"
|
import { structures } from "../../../../api/routes/tests/utilities"
|
||||||
|
@ -12,39 +12,40 @@ describe("automation sdk", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
it("can update input fields", async () => {
|
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 () => {
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const automation: Automation = structures.newAutomation()
|
const automation = structures.newAutomation()
|
||||||
const keyToUse = _.sample(
|
|
||||||
Object.keys(automation.definition.trigger.inputs)
|
const keyToUse = sample(Object.keys(getStep(automation).inputs))!
|
||||||
)!
|
getStep(automation).inputs[keyToUse] = "anyValue"
|
||||||
automation.definition.trigger.inputs[keyToUse] = "anyValue"
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
const response = await automationSdk.create(automation)
|
||||||
|
|
||||||
const update = { ...response }
|
const update = { ...response }
|
||||||
update.definition.trigger.inputs[keyToUse] = "anyUpdatedValue"
|
getStep(update).inputs[keyToUse] = "anyUpdatedValue"
|
||||||
const result = await automationSdk.update(update)
|
const result = await automationSdk.update(update)
|
||||||
expect(result.definition.trigger.inputs[keyToUse]).toEqual(
|
expect(getStep(result).inputs[keyToUse]).toEqual("anyUpdatedValue")
|
||||||
"anyUpdatedValue"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("cannot update readonly fields", async () => {
|
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 () => {
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const automation: Automation = { ...structures.newAutomation() }
|
const automation = structures.newAutomation()
|
||||||
automation.definition.trigger.schema.inputs.properties[
|
getStep(automation).schema.inputs.properties["readonlyProperty"] = {
|
||||||
"readonlyProperty"
|
|
||||||
] = {
|
|
||||||
readonly: true,
|
readonly: true,
|
||||||
}
|
}
|
||||||
automation.definition.trigger.inputs["readonlyProperty"] = "anyValue"
|
getStep(automation).inputs["readonlyProperty"] = "anyValue"
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
const response = await automationSdk.create(automation)
|
||||||
|
|
||||||
const update = { ...response }
|
const update = { ...response }
|
||||||
update.definition.trigger.inputs["readonlyProperty"] = "anyUpdatedValue"
|
getStep(update).inputs["readonlyProperty"] = "anyUpdatedValue"
|
||||||
await expect(automationSdk.update(update)).rejects.toThrow(
|
await expect(automationSdk.update(update)).rejects.toThrow(
|
||||||
"Field readonlyProperty is readonly and it cannot be modified"
|
"Field readonlyProperty is readonly and it cannot be modified"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue