Updated executev2 tests
This commit is contained in:
parent
d4f2e2bbe3
commit
a200370162
|
@ -21,47 +21,44 @@ describe("Execute Script Automations", () => {
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
it("should execute a basic script and return the result", async () => {
|
it("should execute a basic script and return the result", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Basic Script Execution"
|
||||||
name: "Basic Script Execution",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: {} })
|
.onAppAction()
|
||||||
.executeScriptV2({ code: encodeJS("return 2 + 2") })
|
.executeScriptV2({ code: encodeJS("return 2 + 2") })
|
||||||
.run()
|
.test({ fields: {} })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.value).toEqual(4)
|
expect(results.steps[0].outputs.value).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should access bindings from previous steps", async () => {
|
it("should access bindings from previous steps", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Access Bindings"
|
||||||
name: "Access Bindings",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: { data: [1, 2, 3] } })
|
.onAppAction()
|
||||||
.executeScriptV2(
|
.executeScriptV2(
|
||||||
{
|
{
|
||||||
code: encodeJS(`return $("trigger.fields.data").map(x => x * 2)`),
|
code: encodeJS(`return $("trigger.fields.data").map(x => x * 2)`),
|
||||||
},
|
},
|
||||||
{ stepId: "binding-script-step" }
|
{ stepId: "binding-script-step" }
|
||||||
)
|
)
|
||||||
.run()
|
.test({ fields: { data: [1, 2, 3] } })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.value).toEqual([2, 4, 6])
|
expect(results.steps[0].outputs.value).toEqual([2, 4, 6])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle script execution errors gracefully", async () => {
|
it("should handle script execution errors gracefully", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Handle Script Errors"
|
||||||
name: "Handle Script Errors",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: {} })
|
.onAppAction()
|
||||||
.executeScriptV2({
|
.executeScriptV2({
|
||||||
code: encodeJS("return nonexistentVariable.map(x => x)"),
|
code: encodeJS("return nonexistentVariable.map(x => x)"),
|
||||||
})
|
})
|
||||||
.run()
|
.test({ fields: {} })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.response).toContain(
|
expect(results.steps[0].outputs.response).toContain(
|
||||||
"ReferenceError: nonexistentVariable is not defined"
|
"ReferenceError: nonexistentVariable is not defined"
|
||||||
|
@ -70,12 +67,11 @@ describe("Execute Script Automations", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle conditional logic in scripts", async () => {
|
it("should handle conditional logic in scripts", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Conditional Script Logic"
|
||||||
name: "Conditional Script Logic",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: { value: 10 } })
|
.onAppAction()
|
||||||
.executeScriptV2({
|
.executeScriptV2({
|
||||||
code: encodeJS(`
|
code: encodeJS(`
|
||||||
if ($("trigger.fields.value") > 5) {
|
if ($("trigger.fields.value") > 5) {
|
||||||
|
@ -85,18 +81,17 @@ describe("Execute Script Automations", () => {
|
||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
})
|
})
|
||||||
.run()
|
.test({ fields: { value: 10 } })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.value).toEqual("Value is greater than 5")
|
expect(results.steps[0].outputs.value).toEqual("Value is greater than 5")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use multiple steps and validate script execution", async () => {
|
it("should use multiple steps and validate script execution", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Multi-Step Script Execution"
|
||||||
name: "Multi-Step Script Execution",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: {} })
|
.onAppAction()
|
||||||
.serverLog(
|
.serverLog(
|
||||||
{ text: "Starting multi-step automation" },
|
{ text: "Starting multi-step automation" },
|
||||||
{ stepId: "start-log-step" }
|
{ stepId: "start-log-step" }
|
||||||
|
@ -117,7 +112,7 @@ describe("Execute Script Automations", () => {
|
||||||
.serverLog({
|
.serverLog({
|
||||||
text: `Final result is {{ steps.ScriptingStep1.value }}`,
|
text: `Final result is {{ steps.ScriptingStep1.value }}`,
|
||||||
})
|
})
|
||||||
.run()
|
.test({ fields: {} })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.message).toContain(
|
expect(results.steps[0].outputs.message).toContain(
|
||||||
"Starting multi-step automation"
|
"Starting multi-step automation"
|
||||||
|
@ -128,16 +123,15 @@ describe("Execute Script Automations", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should fail if the code has not been encoded as a handlebars template", async () => {
|
it("should fail if the code has not been encoded as a handlebars template", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Invalid Code Encoding"
|
||||||
name: "Invalid Code Encoding",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: {} })
|
.onAppAction()
|
||||||
.executeScriptV2({
|
.executeScriptV2({
|
||||||
code: "return 2 + 2",
|
code: "return 2 + 2",
|
||||||
})
|
})
|
||||||
.run()
|
.test({ fields: {} })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.response.message).toEqual(
|
expect(results.steps[0].outputs.response.message).toEqual(
|
||||||
"Expected code to be a {{ js }} template block"
|
"Expected code to be a {{ js }} template block"
|
||||||
|
@ -146,16 +140,15 @@ describe("Execute Script Automations", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("does not process embedded handlebars templates", async () => {
|
it("does not process embedded handlebars templates", async () => {
|
||||||
const builder = createAutomationBuilder({
|
config.name = "Embedded Handlebars"
|
||||||
name: "Embedded Handlebars",
|
const builder = createAutomationBuilder(config)
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
const results = await builder
|
||||||
.appAction({ fields: {} })
|
.onAppAction()
|
||||||
.executeScriptV2({
|
.executeScriptV2({
|
||||||
code: encodeJS(`return "{{ triggers.row.whatever }}"`),
|
code: encodeJS(`return "{{ triggers.row.whatever }}"`),
|
||||||
})
|
})
|
||||||
.run()
|
.test({ fields: {} })
|
||||||
|
|
||||||
expect(results.steps[0].outputs.value).toEqual(
|
expect(results.steps[0].outputs.value).toEqual(
|
||||||
"{{ triggers.row.whatever }}"
|
"{{ triggers.row.whatever }}"
|
||||||
|
|
|
@ -97,6 +97,7 @@ class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
||||||
loop = this.step(AutomationActionStepId.LOOP)
|
loop = this.step(AutomationActionStepId.LOOP)
|
||||||
serverLog = this.step(AutomationActionStepId.SERVER_LOG)
|
serverLog = this.step(AutomationActionStepId.SERVER_LOG)
|
||||||
executeScript = this.step(AutomationActionStepId.EXECUTE_SCRIPT)
|
executeScript = this.step(AutomationActionStepId.EXECUTE_SCRIPT)
|
||||||
|
executeScriptV2 = this.step(AutomationActionStepId.EXECUTE_SCRIPT_V2)
|
||||||
filter = this.step(AutomationActionStepId.FILTER)
|
filter = this.step(AutomationActionStepId.FILTER)
|
||||||
bash = this.step(AutomationActionStepId.EXECUTE_BASH)
|
bash = this.step(AutomationActionStepId.EXECUTE_BASH)
|
||||||
openai = this.step(AutomationActionStepId.OPENAI)
|
openai = this.step(AutomationActionStepId.OPENAI)
|
||||||
|
|
|
@ -98,6 +98,7 @@ export default class TestConfiguration {
|
||||||
request?: supertest.SuperTest<supertest.Test>
|
request?: supertest.SuperTest<supertest.Test>
|
||||||
started: boolean
|
started: boolean
|
||||||
appId?: string
|
appId?: string
|
||||||
|
name?: string
|
||||||
allApps: App[]
|
allApps: App[]
|
||||||
app?: App
|
app?: App
|
||||||
prodApp?: App
|
prodApp?: App
|
||||||
|
|
Loading…
Reference in New Issue