Add extra tests
This commit is contained in:
parent
f0a89764f2
commit
b744ec3c35
|
@ -62,8 +62,8 @@ export const getQueryableFields = async (
|
||||||
allowedFields: string[]
|
allowedFields: string[]
|
||||||
): Promise<string[]> => {
|
): Promise<string[]> => {
|
||||||
const result = []
|
const result = []
|
||||||
for (const field of Object.keys(table.schema).filter(f =>
|
for (const field of Object.keys(table.schema).filter(
|
||||||
allowedFields.includes(f)
|
f => allowedFields.includes(f) && table.schema[f].visible !== false
|
||||||
)) {
|
)) {
|
||||||
const subSchema = table.schema[field]
|
const subSchema = table.schema[field]
|
||||||
if (subSchema.type === FieldType.LINK) {
|
if (subSchema.type === FieldType.LINK) {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import { FieldType, SearchFilters, Table } from "@budibase/types"
|
import {
|
||||||
|
FieldType,
|
||||||
|
RelationshipType,
|
||||||
|
SearchFilters,
|
||||||
|
Table,
|
||||||
|
} from "@budibase/types"
|
||||||
import { getQueryableFields, removeInvalidFilters } from "../queryUtils"
|
import { getQueryableFields, removeInvalidFilters } from "../queryUtils"
|
||||||
import { structures } from "../../../../api/routes/tests/utilities"
|
import { structures } from "../../../../api/routes/tests/utilities"
|
||||||
|
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
||||||
|
|
||||||
describe("query utils", () => {
|
describe("query utils", () => {
|
||||||
describe("removeInvalidFilters", () => {
|
describe("removeInvalidFilters", () => {
|
||||||
|
@ -182,7 +188,13 @@ describe("query utils", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("getQueryableFields", () => {
|
describe("getQueryableFields", () => {
|
||||||
it("allows querying by table schema fields and _id", async () => {
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns table schema fields and _id", async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
...structures.basicTable(),
|
...structures.basicTable(),
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -194,5 +206,56 @@ describe("query utils", () => {
|
||||||
const result = await getQueryableFields(["name", "age"], table)
|
const result = await getQueryableFields(["name", "age"], table)
|
||||||
expect(result).toEqual(["_id", "name", "age"])
|
expect(result).toEqual(["_id", "name", "age"])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("does not return hidden fields", async () => {
|
||||||
|
const table: Table = {
|
||||||
|
...structures.basicTable(),
|
||||||
|
schema: {
|
||||||
|
name: { name: "name", type: FieldType.STRING },
|
||||||
|
age: { name: "age", type: FieldType.NUMBER, visible: false },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await getQueryableFields(["name", "age"], table)
|
||||||
|
expect(result).toEqual(["_id", "name"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("includes relationship fields", async () => {
|
||||||
|
const aux: Table = await config.api.table.save({
|
||||||
|
...structures.basicTable(),
|
||||||
|
name: "auxTable",
|
||||||
|
schema: {
|
||||||
|
title: { name: "title", type: FieldType.STRING },
|
||||||
|
name: { name: "name", type: FieldType.STRING },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const table: Table = {
|
||||||
|
...structures.basicTable(),
|
||||||
|
schema: {
|
||||||
|
name: { name: "name", type: FieldType.STRING },
|
||||||
|
age: { name: "age", type: FieldType.NUMBER, visible: false },
|
||||||
|
aux: {
|
||||||
|
name: "aux",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: aux._id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "table",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await config.doInContext(config.appId, () => {
|
||||||
|
return getQueryableFields(["name", "age", "aux"], table)
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"_id",
|
||||||
|
"name",
|
||||||
|
"aux.title",
|
||||||
|
"aux.name",
|
||||||
|
"auxTable.title",
|
||||||
|
"auxTable.name",
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue