Add more tests

This commit is contained in:
Adria Navarro 2024-12-16 17:52:30 +01:00
parent 7cd412bfdc
commit fc75728a1e
1 changed files with 29 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import {
TableSchema,
Table,
TableSourceType,
FieldType,
} from "@budibase/types"
import { sql } from "@budibase/backend-core"
import { join } from "path"
@ -73,8 +74,20 @@ describe("Captures of real examples", () => {
})
describe("read", () => {
it("should retrieve all fields if non are specified", () => {
const queryJson = getJson("basicFetch.json")
delete queryJson.resource
let query = new Sql(SqlClient.POSTGRES)._query(queryJson)
expect(query).toEqual({
bindings: [primaryLimit],
sql: `select * from "persons" as "a" order by "a"."firstname" asc nulls first, "a"."personid" asc limit $1`,
})
})
it("should retrieve only requested fields", () => {
const queryJson = getJson("basicFetch.json")
let query = new Sql(SqlClient.POSTGRES)._query(queryJson)
expect(query).toEqual({
bindings: [primaryLimit],
@ -82,6 +95,22 @@ describe("Captures of real examples", () => {
})
})
it("should retrieve all fields if a formula column is requested", () => {
const queryJson = getJson("basicFetch.json")
queryJson.table.schema["formula"] = {
name: "formula",
type: FieldType.FORMULA,
formula: "any",
}
queryJson.resource!.fields.push("formula")
let query = new Sql(SqlClient.POSTGRES)._query(queryJson)
expect(query).toEqual({
bindings: [primaryLimit],
sql: `select "a".* from "persons" as "a" order by "a"."firstname" asc nulls first, "a"."personid" asc limit $1`,
})
})
it("should handle basic retrieval with relationships", () => {
const queryJson = getJson("basicFetchWithRelationships.json")
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(