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,27 +3554,30 @@ if (descriptions.length) {
}).toContainExactly([row]) }).toContainExactly([row])
}) })
it("can filter by the related _id", async () => { isInternal &&
await expectSearch({ describe("search by _id for relations", () => {
query: { it("can filter by the related _id", async () => {
equal: { "rel._id": row.rel[0]._id }, await expectSearch({
}, query: {
}).toContainExactly([row]) equal: { "rel._id": row.rel[0]._id },
},
}).toContainExactly([row])
await expectSearch({ await expectSearch({
query: { query: {
equal: { "rel._id": row.rel[1]._id }, equal: { "rel._id": row.rel[1]._id },
}, },
}).toContainExactly([row]) }).toContainExactly([row])
}) })
it("can filter by the related _id and find nothing", async () => { it("can filter by the related _id and find nothing", async () => {
await expectSearch({ await expectSearch({
query: { query: {
equal: { "rel._id": "rel_none" }, equal: { "rel._id": "rel_none" },
}, },
}).toFindNothing() }).toFindNothing()
}) })
})
}) })
!isInternal && !isInternal &&

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)