Revert "Remove old automation test flag mechanism from Redis."
This reverts commit 99cf4feb07
.
This commit is contained in:
parent
f96c4f352d
commit
5afab49e18
|
@ -2,6 +2,7 @@ import * as triggers from "../../automations/triggers"
|
||||||
import { sdk as coreSdk } from "@budibase/shared-core"
|
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||||
import { DocumentType } from "../../db/utils"
|
import { DocumentType } from "../../db/utils"
|
||||||
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
||||||
|
import { withTestFlag } from "../../utilities/redis"
|
||||||
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
|
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
|
||||||
import { automations, features } from "@budibase/pro"
|
import { automations, features } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
|
@ -245,15 +246,17 @@ export async function test(
|
||||||
const { request, appId } = ctx
|
const { request, appId } = ctx
|
||||||
const { body } = request
|
const { body } = request
|
||||||
|
|
||||||
const occurredAt = new Date().getTime()
|
ctx.body = await withTestFlag(automation._id!, async () => {
|
||||||
await updateTestHistory(appId, automation, { ...body, occurredAt })
|
const occurredAt = new Date().getTime()
|
||||||
|
await updateTestHistory(appId, automation, { ...body, occurredAt })
|
||||||
|
|
||||||
const user = sdk.users.getUserContextBindings(ctx.user)
|
const user = sdk.users.getUserContextBindings(ctx.user)
|
||||||
ctx.body = await triggers.externalTrigger(
|
return await triggers.externalTrigger(
|
||||||
automation,
|
automation,
|
||||||
{ ...prepareTestInput(body), appId, user },
|
{ ...prepareTestInput(body), appId, user },
|
||||||
{ getResponses: true }
|
{ getResponses: true }
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
await events.automation.tested(automation)
|
await events.automation.tested(automation)
|
||||||
}
|
}
|
||||||
|
@ -268,7 +271,7 @@ export async function testStep(
|
||||||
ctx.throw(404, `Automation ${ctx.params.id} not found`)
|
ctx.throw(404, `Automation ${ctx.params.id} not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const step = automation.definition.steps.find(s => s.id === stepId)
|
const step = automation.definition.steps.find(s => s.stepId === stepId)
|
||||||
if (!step) {
|
if (!step) {
|
||||||
ctx.throw(404, `Step ${stepId} not found on automation ${id}`)
|
ctx.throw(404, `Step ${stepId} not found on automation ${id}`)
|
||||||
}
|
}
|
||||||
|
@ -287,10 +290,16 @@ export async function testStep(
|
||||||
ctx.throw(400, `Step ${stepId} is not a valid step`)
|
ctx.throw(400, `Step ${stepId} is not a valid step`)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = await fn({
|
const output = await withTestFlag(
|
||||||
inputs: body.inputs,
|
automation._id!,
|
||||||
context: await enrichBaseContext(body.context),
|
async () =>
|
||||||
appId: ctx.appId,
|
await fn({
|
||||||
emitter: new NoopEmitter(),
|
inputs: body.inputs,
|
||||||
})
|
context: await enrichBaseContext(body.context),
|
||||||
|
appId: ctx.appId,
|
||||||
|
emitter: new NoopEmitter(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx.body = output
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,11 @@ async function queueRelevantRowAutomations(
|
||||||
// don't queue events which are for dev apps, only way to test automations is
|
// don't queue events which are for dev apps, only way to test automations is
|
||||||
// running tests on them, in production the test flag will never
|
// running tests on them, in production the test flag will never
|
||||||
// be checked due to lazy evaluation (first always false)
|
// be checked due to lazy evaluation (first always false)
|
||||||
if (!env.ALLOW_DEV_AUTOMATIONS && isDevAppID(event.appId)) {
|
if (
|
||||||
|
!env.ALLOW_DEV_AUTOMATIONS &&
|
||||||
|
isDevAppID(event.appId) &&
|
||||||
|
!(await checkTestFlag(automation._id!))
|
||||||
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +170,10 @@ export async function externalTrigger(
|
||||||
throw new Error("Automation is disabled")
|
throw new Error("Automation is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdk.automations.isAppAction(automation) && !isDevAppID(params.appId)) {
|
if (
|
||||||
|
sdk.automations.isAppAction(automation) &&
|
||||||
|
!(await checkTestFlag(automation._id!))
|
||||||
|
) {
|
||||||
// values are likely to be submitted as strings, so we shall convert to correct type
|
// values are likely to be submitted as strings, so we shall convert to correct type
|
||||||
const coercedFields: any = {}
|
const coercedFields: any = {}
|
||||||
const fields = automation.definition.trigger.inputs.fields
|
const fields = automation.definition.trigger.inputs.fields
|
||||||
|
|
Loading…
Reference in New Issue