Fix search tests.

This commit is contained in:
Sam Rose 2025-02-25 09:54:10 +00:00
parent e6fc3dbff4
commit 3c6e2ff2d7
No known key found for this signature in database
2 changed files with 30 additions and 22 deletions

View File

@ -3554,6 +3554,8 @@ if (descriptions.length) {
}).toContainExactly([row]) }).toContainExactly([row])
}) })
isInternal &&
describe("search by _id for relations", () => {
it("can filter by the related _id", async () => { it("can filter by the related _id", async () => {
await expectSearch({ await expectSearch({
query: { query: {
@ -3576,6 +3578,7 @@ if (descriptions.length) {
}).toFindNothing() }).toFindNothing()
}) })
}) })
})
!isInternal && !isInternal &&
describe("search by composite key", () => { describe("search by composite key", () => {

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,
@ -69,8 +70,11 @@ export const getQueryableFields = async (
fromTables: string[], fromTables: string[],
opts?: { noRelationships?: boolean } opts?: { noRelationships?: boolean }
): Promise<string[]> => { ): Promise<string[]> => {
// Querying by _id is always allowed, even if it's never part of the schema const result = []
const result = ["_id"] 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
)) { )) {
@ -114,7 +118,8 @@ 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
const result = ["_id"]
if (fields == null) { if (fields == null) {
fields = Object.keys(table.schema) fields = Object.keys(table.schema)