Merge branch 'master' of github.com:budibase/budibase into remove-elasticsearch-mock

This commit is contained in:
Sam Rose 2025-02-25 15:09:27 +00:00
commit 4bd6158f19
No known key found for this signature in database
7 changed files with 85 additions and 117 deletions

View File

@ -3550,6 +3550,31 @@ if (descriptions.length) {
limit: 1, limit: 1,
}).toContainExactly([row]) }).toContainExactly([row])
}) })
isInternal &&
describe("search by _id for relations", () => {
it("can filter by the related _id", async () => {
await expectSearch({
query: {
equal: { "rel._id": row.rel[0]._id },
},
}).toContainExactly([row])
await expectSearch({
query: {
equal: { "rel._id": row.rel[1]._id },
},
}).toContainExactly([row])
})
it("can filter by the related _id and find nothing", async () => {
await expectSearch({
query: {
equal: { "rel._id": "rel_none" },
},
}).toFindNothing()
})
})
}) })
!isInternal && !isInternal &&

View File

@ -1,5 +1,5 @@
import * as automation from "../index" import * as automation from "../index"
import { Table, AutomationStatus } from "@budibase/types" import { Table, AutomationStatus, EmptyFilterOption } from "@budibase/types"
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder" import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
import TestConfiguration from "../../tests/utilities/TestConfiguration" import TestConfiguration from "../../tests/utilities/TestConfiguration"
@ -280,4 +280,23 @@ describe("Branching automations", () => {
expect(results.steps[2].outputs.message).toContain("Special user") expect(results.steps[2].outputs.message).toContain("Special user")
}) })
it("should not fail with empty conditions", async () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.branch({
specialBranch: {
steps: stepBuilder => stepBuilder.serverLog({ text: "Hello!" }),
condition: {
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
},
},
})
.test({ fields: { test_trigger: true } })
expect(results.steps[0].outputs.success).toEqual(false)
expect(results.steps[0].outputs.status).toEqual(
AutomationStatus.NO_CONDITION_MET
)
})
}) })

View File

@ -7,6 +7,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { isInternal } from "../tables/utils"
export const removeInvalidFilters = ( export const removeInvalidFilters = (
filters: SearchFilters, filters: SearchFilters,
@ -70,6 +71,10 @@ export const getQueryableFields = async (
opts?: { noRelationships?: boolean } opts?: { noRelationships?: boolean }
): Promise<string[]> => { ): Promise<string[]> => {
const result = [] const result = []
if (isInternal({ table })) {
result.push("_id")
}
for (const field of Object.keys(table.schema).filter( for (const field of Object.keys(table.schema).filter(
f => allowedFields.includes(f) && table.schema[f].visible !== false f => allowedFields.includes(f) && table.schema[f].visible !== false
)) { )) {
@ -113,14 +118,13 @@ export const getQueryableFields = async (
return result return result
} }
const result = [ // Querying by _id is always allowed, even if it's never part of the schema
"_id", // Querying by _id is always allowed, even if it's never part of the schema const result = ["_id"]
]
if (fields == null) { if (fields == null) {
fields = Object.keys(table.schema) fields = Object.keys(table.schema)
} }
result.push(...(await extractTableFields(table, fields, [table._id!]))) result.push(...(await extractTableFields(table, fields, [table._id!])))
return result return Array.from(new Set(result))
} }

View File

@ -250,6 +250,8 @@ describe("query utils", () => {
expect(result).toEqual([ expect(result).toEqual([
"_id", "_id",
"name", "name",
"aux._id",
"auxTable._id",
"aux.title", "aux.title",
"auxTable.title", "auxTable.title",
"aux.name", "aux.name",
@ -284,7 +286,14 @@ describe("query utils", () => {
const result = await config.doInContext(config.appId, () => { const result = await config.doInContext(config.appId, () => {
return getQueryableFields(table) return getQueryableFields(table)
}) })
expect(result).toEqual(["_id", "name", "aux.name", "auxTable.name"]) expect(result).toEqual([
"_id",
"name",
"aux._id",
"auxTable._id",
"aux.name",
"auxTable.name",
])
}) })
it("excludes all relationship fields if hidden", async () => { it("excludes all relationship fields if hidden", async () => {
@ -387,10 +396,14 @@ describe("query utils", () => {
"_id", "_id",
"name", "name",
// aux1 primitive props // aux1 primitive props
"aux1._id",
"aux1Table._id",
"aux1.name", "aux1.name",
"aux1Table.name", "aux1Table.name",
// aux2 primitive props // aux2 primitive props
"aux2._id",
"aux2Table._id",
"aux2.title", "aux2.title",
"aux2Table.title", "aux2Table.title",
]) ])
@ -405,14 +418,18 @@ describe("query utils", () => {
"name", "name",
// aux2_1 primitive props // aux2_1 primitive props
"aux2_1._id",
"aux2Table._id",
"aux2_1.title", "aux2_1.title",
"aux2Table.title", "aux2Table.title",
// aux2_2 primitive props // aux2_2 primitive props
"aux2_2._id",
"aux2_2.title", "aux2_2.title",
"aux2Table.title",
// table primitive props // table primitive props
"table._id",
"TestTable._id",
"table.name", "table.name",
"TestTable.name", "TestTable.name",
]) ])
@ -427,14 +444,18 @@ describe("query utils", () => {
"title", "title",
// aux1_1 primitive props // aux1_1 primitive props
"aux1_1._id",
"aux1Table._id",
"aux1_1.name", "aux1_1.name",
"aux1Table.name", "aux1Table.name",
// aux1_2 primitive props // aux1_2 primitive props
"aux1_2._id",
"aux1_2.name", "aux1_2.name",
"aux1Table.name",
// table primitive props // table primitive props
"table._id",
"TestTable._id",
"table.name", "table.name",
"TestTable.name", "TestTable.name",
]) ])
@ -481,6 +502,8 @@ describe("query utils", () => {
"name", "name",
// deep 1 aux primitive props // deep 1 aux primitive props
"aux._id",
"auxTable._id",
"aux.title", "aux.title",
"auxTable.title", "auxTable.title",
]) ])
@ -495,6 +518,8 @@ describe("query utils", () => {
"title", "title",
// deep 1 dependency primitive props // deep 1 dependency primitive props
"table._id",
"TestTable._id",
"table.name", "table.name",
"TestTable.name", "TestTable.name",
]) ])

View File

@ -1,108 +0,0 @@
import {
FieldType,
INTERNAL_TABLE_SOURCE_ID,
Table,
TableSourceType,
ViewV2,
} from "@budibase/types"
import { generator } from "@budibase/backend-core/tests"
import sdk from "../../.."
jest.mock("../../views", () => ({
...jest.requireActual("../../views"),
enrichSchema: jest.fn().mockImplementation(v => ({ ...v, mocked: true })),
}))
describe("table sdk", () => {
describe("enrichViewSchemas", () => {
const basicTable: Table = {
_id: generator.guid(),
name: "TestTable",
type: "table",
sourceId: INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL,
schema: {
name: {
type: FieldType.STRING,
name: "name",
visible: true,
width: 80,
order: 2,
constraints: {
type: "string",
},
},
description: {
type: FieldType.STRING,
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: FieldType.NUMBER,
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
},
hiddenField: {
type: FieldType.STRING,
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
},
},
}
it("should fetch the default schema if not overriden", async () => {
const tableId = basicTable._id!
function getTable() {
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
}
return view
}
const view1 = getTable()
const view2 = getTable()
const view3 = getTable()
const res = await sdk.tables.enrichViewSchemas({
...basicTable,
views: {
[view1.name]: view1,
[view2.name]: view2,
[view3.name]: view3,
},
})
expect(sdk.views.enrichSchema).toHaveBeenCalledTimes(3)
expect(res).toEqual({
...basicTable,
views: {
[view1.name]: {
...view1,
mocked: true,
},
[view2.name]: {
...view2,
mocked: true,
},
[view3.name]: {
...view3,
mocked: true,
},
},
})
})
})
})

View File

@ -367,6 +367,8 @@ class Orchestrator {
if (e.errno === "ETIME") { if (e.errno === "ETIME") {
span?.addTags({ timedOut: true }) span?.addTags({ timedOut: true })
console.warn(`Automation execution timed out after ${timeout}ms`) console.warn(`Automation execution timed out after ${timeout}ms`)
} else {
throw e
} }
} }

View File

@ -3,6 +3,7 @@ import { Row, DocumentType, Table, Datasource } from "../documents"
import { SortOrder, SortType } from "../api" import { SortOrder, SortType } from "../api"
import { Knex } from "knex" import { Knex } from "knex"
import { Aggregation } from "./row" import { Aggregation } from "./row"
import _ from "lodash"
export enum BasicOperator { export enum BasicOperator {
EQUAL = "equal", EQUAL = "equal",
@ -83,7 +84,7 @@ type RangeFilter = Record<
type LogicalFilter = { conditions: SearchFilters[] } type LogicalFilter = { conditions: SearchFilters[] }
export function isLogicalFilter(filter: any): filter is LogicalFilter { export function isLogicalFilter(filter: any): filter is LogicalFilter {
return "conditions" in filter return _.isPlainObject(filter) && "conditions" in filter
} }
export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter