Adding a test case for the removal of automation logs from app sync, as well as adding to the publish/sync filter a check to not carry over automation logs.

This commit is contained in:
mike12345567 2023-06-26 18:52:15 +01:00
parent 643a4f02aa
commit 3eff4d85d0
4 changed files with 76 additions and 1 deletions

View File

@ -57,6 +57,9 @@ class Replication {
appReplicateOpts() {
return {
filter: (doc: any) => {
if (doc._id && doc._id.startsWith(DocumentType.AUTOMATION_LOG)) {
return false
}
return doc._id !== DocumentType.APP_METADATA
},
}

View File

@ -14,7 +14,7 @@ jest.mock("../../../utilities/redis", () => ({
import { clearAllApps, checkBuilderEndpoint } from "./utilities/TestFunctions"
import * as setup from "./utilities"
import { AppStatus } from "../../../db/utils"
import { events, utils } from "@budibase/backend-core"
import { events, utils, context } from "@budibase/backend-core"
import env from "../../../environment"
jest.setTimeout(15000)
@ -324,4 +324,39 @@ describe("/applications", () => {
expect(events.app.unpublished).toBeCalledTimes(1)
})
})
describe("app sync", () => {
it("should not sync automation logs", async () => {
// setup the apps
await config.createApp("testing-auto-logs")
const automation = await config.createAutomation()
await config.publish()
await context.doInAppContext(config.getProdAppId(), () => {
return config.createAutomationLog(automation)
})
// do the sync
const appId = config.getAppId()
await request
.post(`/api/applications/${appId}/sync`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
// does exist in prod
await context.doInAppContext(config.getProdAppId(), async () => {
const logs = await config.getAutomationLogs()
expect(logs.data.length).toBe(1)
})
// delete prod app so we revert to dev log search
await config.unpublish()
// doesn't exist in dev
await context.doInAppContext(config.getAppId(), async () => {
const logs = await config.getAutomationLogs()
expect(logs.data.length).toBe(0)
})
})
})
})

View File

@ -21,6 +21,7 @@ import {
basicScreen,
basicLayout,
basicWebhook,
basicAutomationLog,
} from "./structures"
import {
constants,
@ -48,6 +49,7 @@ import {
Table,
SearchFilters,
UserRoles,
Automation,
} from "@budibase/types"
import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
@ -720,6 +722,24 @@ class TestConfiguration {
return { datasource, query: basedOnQuery }
}
// AUTOMATION LOG
async createAutomationLog(automation: Automation) {
return await context.doInAppContext(this.getProdAppId(), async () => {
return await pro.sdk.automations.logs.storeLog(
automation,
basicAutomationLog(automation._id!)
)
})
}
async getAutomationLogs() {
const now = new Date()
return await pro.sdk.automations.logs.logSearch({
startDate: new Date(now.getTime() - 100000).toISOString(),
})
}
// QUERY
async previewQuery(

View File

@ -9,6 +9,8 @@ import {
import {
Automation,
AutomationActionStepId,
AutomationResults,
AutomationStatus,
AutomationStep,
AutomationStepType,
AutomationTrigger,
@ -241,6 +243,21 @@ export function collectAutomation(tableId?: string): Automation {
return automation as Automation
}
export function basicAutomationLog(automationId: string): AutomationResults {
return {
automationId,
status: AutomationStatus.SUCCESS,
trigger: "trigger",
steps: [
{
stepId: AutomationActionStepId.SERVER_LOG,
inputs: {},
outputs: {},
},
],
}
}
export function basicRow(tableId: string) {
return {
name: "Test Contact",