1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Move view code to test config

This commit is contained in:
Adria Navarro 2023-07-18 10:14:13 +02:00
parent 8282fbb99b
commit 7f3de5d40e
2 changed files with 36 additions and 32 deletions

View file

@ -35,15 +35,6 @@ describe("/v2/views", () => {
table = await config.createTable(priceTable())
})
const saveView = async (view: ViewV2) => {
return request
.post(`/api/v2/views`)
.send(view)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
}
const getView = (viewId: string) => {
return request
.get(`/api/v2/views/${viewId}`)
@ -51,21 +42,13 @@ describe("/v2/views", () => {
.expect("Content-Type", /json/)
}
function createView(tableId: string): ViewV2 {
return {
name: generator.guid(),
tableId,
}
}
describe("fetch", () => {
const views: ViewV2[] = []
beforeAll(async () => {
table = await config.createTable(priceTable())
await config.createTable(priceTable())
for (let id = 0; id < 10; id++) {
const res = await saveView(createView(table._id!))
views.push(res.body)
views.push(await config.createViewV2())
}
})
@ -86,9 +69,9 @@ describe("/v2/views", () => {
const newTable = await config.createTable(priceTable())
const newViews = []
for (let id = 0; id < 5; id++) {
const res = await saveView(createView(newTable._id!))
newViews.push(res.body)
newViews.push(await config.createViewV2({ tableId: newTable._id }))
}
const res = await request
.get(`/api/v2/views?tableId=${newTable._id}`)
.set(config.defaultHeaders())
@ -117,7 +100,7 @@ describe("/v2/views", () => {
describe("getView", () => {
let view: ViewV2
beforeAll(async () => {
view = (await saveView(createView(table._id!))).body
view = await config.createViewV2()
})
it("can fetch the expected view", async () => {
@ -142,8 +125,16 @@ describe("/v2/views", () => {
describe("create", () => {
it("persist the view when the view is successfully created", async () => {
const newView = createView(table._id!)
const res = await saveView(newView)
const newView: ViewV2 = {
name: generator.name(),
tableId: config.table!._id!,
}
const res = await request
.post(`/api/v2/views`)
.send(newView)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(res.status).toBe(200)
expect(res.body._id).toBeDefined()
@ -159,8 +150,8 @@ describe("/v2/views", () => {
let view: ViewV2
beforeAll(async () => {
table = await config.createTable(priceTable())
view = (await saveView(createView(table._id!))).body
await config.createTable(priceTable())
view = await config.createViewV2()
})
it("can delete an existing view", async () => {

View file

@ -50,6 +50,7 @@ import {
SearchFilters,
UserRoles,
Automation,
ViewV2,
} from "@budibase/types"
import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
@ -73,7 +74,7 @@ class TestConfiguration {
user: any
globalUserId: any
userMetadataId: any
table: any
table?: Table
linkedTable: any
automation: any
datasource: any
@ -525,7 +526,7 @@ class TestConfiguration {
async updateTable(config?: any): Promise<Table> {
config = config || basicTable()
this.table = await this._req(config, null, controllers.table.save)
return this.table
return this.table!
}
async createTable(config?: Table) {
@ -536,7 +537,7 @@ class TestConfiguration {
}
async getTable(tableId?: string) {
tableId = tableId || this.table._id
tableId = tableId || this.table?._id
return this._req(null, { tableId }, controllers.table.find)
}
@ -577,7 +578,7 @@ class TestConfiguration {
throw "Test requires table to be configured."
}
const tableId = (config && config.tableId) || this.table._id
config = config || basicRow(tableId)
config = config || basicRow(tableId!)
return this._req(config, { tableId }, controllers.row.save)
}
@ -587,14 +588,14 @@ class TestConfiguration {
async getRows(tableId: string) {
if (!tableId && this.table) {
tableId = this.table._id
tableId = this.table._id!
}
return this._req(null, { tableId }, controllers.row.fetch)
}
async searchRows(tableId: string, searchParams: SearchFilters = {}) {
if (!tableId && this.table) {
tableId = this.table._id
tableId = this.table._id!
}
const body = {
query: searchParams,
@ -634,6 +635,18 @@ class TestConfiguration {
return this._req(view, null, controllers.view.v1.save)
}
async createViewV2(config?: Partial<ViewV2>) {
if (!this.table) {
throw "Test requires table to be configured."
}
const view = {
tableId: this.table._id,
name: generator.guid(),
...config,
}
return this._req(view, null, controllers.view.v2.save)
}
// AUTOMATION
async createAutomation(config?: any) {