Merge remote-tracking branch 'origin/v3-ui' into feature/automation-branching-ux

This commit is contained in:
Dean 2024-10-28 12:00:33 +00:00
commit 11d24db255
5 changed files with 96 additions and 18 deletions

View File

@ -9,9 +9,15 @@ import {
TRIGGER_DEFINITIONS, TRIGGER_DEFINITIONS,
BUILTIN_ACTION_DEFINITIONS, BUILTIN_ACTION_DEFINITIONS,
} from "../../../automations" } from "../../../automations"
import { events } from "@budibase/backend-core" import { configs, context, events } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { Automation, FieldType, Table } from "@budibase/types" import {
Automation,
ConfigType,
FieldType,
SettingsConfig,
Table,
} from "@budibase/types"
import { mocks } from "@budibase/backend-core/tests" import { mocks } from "@budibase/backend-core/tests"
import { FilterConditions } from "../../../automations/steps/filter" import { FilterConditions } from "../../../automations/steps/filter"
import { removeDeprecated } from "../../../automations/utils" import { removeDeprecated } from "../../../automations/utils"
@ -39,8 +45,7 @@ describe("/automations", () => {
}) })
beforeEach(() => { beforeEach(() => {
// @ts-ignore jest.clearAllMocks()
events.automation.deleted.mockClear()
}) })
describe("get definitions", () => { describe("get definitions", () => {
@ -244,6 +249,59 @@ describe("/automations", () => {
}) })
}) })
describe("run", () => {
let oldConfig: SettingsConfig
beforeAll(async () => {
await context.doInTenant(config.getTenantId(), async () => {
oldConfig = await configs.getSettingsConfigDoc()
const settings: SettingsConfig = {
_id: oldConfig._id,
_rev: oldConfig._rev,
type: ConfigType.SETTINGS,
config: {
platformUrl: "https://example.com",
logoUrl: "https://example.com/logo.png",
company: "Test Company",
},
}
const saved = await configs.save(settings)
oldConfig._rev = saved.rev
})
})
afterAll(async () => {
await context.doInTenant(config.getTenantId(), async () => {
await configs.save(oldConfig)
})
})
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,
})
.appAction({ fields: {} })
.serverLog({
text: "{{ settings.url }}",
})
.serverLog({
text: "{{ settings.logo }}",
})
.serverLog({
text: "{{ settings.company }}",
})
.run()
expect(result.steps[0].outputs.message).toEndWith("https://example.com")
expect(result.steps[1].outputs.message).toEndWith(
"https://example.com/logo.png"
)
expect(result.steps[2].outputs.message).toEndWith("Test Company")
})
})
describe("test", () => { describe("test", () => {
it("tests the automation successfully", async () => { it("tests the automation successfully", async () => {
let table = await config.createTable() let table = await config.createTable()

View File

@ -226,7 +226,9 @@ class AutomationBuilder extends BaseStepBuilder {
private triggerOutputs: any private triggerOutputs: any
private triggerSet: boolean = false private triggerSet: boolean = false
constructor(options: { name?: string; appId?: string } = {}) { constructor(
options: { name?: string; appId?: string; config?: TestConfiguration } = {}
) {
super() super()
this.automationConfig = { this.automationConfig = {
name: options.name || `Test Automation ${uuidv4()}`, name: options.name || `Test Automation ${uuidv4()}`,
@ -238,7 +240,7 @@ class AutomationBuilder extends BaseStepBuilder {
type: "automation", type: "automation",
appId: options.appId ?? setup.getConfig().getAppId(), appId: options.appId ?? setup.getConfig().getAppId(),
} }
this.config = setup.getConfig() this.config = options.config || setup.getConfig()
} }
// TRIGGERS // TRIGGERS
@ -348,6 +350,7 @@ class AutomationBuilder extends BaseStepBuilder {
export function createAutomationBuilder(options?: { export function createAutomationBuilder(options?: {
name?: string name?: string
appId?: string appId?: string
config?: TestConfiguration
}) { }) {
return new AutomationBuilder(options) return new AutomationBuilder(options)
} }

View File

@ -20,4 +20,9 @@ export interface AutomationContext extends AutomationResults {
env?: Record<string, string> env?: Record<string, string>
user?: UserBindings user?: UserBindings
trigger: any trigger: any
settings?: {
url?: string
logo?: string
company?: string
}
} }

View File

@ -30,7 +30,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { AutomationContext, TriggerOutput } from "../definitions/automations" import { AutomationContext, TriggerOutput } from "../definitions/automations"
import { WorkerCallback } from "./definitions" import { WorkerCallback } from "./definitions"
import { context, logging } from "@budibase/backend-core" import { context, logging, configs } from "@budibase/backend-core"
import { import {
findHBSBlocks, findHBSBlocks,
processObject, processObject,
@ -267,6 +267,18 @@ class Orchestrator {
this.context.env = await sdkUtils.getEnvironmentVariables() this.context.env = await sdkUtils.getEnvironmentVariables()
this.context.user = this.currentUser this.context.user = this.currentUser
try {
const { config } = await configs.getSettingsConfigDoc()
this.context.settings = {
url: config.platformUrl,
logo: config.logoUrl,
company: config.company,
}
} catch (e) {
// if settings doc doesn't exist, make the settings blank
this.context.settings = {}
}
let metadata let metadata
// check if this is a recurring automation, // check if this is a recurring automation,

View File

@ -2051,7 +2051,7 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.32.11": "@budibase/backend-core@2.33.2":
version "0.0.0" version "0.0.0"
dependencies: dependencies:
"@budibase/nano" "10.1.5" "@budibase/nano" "10.1.5"
@ -2132,15 +2132,15 @@
through2 "^2.0.0" through2 "^2.0.0"
"@budibase/pro@npm:@budibase/pro@latest": "@budibase/pro@npm:@budibase/pro@latest":
version "2.32.11" version "2.33.2"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.32.11.tgz#c94d534f829ca0ef252677757e157a7e58b87b4d" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.33.2.tgz#5c2012f7b2bf0fd871cda1ad37ad7a0442c84658"
integrity sha512-mOkqJpqHKWsfTWZwWcvBCYFUIluSUHltQNinc1ZRsg9rC3OKoHSDop6gzm744++H/GzGRN8V86kLhCgtNIlkpA== integrity sha512-lBB6Wfp6OIOHRlGq82WS9KxvEXRs/P2QlwJT0Aj9PhmkQFsnXm2r8d18f0xTGvcflD+iR7XGP/k56JlCanmhQg==
dependencies: dependencies:
"@anthropic-ai/sdk" "^0.27.3" "@anthropic-ai/sdk" "^0.27.3"
"@budibase/backend-core" "2.32.11" "@budibase/backend-core" "2.33.2"
"@budibase/shared-core" "2.32.11" "@budibase/shared-core" "2.33.2"
"@budibase/string-templates" "2.32.11" "@budibase/string-templates" "2.33.2"
"@budibase/types" "2.32.11" "@budibase/types" "2.33.2"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
bull "4.10.1" bull "4.10.1"
dd-trace "5.2.0" dd-trace "5.2.0"
@ -2153,13 +2153,13 @@
scim-patch "^0.8.1" scim-patch "^0.8.1"
scim2-parse-filter "^0.2.8" scim2-parse-filter "^0.2.8"
"@budibase/shared-core@2.32.11": "@budibase/shared-core@2.33.2":
version "0.0.0" version "0.0.0"
dependencies: dependencies:
"@budibase/types" "0.0.0" "@budibase/types" "0.0.0"
cron-validate "1.4.5" cron-validate "1.4.5"
"@budibase/string-templates@2.32.11": "@budibase/string-templates@2.33.2":
version "0.0.0" version "0.0.0"
dependencies: dependencies:
"@budibase/handlebars-helpers" "^0.13.2" "@budibase/handlebars-helpers" "^0.13.2"
@ -2167,7 +2167,7 @@
handlebars "^4.7.8" handlebars "^4.7.8"
lodash.clonedeep "^4.5.0" lodash.clonedeep "^4.5.0"
"@budibase/types@2.32.11": "@budibase/types@2.33.2":
version "0.0.0" version "0.0.0"
dependencies: dependencies:
scim-patch "^0.8.1" scim-patch "^0.8.1"