Skip to content

Commit

Permalink
Simplify calls to createAutomationBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwho committed Feb 5, 2025
1 parent d290246 commit d62be26
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 143 deletions.
26 changes: 5 additions & 21 deletions packages/server/src/api/routes/tests/automation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ describe("/automations", () => {
})

it("Should ensure you can't have a branch as not a last step", async () => {
const automation = createAutomationBuilder({
name: "String Equality Branching",
appId: config.getAppId(),
})
const automation = createAutomationBuilder(config)
.appAction({ fields: { status: "active" } })
.branch({
activeBranch: {
Expand All @@ -134,10 +131,7 @@ describe("/automations", () => {
})

it("Should check validation on an automation that has a branch step with no children", async () => {
const automation = createAutomationBuilder({
name: "String Equality Branching",
appId: config.getAppId(),
})
const automation = createAutomationBuilder(config)
.appAction({ fields: { status: "active" } })
.branch({})
.serverLog({ text: "Inactive user" })
Expand All @@ -153,10 +147,7 @@ describe("/automations", () => {
})

it("Should check validation on a branch step with empty conditions", async () => {
const automation = createAutomationBuilder({
name: "String Equality Branching",
appId: config.getAppId(),
})
const automation = createAutomationBuilder(config)
.appAction({ fields: { status: "active" } })
.branch({
activeBranch: {
Expand All @@ -177,10 +168,7 @@ describe("/automations", () => {
})

it("Should check validation on an branch that has a condition that is not valid", async () => {
const automation = createAutomationBuilder({
name: "String Equality Branching",
appId: config.getAppId(),
})
const automation = createAutomationBuilder(config)
.appAction({ fields: { status: "active" } })
.branch({
activeBranch: {
Expand Down Expand Up @@ -252,11 +240,7 @@ describe("/automations", () => {
})

it("should be able to access platformUrl, logoUrl and company in the automation", async () => {
const result = await createAutomationBuilder({
name: "Test Automation",
appId: config.getAppId(),
config,
})
const result = await createAutomationBuilder(config)
.serverLog({
text: "{{ settings.url }}",
})
Expand Down
14 changes: 7 additions & 7 deletions packages/server/src/automations/tests/branching.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Branching automations", () => {
const branch2LogId = "33333333-3333-3333-3333-333333333333"
const branch2Id = "44444444-4444-4444-4444-444444444444"

const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.serverLog(
{ text: "Starting automation" },
{ stepName: "FirstLog", stepId: firstLogId }
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("Branching automations", () => {
})

it("should execute correct branch based on string equality", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { status: "active" } })
.branch({
activeBranch: {
Expand All @@ -107,7 +107,7 @@ describe("Branching automations", () => {
})

it("should handle multiple conditions with AND operator", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { status: "active", role: "admin" } })
.branch({
activeAdminBranch: {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("Branching automations", () => {
})

it("should handle multiple conditions with OR operator", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { status: "test", role: "user" } })
.branch({
specialBranch: {
Expand Down Expand Up @@ -167,7 +167,7 @@ describe("Branching automations", () => {
})

it("should stop the branch automation when no conditions are met", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { status: "test", role: "user" } })
.createRow({ row: { name: "Test", tableId: table._id } })
.branch({
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("Branching automations", () => {
})

it("evaluate multiple conditions", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { test_trigger: true } })
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
.branch({
Expand Down Expand Up @@ -244,7 +244,7 @@ describe("Branching automations", () => {
})

it("evaluate multiple conditions with interpolated text", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({ fields: { test_trigger: true } })
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
.branch({
Expand Down
22 changes: 11 additions & 11 deletions packages/server/src/automations/tests/scenarios.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Automation Scenarios", () => {
it("should trigger an automation which then creates a row", async () => {
const table = await config.api.table.save(basicTable())

const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.rowUpdated(
{ tableId: table._id! },
{
Expand Down Expand Up @@ -65,7 +65,7 @@ describe("Automation Scenarios", () => {
}
await config.api.row.save(table._id!, row)
await config.api.row.save(table._id!, row)
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.queryRows({
tableId: table._id!,
})
Expand All @@ -83,7 +83,7 @@ describe("Automation Scenarios", () => {
}
await config.api.row.save(table._id!, row)
await config.api.row.save(table._id!, row)
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.queryRows({
tableId: table._id!,
})
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("Automation Scenarios", () => {
},
})

const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.createRow(
{
row: {
Expand Down Expand Up @@ -192,7 +192,7 @@ describe("Automation Scenarios", () => {
}
await config.api.row.save(table._id!, row)
await config.api.row.save(table._id!, row)
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.queryRows(
{
tableId: table._id!,
Expand Down Expand Up @@ -241,7 +241,7 @@ describe("Automation Scenarios", () => {
})

it("should stop an automation if the condition is not met", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.createRow({
row: {
name: "Equal Test",
Expand All @@ -266,7 +266,7 @@ describe("Automation Scenarios", () => {
})

it("should continue the automation if the condition is met", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.createRow({
row: {
name: "Not Equal Test",
Expand Down Expand Up @@ -332,7 +332,7 @@ describe("Automation Scenarios", () => {
it.each(testCases)(
"should pass the filter when condition is $condition",
async ({ condition, value, rowValue, expectPass }) => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.createRow({
row: {
name: `${condition} Test`,
Expand Down Expand Up @@ -366,7 +366,7 @@ describe("Automation Scenarios", () => {
it("Check user is passed through from row trigger", async () => {
const table = await config.api.table.save(basicTable())

const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.rowUpdated(
{ tableId: table._id! },
{
Expand All @@ -381,7 +381,7 @@ describe("Automation Scenarios", () => {
})

it("Check user is passed through from app trigger", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.serverLog({ text: "{{ [user].[email] }}" })
.run()

Expand Down Expand Up @@ -452,7 +452,7 @@ if (descriptions.length) {
queryVerb: "read",
})

const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.appAction({
fields: {},
})
Expand Down
10 changes: 5 additions & 5 deletions packages/server/src/automations/tests/steps/bash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Execute Bash Automations", () => {
})

it("should use trigger data in bash command and pass output to subsequent steps", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { command: "hello world" } })
.bash(
{ code: "echo '{{ trigger.fields.command }}'" },
Expand All @@ -43,7 +43,7 @@ describe("Execute Bash Automations", () => {
})

it("should chain multiple bash commands using previous outputs", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { filename: "testfile.txt" } })
.bash(
{ code: "echo 'initial content' > {{ trigger.fields.filename }}" },
Expand All @@ -64,7 +64,7 @@ describe("Execute Bash Automations", () => {
})

it("should integrate bash output with row operations", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.queryRows(
{
tableId: table._id!,
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("Execute Bash Automations", () => {
})

it("should handle bash output in conditional logic", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { threshold: "5" } })
.bash(
{ code: "echo $(( {{ trigger.fields.threshold }} + 5 ))" },
Expand All @@ -120,7 +120,7 @@ describe("Execute Bash Automations", () => {
})

it("should handle null values gracefully", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.bash(
// @ts-expect-error - testing null input
{ code: null },
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/automations/tests/steps/createRow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("test the create row action", () => {
})

it("should be able to run the action", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { status: "new" } })
.serverLog({ text: "Starting create row flow" }, { stepName: "StartLog" })
.createRow({ row }, { stepName: "CreateRow" })
Expand All @@ -66,7 +66,7 @@ describe("test the create row action", () => {
})

it("should return an error (not throw) when bad info provided", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { status: "error" } })
.serverLog({ text: "Starting error test flow" }, { stepName: "StartLog" })
.createRow(
Expand All @@ -84,7 +84,7 @@ describe("test the create row action", () => {
})

it("should check invalid inputs return an error", async () => {
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { status: "invalid" } })
.serverLog({ text: "Testing invalid input" }, { stepName: "StartLog" })
.createRow({ row: {} }, { stepName: "CreateRow" })
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("test the create row action", () => {
]

attachmentRow.file_attachment = attachmentObject
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { type: "attachment" } })
.serverLog(
{ text: "Processing attachment upload" },
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("test the create row action", () => {
}

attachmentRow.single_file_attachment = attachmentObject
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { type: "single-attachment" } })
.serverLog(
{ text: "Processing single attachment" },
Expand Down Expand Up @@ -244,7 +244,7 @@ describe("test the create row action", () => {
}

attachmentRow.single_file_attachment = attachmentObject
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.appAction({ fields: { type: "invalid-attachment" } })
.serverLog(
{ text: "Testing invalid attachment keys" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("cron automations", () => {
})

it("should initialise the automation timestamp", async () => {
await createAutomationBuilder({ config }).cron({ cron: "* * * * *" }).save()
await createAutomationBuilder(config).cron({ cron: "* * * * *" }).save()

tk.travel(Date.now() + oneMinuteInMs)
await config.publish()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/automations/tests/steps/delay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("test the delay logic", () => {
const time = 100
const before = performance.now()

await createAutomationBuilder({ config }).delay({ time }).run()
await createAutomationBuilder(config).delay({ time }).run()

const now = performance.now()

Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/automations/tests/steps/deleteRow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("test the delete row action", () => {
})

it("should be able to run the delete row action", async () => {
await createAutomationBuilder({ config })
await createAutomationBuilder(config)
.deleteRow({
tableId: table._id!,
id: row._id!,
Expand All @@ -34,15 +34,15 @@ describe("test the delete row action", () => {
})

it("should check invalid inputs return an error", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.deleteRow({ tableId: "", id: "", revision: "" })
.run()

expect(results.steps[0].outputs.success).toEqual(false)
})

it("should return an error when table doesn't exist", async () => {
const results = await createAutomationBuilder({ config })
const results = await createAutomationBuilder(config)
.deleteRow({
tableId: "invalid",
id: "invalid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("test the outgoing webhook action", () => {

it("should be able to run the action", async () => {
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
const result = await createAutomationBuilder({ config })
const result = await createAutomationBuilder(config)
.discord({
url: "http://www.example.com",
username: "joe_bloggs",
Expand Down
Loading

0 comments on commit d62be26

Please sign in to comment.