Rename run to test to better reflect the API being hit.

This commit is contained in:
Sam Rose 2025-02-06 15:58:15 +00:00
parent 9f28eb00d4
commit 924f400992
No known key found for this signature in database
10 changed files with 78 additions and 78 deletions

View File

@ -251,7 +251,7 @@ describe("/automations", () => {
.serverLog({
text: "{{ settings.company }}",
})
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.message).toEndWith("https://example.com")
expect(result.steps[1].outputs.message).toEndWith(

View File

@ -76,7 +76,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[3].outputs.status).toContain("branch1 branch taken")
expect(results.steps[4].outputs.message).toContain("Branch 1.1")
@ -100,7 +100,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { status: "active" } })
.test({ fields: { status: "active" } })
expect(results.steps[0].outputs.status).toContain(
"activeBranch branch taken"
)
@ -130,7 +130,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { status: "active", role: "admin" } })
.test({ fields: { status: "active", role: "admin" } })
expect(results.steps[1].outputs.message).toContain("Active admin user")
})
@ -162,7 +162,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { status: "test", role: "user" } })
.test({ fields: { status: "test", role: "user" } })
expect(results.steps[1].outputs.message).toContain("Special user")
})
@ -195,7 +195,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { status: "test", role: "user" } })
.test({ fields: { status: "test", role: "user" } })
expect(results.steps[1].outputs.status).toEqual(
AutomationStatus.NO_CONDITION_MET
@ -239,7 +239,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { test_trigger: true } })
.test({ fields: { test_trigger: true } })
expect(results.steps[2].outputs.message).toContain("Special user")
})
@ -276,7 +276,7 @@ describe("Branching automations", () => {
},
},
})
.run({ fields: { test_trigger: true } })
.test({ fields: { test_trigger: true } })
expect(results.steps[2].outputs.message).toContain("Special user")
})

View File

@ -38,7 +38,7 @@ describe("Automation Scenarios", () => {
tableId: table._id,
},
})
.run({
.test({
row: { name: "Test", description: "TEST" },
id: "1234",
})
@ -67,7 +67,7 @@ describe("Automation Scenarios", () => {
.queryRows({
tableId: table._id!,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps).toHaveLength(1)
expect(results.steps[0].outputs.rows).toHaveLength(2)
@ -93,7 +93,7 @@ describe("Automation Scenarios", () => {
.queryRows({
tableId: table._id!,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps).toHaveLength(3)
expect(results.steps[1].outputs.success).toBeTruthy()
@ -153,7 +153,7 @@ describe("Automation Scenarios", () => {
},
{ stepName: "QueryRowsStep" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps).toHaveLength(3)
@ -207,7 +207,7 @@ describe("Automation Scenarios", () => {
.queryRows({
tableId: table._id!,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps).toHaveLength(3)
expect(results.steps[1].outputs.success).toBeTruthy()
@ -260,7 +260,7 @@ describe("Automation Scenarios", () => {
value: 20,
})
.serverLog({ text: "Equal condition met" })
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[2].outputs.success).toBeTrue()
expect(results.steps[2].outputs.result).toBeFalse()
@ -286,7 +286,7 @@ describe("Automation Scenarios", () => {
value: 20,
})
.serverLog({ text: "Not Equal condition met" })
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[2].outputs.success).toBeTrue()
expect(results.steps[2].outputs.result).toBeTrue()
@ -355,7 +355,7 @@ describe("Automation Scenarios", () => {
.serverLog({
text: `${condition} condition ${expectPass ? "passed" : "failed"}`,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[2].outputs.result).toBe(expectPass)
if (expectPass) {
@ -373,7 +373,7 @@ describe("Automation Scenarios", () => {
const results = await createAutomationBuilder(config)
.onRowUpdated({ tableId: table._id! })
.serverLog({ text: "{{ [user].[email] }}" })
.run({
.test({
row: { name: "Test", description: "TEST" },
id: "1234",
})
@ -385,7 +385,7 @@ describe("Automation Scenarios", () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.serverLog({ text: "{{ [user].[email] }}" })
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[0].outputs.message).toContain("example.com")
})
@ -475,7 +475,7 @@ if (descriptions.length) {
.queryRows({
tableId: newTable._id!,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps).toHaveLength(3)

View File

@ -34,7 +34,7 @@ describe("Execute Bash Automations", () => {
{ text: "Bash output was: {{ steps.[Echo Command].stdout }}" },
{ stepName: "Log Output" }
)
.run()
.test()
expect(result.steps[0].outputs.stdout).toEqual("hello world\n")
expect(result.steps[1].outputs.message).toContain(
@ -57,7 +57,7 @@ describe("Execute Bash Automations", () => {
{ code: "rm {{ trigger.fields.filename }}" },
{ stepName: "Cleanup" }
)
.run()
.test()
expect(result.steps[1].outputs.stdout).toEqual("INITIAL CONTENT\n")
expect(result.steps[1].outputs.success).toEqual(true)
@ -112,7 +112,7 @@ describe("Execute Bash Automations", () => {
{ text: "Value was {{ steps.[Check Value].value }}" },
{ stepName: "Log Result" }
)
.run()
.test()
expect(result.steps[0].outputs.stdout).toEqual("10\n")
expect(result.steps[1].outputs.value).toEqual("high")

View File

@ -48,7 +48,7 @@ describe("test the create row action", () => {
{ text: "Row created with ID: {{ stepsByName.CreateRow.row._id }}" },
{ stepName: "CreationLog" }
)
.run()
.test()
expect(result.steps[1].outputs.success).toBeDefined()
expect(result.steps[1].outputs.id).toBeDefined()
@ -78,7 +78,7 @@ describe("test the create row action", () => {
},
{ stepName: "CreateRow" }
)
.run()
.test()
expect(result.steps[1].outputs.success).toEqual(false)
})
@ -97,7 +97,7 @@ describe("test the create row action", () => {
{ text: "This log should not appear" },
{ stepName: "SkippedLog" }
)
.run()
.test()
expect(result.steps[1].outputs.success).toEqual(false)
expect(result.steps.length).toBeLessThan(4)
@ -140,7 +140,7 @@ describe("test the create row action", () => {
},
{ stepName: "UploadLog" }
)
.run()
.test()
expect(result.steps[1].outputs.success).toEqual(true)
expect(result.steps[1].outputs.row.file_attachment[0]).toHaveProperty("key")
@ -209,7 +209,7 @@ describe("test the create row action", () => {
},
},
})
.run()
.test()
expect(result.steps[1].outputs.success).toEqual(true)
expect(result.steps[1].outputs.row.single_file_attachment).toHaveProperty(
@ -278,7 +278,7 @@ describe("test the create row action", () => {
},
},
})
.run()
.test()
expect(result.steps[1].outputs.success).toEqual(false)
expect(result.steps[1].outputs.response).toEqual(

View File

@ -23,7 +23,7 @@ describe("Execute Script Automations", () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.executeScript({ code: "return 2 + 2" })
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[0].outputs.value).toEqual(4)
})
@ -37,7 +37,7 @@ describe("Execute Script Automations", () => {
},
{ stepId: "binding-script-step" }
)
.run({ fields: { data: [1, 2, 3] } })
.test({ fields: { data: [1, 2, 3] } })
expect(results.steps[0].outputs.value).toEqual([2, 4, 6])
})
@ -46,7 +46,7 @@ describe("Execute Script Automations", () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.executeScript({ code: "return nonexistentVariable.map(x => x)" })
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[0].outputs.response).toContain(
"ReferenceError: nonexistentVariable is not defined"
@ -66,7 +66,7 @@ describe("Execute Script Automations", () => {
}
`,
})
.run({ fields: { value: 10 } })
.test({ fields: { value: 10 } })
expect(results.steps[0].outputs.value).toEqual("Value is greater than 5")
})
@ -94,7 +94,7 @@ describe("Execute Script Automations", () => {
.serverLog({
text: `Final result is {{ steps.ScriptingStep1.value }}`,
})
.run({ fields: {} })
.test({ fields: {} })
expect(results.steps[0].outputs.message).toContain(
"Starting multi-step automation"

View File

@ -95,7 +95,7 @@ describe("Attempt to run a basic loop automation", () => {
tableId: table._id,
},
})
.run()
.test()
expect(results.trigger).toBeDefined()
expect(results.steps).toHaveLength(1)
@ -136,7 +136,7 @@ describe("Attempt to run a basic loop automation", () => {
})
.serverLog({ text: "Message {{loop.currentItem}}" })
.serverLog({ text: "{{steps.1.rows.0._id}}" })
.run()
.test()
results.steps[1].outputs.items.forEach(
(output: ServerLogStepOutputs, index: number) => {
@ -240,7 +240,7 @@ describe("Attempt to run a basic loop automation", () => {
binding: "Message 1,Message 2,Message 3",
})
.serverLog({ text: "{{loop.currentItem}}" })
.run()
.test()
expect(results.trigger).toBeDefined()
expect(results.steps).toHaveLength(2)

View File

@ -60,7 +60,7 @@ describe("test the openai action", () => {
createAutomationBuilder(config)
.onAppAction()
.openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI })
.run({ fields: {} })
.test({ fields: {} })
)
expect(result.steps[0].outputs.response).toEqual("This is a test")
@ -72,7 +72,7 @@ describe("test the openai action", () => {
createAutomationBuilder(config)
.onAppAction()
.openai({ prompt: "", model: Model.GPT_4O_MINI })
.run({ fields: {} })
.test({ fields: {} })
)
expect(result.steps[0].outputs.response).toEqual(
@ -88,7 +88,7 @@ describe("test the openai action", () => {
createAutomationBuilder(config)
.onAppAction()
.openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI })
.run({ fields: {} })
.test({ fields: {} })
)
expect(result.steps[0].outputs.response).toEqual(
@ -111,7 +111,7 @@ describe("test the openai action", () => {
createAutomationBuilder(config)
.onAppAction()
.openai({ model: Model.GPT_4O_MINI, prompt: "Hello, world" })
.run({ fields: {} })
.test({ fields: {} })
)
expect(result.steps[0].outputs.response).toEqual("This is a test")

View File

@ -44,7 +44,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query All Rows" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
@ -65,7 +65,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query With Empty Filter" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
@ -88,7 +88,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query With Return None" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
@ -114,7 +114,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query With Null Filter" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
@ -135,7 +135,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query With Return All" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
@ -160,7 +160,7 @@ describe("Test a query step automation", () => {
},
{ stepName: "Query table with spaces" }
)
.run({ fields: {} })
.test({ fields: {} })
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
expect(result.steps[0].outputs.rows.length).toBe(1)

View File

@ -31,7 +31,7 @@ type BranchConfig = {
}
class TriggerBuilder {
private config: TestConfiguration
private readonly config: TestConfiguration
constructor(config: TestConfiguration) {
this.config = config
@ -64,10 +64,10 @@ class TriggerBuilder {
}
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
protected steps: AutomationStep[] = []
protected stepNames: { [key: string]: string } = {}
protected readonly steps: AutomationStep[] = []
protected readonly stepNames: { [key: string]: string } = {}
protected createStepFn<TStep extends AutomationActionStepId>(stepId: TStep) {
protected step<TStep extends AutomationActionStepId>(stepId: TStep) {
return (
inputs: AutomationStepInputs<TStep>,
opts?: { stepName?: string; stepId?: string }
@ -88,28 +88,28 @@ class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
}
}
createRow = this.createStepFn(AutomationActionStepId.CREATE_ROW)
updateRow = this.createStepFn(AutomationActionStepId.UPDATE_ROW)
deleteRow = this.createStepFn(AutomationActionStepId.DELETE_ROW)
sendSmtpEmail = this.createStepFn(AutomationActionStepId.SEND_EMAIL_SMTP)
executeQuery = this.createStepFn(AutomationActionStepId.EXECUTE_QUERY)
queryRows = this.createStepFn(AutomationActionStepId.QUERY_ROWS)
loop = this.createStepFn(AutomationActionStepId.LOOP)
serverLog = this.createStepFn(AutomationActionStepId.SERVER_LOG)
executeScript = this.createStepFn(AutomationActionStepId.EXECUTE_SCRIPT)
filter = this.createStepFn(AutomationActionStepId.FILTER)
bash = this.createStepFn(AutomationActionStepId.EXECUTE_BASH)
openai = this.createStepFn(AutomationActionStepId.OPENAI)
collect = this.createStepFn(AutomationActionStepId.COLLECT)
zapier = this.createStepFn(AutomationActionStepId.zapier)
triggerAutomationRun = this.createStepFn(
createRow = this.step(AutomationActionStepId.CREATE_ROW)
updateRow = this.step(AutomationActionStepId.UPDATE_ROW)
deleteRow = this.step(AutomationActionStepId.DELETE_ROW)
sendSmtpEmail = this.step(AutomationActionStepId.SEND_EMAIL_SMTP)
executeQuery = this.step(AutomationActionStepId.EXECUTE_QUERY)
queryRows = this.step(AutomationActionStepId.QUERY_ROWS)
loop = this.step(AutomationActionStepId.LOOP)
serverLog = this.step(AutomationActionStepId.SERVER_LOG)
executeScript = this.step(AutomationActionStepId.EXECUTE_SCRIPT)
filter = this.step(AutomationActionStepId.FILTER)
bash = this.step(AutomationActionStepId.EXECUTE_BASH)
openai = this.step(AutomationActionStepId.OPENAI)
collect = this.step(AutomationActionStepId.COLLECT)
zapier = this.step(AutomationActionStepId.zapier)
triggerAutomationRun = this.step(
AutomationActionStepId.TRIGGER_AUTOMATION_RUN
)
outgoingWebhook = this.createStepFn(AutomationActionStepId.OUTGOING_WEBHOOK)
n8n = this.createStepFn(AutomationActionStepId.n8n)
make = this.createStepFn(AutomationActionStepId.integromat)
discord = this.createStepFn(AutomationActionStepId.discord)
delay = this.createStepFn(AutomationActionStepId.DELAY)
outgoingWebhook = this.step(AutomationActionStepId.OUTGOING_WEBHOOK)
n8n = this.step(AutomationActionStepId.n8n)
make = this.step(AutomationActionStepId.integromat)
discord = this.step(AutomationActionStepId.discord)
delay = this.step(AutomationActionStepId.DELAY)
protected addBranchStep(branchConfig: BranchConfig): void {
const inputs: BranchStepInputs = {
@ -142,8 +142,8 @@ class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
class StepBuilder<
TStep extends AutomationTriggerStepId
> extends BranchStepBuilder<TStep> {
private config: TestConfiguration
private trigger: AutomationTrigger
private readonly config: TestConfiguration
private readonly trigger: AutomationTrigger
private _name: string | undefined = undefined
constructor(config: TestConfiguration, trigger: AutomationTrigger) {
@ -176,26 +176,26 @@ class StepBuilder<
return new AutomationRunner<TStep>(this.config, automation)
}
async run(outputs: AutomationTriggerOutputs<TStep>) {
async test(triggerOutput: AutomationTriggerOutputs<TStep>) {
const runner = await this.save()
return await runner.run(outputs)
return await runner.test(triggerOutput)
}
}
class AutomationRunner<TStep extends AutomationTriggerStepId> {
private config: TestConfiguration
automation: Automation
private readonly config: TestConfiguration
readonly automation: Automation
constructor(config: TestConfiguration, automation: Automation) {
this.config = config
this.automation = automation
}
async run(outputs: AutomationTriggerOutputs<TStep>) {
async test(triggerOutput: AutomationTriggerOutputs<TStep>) {
const response = await this.config.api.automation.test(
this.automation._id!,
// TODO: figure out why this cast is needed.
outputs as TestAutomationRequest
triggerOutput as TestAutomationRequest
)
if (isDidNotTriggerResponse(response)) {