Update basic test
This commit is contained in:
parent
29bc87a47f
commit
2412056292
|
@ -86,6 +86,29 @@ describe("/v2/views", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
let view: ViewV2
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.createTable(priceTable())
|
||||
view = await config.api.viewV2.create({ name: "View A" })
|
||||
})
|
||||
|
||||
it("can update an existing view name", async () => {
|
||||
const tableId = config.table!._id!
|
||||
await config.api.viewV2.update({ ...view, name: "View B" })
|
||||
|
||||
expect(await config.api.table.get(tableId)).toEqual({
|
||||
...config.table,
|
||||
views: {
|
||||
"View B": { ...view, name: "View B", schema: expect.anything() },
|
||||
},
|
||||
_rev: expect.any(String),
|
||||
updatedAt: expect.any(String),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
let view: ViewV2
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { SortOrder, SortType, ViewV2 } from "@budibase/types"
|
||||
import { CreateViewRequest, SortOrder, SortType, ViewV2 } from "@budibase/types"
|
||||
import TestConfiguration from "../TestConfiguration"
|
||||
import { TestAPI } from "./base"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
@ -9,7 +9,7 @@ export class ViewV2API extends TestAPI {
|
|||
}
|
||||
|
||||
create = async (
|
||||
viewData?: Partial<ViewV2>,
|
||||
viewData?: Partial<CreateViewRequest>,
|
||||
{ expectStatus } = { expectStatus: 201 }
|
||||
): Promise<ViewV2> => {
|
||||
let tableId = viewData?.tableId
|
||||
|
@ -31,6 +31,29 @@ export class ViewV2API extends TestAPI {
|
|||
return result.body.data as ViewV2
|
||||
}
|
||||
|
||||
update = async (
|
||||
viewData?: Partial<ViewV2>,
|
||||
{ expectStatus } = { expectStatus: 200 }
|
||||
): Promise<ViewV2> => {
|
||||
let tableId = viewData?.tableId
|
||||
if (!tableId && !this.config.table) {
|
||||
throw "Test requires table to be configured."
|
||||
}
|
||||
tableId = this.config.table!._id!
|
||||
const view = {
|
||||
tableId,
|
||||
name: generator.guid(),
|
||||
...viewData,
|
||||
}
|
||||
const result = await this.request
|
||||
.put(`/api/v2/views`)
|
||||
.send(view)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(expectStatus)
|
||||
return result.body.data as ViewV2
|
||||
}
|
||||
|
||||
delete = async (viewId: string, { expectStatus } = { expectStatus: 204 }) => {
|
||||
return this.request
|
||||
.delete(`/api/v2/views/${viewId}`)
|
||||
|
|
Loading…
Reference in New Issue