Rename triggers to start with 'on'
This commit is contained in:
parent
ac2f40e955
commit
9f28eb00d4
|
@ -108,7 +108,7 @@ describe("/automations", () => {
|
|||
|
||||
it("Should ensure you can't have a branch as not a last step", async () => {
|
||||
const automation = createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
activeBranch: {
|
||||
steps: stepBuilder =>
|
||||
|
@ -132,7 +132,7 @@ describe("/automations", () => {
|
|||
|
||||
it("Should check validation on an automation that has a branch step with no children", async () => {
|
||||
const automation = createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({})
|
||||
.serverLog({ text: "Inactive user" })
|
||||
.build()
|
||||
|
@ -148,7 +148,7 @@ describe("/automations", () => {
|
|||
|
||||
it("Should check validation on a branch step with empty conditions", async () => {
|
||||
const automation = createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
activeBranch: {
|
||||
steps: stepBuilder =>
|
||||
|
@ -169,7 +169,7 @@ describe("/automations", () => {
|
|||
|
||||
it("Should check validation on an branch that has a condition that is not valid", async () => {
|
||||
const automation = createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
activeBranch: {
|
||||
steps: stepBuilder =>
|
||||
|
@ -241,7 +241,7 @@ describe("/automations", () => {
|
|||
|
||||
it("should be able to access platformUrl, logoUrl and company in the automation", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog({
|
||||
text: "{{ settings.url }}",
|
||||
})
|
||||
|
|
|
@ -25,7 +25,7 @@ describe("Branching automations", () => {
|
|||
const branch2Id = "44444444-4444-4444-4444-444444444444"
|
||||
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog(
|
||||
{ text: "Starting automation" },
|
||||
{ stepName: "FirstLog", stepId: firstLogId }
|
||||
|
@ -84,7 +84,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("should execute correct branch based on string equality", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
activeBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Active user" }),
|
||||
|
@ -109,7 +109,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("should handle multiple conditions with AND operator", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
activeAdminBranch: {
|
||||
steps: stepBuilder =>
|
||||
|
@ -137,7 +137,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("should handle multiple conditions with OR operator", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.branch({
|
||||
specialBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Special user" }),
|
||||
|
@ -169,7 +169,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("should stop the branch automation when no conditions are met", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.createRow({ row: { name: "Test", tableId: table._id } })
|
||||
.branch({
|
||||
specialBranch: {
|
||||
|
@ -205,7 +205,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("evaluate multiple conditions", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
|
||||
.branch({
|
||||
specialBranch: {
|
||||
|
@ -246,7 +246,7 @@ describe("Branching automations", () => {
|
|||
|
||||
it("evaluate multiple conditions with interpolated text", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
|
||||
.branch({
|
||||
specialBranch: {
|
||||
|
|
|
@ -30,7 +30,7 @@ describe("Automation Scenarios", () => {
|
|||
const table = await config.api.table.save(basicTable())
|
||||
|
||||
const results = await createAutomationBuilder(config)
|
||||
.rowUpdated({ tableId: table._id! })
|
||||
.onRowUpdated({ tableId: table._id! })
|
||||
.createRow({
|
||||
row: {
|
||||
name: "{{trigger.row.name}}",
|
||||
|
@ -63,7 +63,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)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows({
|
||||
tableId: table._id!,
|
||||
})
|
||||
|
@ -82,7 +82,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)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows({
|
||||
tableId: table._id!,
|
||||
})
|
||||
|
@ -124,7 +124,7 @@ describe("Automation Scenarios", () => {
|
|||
})
|
||||
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.createRow(
|
||||
{
|
||||
row: {
|
||||
|
@ -193,7 +193,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)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -243,7 +243,7 @@ describe("Automation Scenarios", () => {
|
|||
|
||||
it("should stop an automation if the condition is not met", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.createRow({
|
||||
row: {
|
||||
name: "Equal Test",
|
||||
|
@ -269,7 +269,7 @@ describe("Automation Scenarios", () => {
|
|||
|
||||
it("should continue the automation if the condition is met", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.createRow({
|
||||
row: {
|
||||
name: "Not Equal Test",
|
||||
|
@ -336,7 +336,7 @@ describe("Automation Scenarios", () => {
|
|||
"should pass the filter when condition is $condition",
|
||||
async ({ condition, value, rowValue, expectPass }) => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.createRow({
|
||||
row: {
|
||||
name: `${condition} Test`,
|
||||
|
@ -371,7 +371,7 @@ describe("Automation Scenarios", () => {
|
|||
const table = await config.api.table.save(basicTable())
|
||||
|
||||
const results = await createAutomationBuilder(config)
|
||||
.rowUpdated({ tableId: table._id! })
|
||||
.onRowUpdated({ tableId: table._id! })
|
||||
.serverLog({ text: "{{ [user].[email] }}" })
|
||||
.run({
|
||||
row: { name: "Test", description: "TEST" },
|
||||
|
@ -383,7 +383,7 @@ describe("Automation Scenarios", () => {
|
|||
|
||||
it("Check user is passed through from app trigger", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog({ text: "{{ [user].[email] }}" })
|
||||
.run({ fields: {} })
|
||||
|
||||
|
@ -455,7 +455,7 @@ if (descriptions.length) {
|
|||
})
|
||||
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.executeQuery({
|
||||
query: {
|
||||
queryId: query._id!,
|
||||
|
|
|
@ -25,7 +25,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)
|
||||
.appAction({ fields: { command: "hello world" } })
|
||||
.onAppAction({ fields: { command: "hello world" } })
|
||||
.bash(
|
||||
{ code: "echo '{{ trigger.fields.command }}'" },
|
||||
{ stepName: "Echo Command" }
|
||||
|
@ -44,7 +44,7 @@ describe("Execute Bash Automations", () => {
|
|||
|
||||
it("should chain multiple bash commands using previous outputs", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { filename: "testfile.txt" } })
|
||||
.onAppAction({ fields: { filename: "testfile.txt" } })
|
||||
.bash(
|
||||
{ code: "echo 'initial content' > {{ trigger.fields.filename }}" },
|
||||
{ stepName: "Create File" }
|
||||
|
@ -94,7 +94,7 @@ describe("Execute Bash Automations", () => {
|
|||
|
||||
it("should handle bash output in conditional logic", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { threshold: "5" } })
|
||||
.onAppAction({ fields: { threshold: "5" } })
|
||||
.bash(
|
||||
{ code: "echo $(( {{ trigger.fields.threshold }} + 5 ))" },
|
||||
{ stepName: "Calculate Value" }
|
||||
|
|
|
@ -41,7 +41,7 @@ describe("test the create row action", () => {
|
|||
|
||||
it("should be able to run the action", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { status: "new" } })
|
||||
.onAppAction({ fields: { status: "new" } })
|
||||
.serverLog({ text: "Starting create row flow" }, { stepName: "StartLog" })
|
||||
.createRow({ row }, { stepName: "CreateRow" })
|
||||
.serverLog(
|
||||
|
@ -67,7 +67,7 @@ describe("test the create row action", () => {
|
|||
|
||||
it("should return an error (not throw) when bad info provided", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { status: "error" } })
|
||||
.onAppAction({ fields: { status: "error" } })
|
||||
.serverLog({ text: "Starting error test flow" }, { stepName: "StartLog" })
|
||||
.createRow(
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ describe("test the create row action", () => {
|
|||
|
||||
it("should check invalid inputs return an error", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { status: "invalid" } })
|
||||
.onAppAction({ fields: { status: "invalid" } })
|
||||
.serverLog({ text: "Testing invalid input" }, { stepName: "StartLog" })
|
||||
.createRow({ row: {} }, { stepName: "CreateRow" })
|
||||
.filter({
|
||||
|
@ -123,7 +123,7 @@ describe("test the create row action", () => {
|
|||
|
||||
attachmentRow.file_attachment = attachmentObject
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { type: "attachment" } })
|
||||
.onAppAction({ fields: { type: "attachment" } })
|
||||
.serverLog(
|
||||
{ text: "Processing attachment upload" },
|
||||
{ stepName: "StartLog" }
|
||||
|
@ -174,7 +174,7 @@ describe("test the create row action", () => {
|
|||
|
||||
attachmentRow.single_file_attachment = attachmentObject
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { type: "single-attachment" } })
|
||||
.onAppAction({ fields: { type: "single-attachment" } })
|
||||
.serverLog(
|
||||
{ text: "Processing single attachment" },
|
||||
{ stepName: "StartLog" }
|
||||
|
@ -245,7 +245,7 @@ describe("test the create row action", () => {
|
|||
|
||||
attachmentRow.single_file_attachment = attachmentObject
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction({ fields: { type: "invalid-attachment" } })
|
||||
.onAppAction({ fields: { type: "invalid-attachment" } })
|
||||
.serverLog(
|
||||
{ text: "Testing invalid attachment keys" },
|
||||
{ stepName: "StartLog" }
|
||||
|
|
|
@ -27,7 +27,7 @@ describe("cron automations", () => {
|
|||
})
|
||||
|
||||
it("should initialise the automation timestamp", async () => {
|
||||
await createAutomationBuilder(config).cron({ cron: "* * * * *" }).save()
|
||||
await createAutomationBuilder(config).onCron({ cron: "* * * * *" }).save()
|
||||
|
||||
tk.travel(Date.now() + oneMinuteInMs)
|
||||
await config.publish()
|
||||
|
|
|
@ -21,7 +21,7 @@ describe("Execute Script Automations", () => {
|
|||
|
||||
it("should execute a basic script and return the result", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.executeScript({ code: "return 2 + 2" })
|
||||
.run({ fields: {} })
|
||||
|
||||
|
@ -30,7 +30,7 @@ describe("Execute Script Automations", () => {
|
|||
|
||||
it("should access bindings from previous steps", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.executeScript(
|
||||
{
|
||||
code: "return trigger.fields.data.map(x => x * 2)",
|
||||
|
@ -44,7 +44,7 @@ describe("Execute Script Automations", () => {
|
|||
|
||||
it("should handle script execution errors gracefully", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.executeScript({ code: "return nonexistentVariable.map(x => x)" })
|
||||
.run({ fields: {} })
|
||||
|
||||
|
@ -56,7 +56,7 @@ describe("Execute Script Automations", () => {
|
|||
|
||||
it("should handle conditional logic in scripts", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.executeScript({
|
||||
code: `
|
||||
if (trigger.fields.value > 5) {
|
||||
|
@ -73,7 +73,7 @@ describe("Execute Script Automations", () => {
|
|||
|
||||
it("should use multiple steps and validate script execution", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.serverLog(
|
||||
{ text: "Starting multi-step automation" },
|
||||
{ stepId: "start-log-step" }
|
||||
|
|
|
@ -73,7 +73,7 @@ describe("Attempt to run a basic loop automation", () => {
|
|||
|
||||
it("should run an automation with a trigger, loop, and create row step", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.rowSaved(
|
||||
.onRowSaved(
|
||||
{ tableId: table._id! },
|
||||
{
|
||||
row: {
|
||||
|
@ -116,7 +116,7 @@ describe("Attempt to run a basic loop automation", () => {
|
|||
|
||||
it("should run an automation where a loop step is between two normal steps to ensure context correctness", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.rowSaved(
|
||||
.onRowSaved(
|
||||
{ tableId: table._id! },
|
||||
{
|
||||
row: {
|
||||
|
@ -213,7 +213,7 @@ describe("Attempt to run a basic loop automation", () => {
|
|||
|
||||
it("should run an automation where a loop is successfully run twice", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.rowSaved(
|
||||
.onRowSaved(
|
||||
{ tableId: table._id! },
|
||||
{
|
||||
row: {
|
||||
|
|
|
@ -58,7 +58,7 @@ describe("test the openai action", () => {
|
|||
// own API key. We don't count this against your quota.
|
||||
const result = await expectAIUsage(0, () =>
|
||||
createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI })
|
||||
.run({ fields: {} })
|
||||
)
|
||||
|
@ -70,7 +70,7 @@ describe("test the openai action", () => {
|
|||
it("should present the correct error message when a prompt is not provided", async () => {
|
||||
const result = await expectAIUsage(0, () =>
|
||||
createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.openai({ prompt: "", model: Model.GPT_4O_MINI })
|
||||
.run({ fields: {} })
|
||||
)
|
||||
|
@ -86,7 +86,7 @@ describe("test the openai action", () => {
|
|||
|
||||
const result = await expectAIUsage(0, () =>
|
||||
createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI })
|
||||
.run({ fields: {} })
|
||||
)
|
||||
|
@ -109,7 +109,7 @@ describe("test the openai action", () => {
|
|||
// key, so we charge users for it.
|
||||
const result = await expectAIUsage(14, () =>
|
||||
createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.openai({ model: Model.GPT_4O_MINI, prompt: "Hello, world" })
|
||||
.run({ fields: {} })
|
||||
)
|
||||
|
|
|
@ -29,7 +29,7 @@ describe("Test a query step automation", () => {
|
|||
|
||||
it("should be able to run the query step", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -54,7 +54,7 @@ describe("Test a query step automation", () => {
|
|||
|
||||
it("Returns all rows when onEmptyFilter has no value and no filters are passed", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -75,7 +75,7 @@ describe("Test a query step automation", () => {
|
|||
|
||||
it("Returns no rows when onEmptyFilter is RETURN_NONE and theres no filters", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -97,7 +97,7 @@ describe("Test a query step automation", () => {
|
|||
|
||||
it("Returns no rows when onEmptyFilters RETURN_NONE and a filter is passed with a null value", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -123,7 +123,7 @@ describe("Test a query step automation", () => {
|
|||
|
||||
it("Returns rows when onEmptyFilter is RETURN_ALL and no filter is passed", async () => {
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: table._id!,
|
||||
|
@ -151,7 +151,7 @@ describe("Test a query step automation", () => {
|
|||
name: NAME,
|
||||
})
|
||||
const result = await createAutomationBuilder(config)
|
||||
.appAction()
|
||||
.onAppAction()
|
||||
.queryRows(
|
||||
{
|
||||
tableId: tableWithSpaces._id!,
|
||||
|
|
|
@ -25,7 +25,7 @@ describe("cron trigger", () => {
|
|||
})
|
||||
|
||||
await createAutomationBuilder(config)
|
||||
.cron({ cron: "* * * * *" })
|
||||
.onCron({ cron: "* * * * *" })
|
||||
.serverLog({
|
||||
text: "Hello, world!",
|
||||
})
|
||||
|
@ -45,7 +45,7 @@ describe("cron trigger", () => {
|
|||
|
||||
it("should fail if the cron expression is invalid", async () => {
|
||||
await createAutomationBuilder(config)
|
||||
.cron({ cron: "* * * * * *" })
|
||||
.onCron({ cron: "* * * * * *" })
|
||||
.serverLog({
|
||||
text: "Hello, world!",
|
||||
})
|
||||
|
|
|
@ -12,7 +12,7 @@ describe("Branching automations", () => {
|
|||
|
||||
async function createWebhookAutomation() {
|
||||
const { automation } = await createAutomationBuilder(config)
|
||||
.webhook({ fields: { parameter: "string" } })
|
||||
.onWebhook({ fields: { parameter: "string" } })
|
||||
.createRow({
|
||||
row: { tableId: table._id!, name: "{{ trigger.parameter }}" },
|
||||
})
|
||||
|
|
|
@ -54,13 +54,13 @@ class TriggerBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
appAction = this.trigger(AutomationTriggerStepId.APP)
|
||||
onAppAction = this.trigger(AutomationTriggerStepId.APP)
|
||||
|
||||
rowSaved = this.trigger(AutomationTriggerStepId.ROW_SAVED)
|
||||
rowUpdated = this.trigger(AutomationTriggerStepId.ROW_UPDATED)
|
||||
rowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
||||
webhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
||||
cron = this.trigger(AutomationTriggerStepId.CRON)
|
||||
onRowSaved = this.trigger(AutomationTriggerStepId.ROW_SAVED)
|
||||
onRowUpdated = this.trigger(AutomationTriggerStepId.ROW_UPDATED)
|
||||
onRowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
||||
onWebhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
||||
onCron = this.trigger(AutomationTriggerStepId.CRON)
|
||||
}
|
||||
|
||||
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
||||
|
|
Loading…
Reference in New Issue