Test sdk calls

This commit is contained in:
Adria Navarro 2023-07-24 14:57:16 +02:00
parent 810bb41547
commit 559cb3d9e0
1 changed files with 25 additions and 163 deletions

View File

@ -1,8 +1,10 @@
import { generator } from "@budibase/backend-core/tests"
import { events, context } from "@budibase/backend-core"
import { FieldType, Table } from "@budibase/types"
import { checkBuilderEndpoint } from "./utilities/TestFunctions" import { checkBuilderEndpoint } from "./utilities/TestFunctions"
import * as setup from "./utilities" import * as setup from "./utilities"
const { basicTable } = setup.structures const { basicTable } = setup.structures
import { events, context } from "@budibase/backend-core" import sdk from "../../../sdk"
import { FieldType, Table } from "@budibase/types"
describe("/tables", () => { describe("/tables", () => {
let request = setup.getRequest() let request = setup.getRequest()
@ -275,75 +277,23 @@ describe("/tables", () => {
) )
}) })
it("should fetch the default schema if not overriden", async () => { it("should enrich the view schemas for viewsV2", async () => {
const tableId = config.table!._id! const tableId = config.table!._id!
const view = await config.api.viewV2.create({ tableId }) jest.spyOn(sdk.tables, "enrichViewSchemas").mockImplementation(t => ({
...t,
const res = await config.api.table.fetch()
expect(res).toEqual(
expect.arrayContaining([
expect.objectContaining({
_id: tableId,
views: { views: {
[view.name]: { view1: {
...view, version: 2,
schema: { name: "view1",
name: { schema: {},
type: "string", id: "new_view_id",
name: "name",
visible: true,
width: 80,
constraints: {
type: "string",
},
},
description: {
type: "string",
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
visible: true,
constraints: {
type: "number",
},
},
hiddenField: {
type: "string",
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
},
},
},
},
}),
])
)
})
it("should fetch the default schema if not overriden", async () => {
const tableId = testTable._id!
const views = [
await config.api.viewV2.create({ tableId }),
await config.api.viewV2.create({
tableId, tableId,
columns: {
name: { visible: true },
id: { visible: true },
description: { visible: false },
}, },
}), },
] }))
await config.api.viewV2.create({ tableId })
await config.createView({ tableId, name: generator.guid() })
const res = await config.api.table.fetch() const res = await config.api.table.fetch()
@ -352,100 +302,12 @@ describe("/tables", () => {
expect.objectContaining({ expect.objectContaining({
_id: tableId, _id: tableId,
views: { views: {
[views[0].name]: { view1: {
...views[0], version: 2,
schema: { name: "view1",
name: { schema: {},
type: "string", id: "new_view_id",
name: "name",
visible: true,
width: 80,
constraints: {
type: "string",
},
},
description: {
type: "string",
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
visible: true,
constraints: {
type: "number",
},
},
hiddenField: {
type: "string",
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
},
},
},
[views[1].name]: {
...views[1],
schema: {
name: {
type: "string",
name: "name",
visible: true,
width: 80,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
visible: true,
constraints: {
type: "number",
},
},
},
},
},
}),
])
)
})
it("should fetch the default schema if not overriden", async () => {
const tableId = config.table!._id!
const view = await config.api.viewV2.create({
tableId, tableId,
columns: { unnexisting: { visible: true }, name: { visible: true } },
})
const res = await config.api.table.fetch()
expect(res).toEqual(
expect.arrayContaining([
expect.objectContaining({
_id: tableId,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
visible: true,
width: 80,
constraints: {
type: "string",
},
},
},
}, },
}, },
}), }),