Add basic sqlUtils test
This commit is contained in:
parent
3de079579c
commit
27d1929388
|
@ -166,7 +166,9 @@ export async function buildSqlFieldList(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
table = source
|
table = source
|
||||||
fields = extractRealFields(source)
|
fields = extractRealFields(source).filter(
|
||||||
|
f => table.schema[f].visible !== false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const containsFormula = (isView ? fields : Object.keys(table.schema)).some(
|
const containsFormula = (isView ? fields : Object.keys(table.schema)).some(
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
import {
|
||||||
|
AIOperationEnum,
|
||||||
|
FieldType,
|
||||||
|
RelationshipType,
|
||||||
|
Table,
|
||||||
|
} from "@budibase/types"
|
||||||
|
import { buildSqlFieldList } from "../sqlUtils"
|
||||||
|
import { structures } from "../../../../routes/tests/utilities"
|
||||||
|
import { cloneDeep } from "lodash"
|
||||||
|
|
||||||
|
describe("buildSqlFieldList", () => {
|
||||||
|
const basicTable: Table = {
|
||||||
|
...structures.basicTable(),
|
||||||
|
name: "table",
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "name",
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "description",
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
name: "amount",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
it("extracts fields from table schema", async () => {
|
||||||
|
const result = await buildSqlFieldList(basicTable, {})
|
||||||
|
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("excludes hidden fields", async () => {
|
||||||
|
const table = cloneDeep(basicTable)
|
||||||
|
table.schema.description.visible = false
|
||||||
|
const result = await buildSqlFieldList(table, {})
|
||||||
|
expect(result).toEqual(["table.name", "table.amount"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("excludes non-sql fields fields", async () => {
|
||||||
|
const table = cloneDeep(basicTable)
|
||||||
|
table.schema.formula = {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
}
|
||||||
|
table.schema.ai = {
|
||||||
|
name: "ai",
|
||||||
|
type: FieldType.AI,
|
||||||
|
operation: AIOperationEnum.PROMPT,
|
||||||
|
}
|
||||||
|
table.schema.link = {
|
||||||
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: "otherTableId",
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await buildSqlFieldList(table, {})
|
||||||
|
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("includes hidden fields if there is a formula column", async () => {
|
||||||
|
const table = cloneDeep(basicTable)
|
||||||
|
table.schema.description.visible = false
|
||||||
|
table.schema.formula = {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await buildSqlFieldList(table, {})
|
||||||
|
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue