Add tests
This commit is contained in:
parent
a3a1e29350
commit
e11279311d
|
@ -6,6 +6,7 @@ import {
|
||||||
SortOrder,
|
SortOrder,
|
||||||
SortType,
|
SortType,
|
||||||
Table,
|
Table,
|
||||||
|
UpdateViewRequest,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
@ -34,20 +35,6 @@ function priceTable(): Table {
|
||||||
describe("/v2/views", () => {
|
describe("/v2/views", () => {
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
|
|
||||||
const viewFilters: Omit<CreateViewRequest, "name" | "tableId"> = {
|
|
||||||
query: { allOr: false, equal: { field: "value" } },
|
|
||||||
sort: {
|
|
||||||
field: "fieldToSort",
|
|
||||||
order: SortOrder.DESCENDING,
|
|
||||||
type: SortType.STRING,
|
|
||||||
},
|
|
||||||
schema: {
|
|
||||||
name: {
|
|
||||||
visible: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -70,20 +57,30 @@ describe("/v2/views", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can persist views with queries", async () => {
|
it("can persist views with all fields", async () => {
|
||||||
const newView: CreateViewRequest = {
|
const newView: Required<CreateViewRequest> = {
|
||||||
name: generator.name(),
|
name: generator.name(),
|
||||||
tableId: config.table!._id!,
|
tableId: config.table!._id!,
|
||||||
query: viewFilters.query,
|
primaryDisplay: generator.word(),
|
||||||
sort: viewFilters.sort,
|
query: { allOr: false, equal: { field: "value" } },
|
||||||
|
sort: {
|
||||||
|
field: "fieldToSort",
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
type: SortType.STRING,
|
||||||
|
},
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
delete newView.schema
|
|
||||||
const res = await config.api.viewV2.create(newView)
|
const res = await config.api.viewV2.create(newView)
|
||||||
|
|
||||||
expect(res).toEqual({
|
expect(res).toEqual({
|
||||||
...newView,
|
...newView,
|
||||||
query: viewFilters.query,
|
schema: undefined,
|
||||||
sort: viewFilters.sort,
|
columns: ["name"],
|
||||||
|
schemaUI: newView.schema,
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
version: 2,
|
version: 2,
|
||||||
})
|
})
|
||||||
|
@ -210,6 +207,46 @@ describe("/v2/views", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can update all fields", async () => {
|
||||||
|
const tableId = config.table!._id!
|
||||||
|
|
||||||
|
const updatedData: Required<UpdateViewRequest> = {
|
||||||
|
version: view.version,
|
||||||
|
id: view.id,
|
||||||
|
tableId,
|
||||||
|
name: view.name,
|
||||||
|
primaryDisplay: generator.word(),
|
||||||
|
query: { equal: { [generator.word()]: generator.word() } },
|
||||||
|
sort: {
|
||||||
|
field: generator.word(),
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
type: SortType.STRING,
|
||||||
|
},
|
||||||
|
schema: {
|
||||||
|
Category: {
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
await config.api.viewV2.update(updatedData)
|
||||||
|
|
||||||
|
expect(await config.api.table.get(tableId)).toEqual({
|
||||||
|
...config.table,
|
||||||
|
views: {
|
||||||
|
[view.name]: {
|
||||||
|
...updatedData,
|
||||||
|
schema: {
|
||||||
|
Category: expect.objectContaining({
|
||||||
|
visible: false,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
_rev: expect.any(String),
|
||||||
|
updatedAt: expect.any(String),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("can update an existing view name", async () => {
|
it("can update an existing view name", async () => {
|
||||||
const tableId = config.table!._id!
|
const tableId = config.table!._id!
|
||||||
await config.api.viewV2.update({ ...view, name: "View B" })
|
await config.api.viewV2.update({ ...view, name: "View B" })
|
||||||
|
|
Loading…
Reference in New Issue