Move view code to test config
This commit is contained in:
parent
8282fbb99b
commit
7f3de5d40e
2 changed files with 36 additions and 32 deletions
|
@ -35,15 +35,6 @@ describe("/v2/views", () => {
|
||||||
table = await config.createTable(priceTable())
|
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) => {
|
const getView = (viewId: string) => {
|
||||||
return request
|
return request
|
||||||
.get(`/api/v2/views/${viewId}`)
|
.get(`/api/v2/views/${viewId}`)
|
||||||
|
@ -51,21 +42,13 @@ describe("/v2/views", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createView(tableId: string): ViewV2 {
|
|
||||||
return {
|
|
||||||
name: generator.guid(),
|
|
||||||
tableId,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
const views: ViewV2[] = []
|
const views: ViewV2[] = []
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
table = await config.createTable(priceTable())
|
await config.createTable(priceTable())
|
||||||
for (let id = 0; id < 10; id++) {
|
for (let id = 0; id < 10; id++) {
|
||||||
const res = await saveView(createView(table._id!))
|
views.push(await config.createViewV2())
|
||||||
views.push(res.body)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -86,9 +69,9 @@ describe("/v2/views", () => {
|
||||||
const newTable = await config.createTable(priceTable())
|
const newTable = await config.createTable(priceTable())
|
||||||
const newViews = []
|
const newViews = []
|
||||||
for (let id = 0; id < 5; id++) {
|
for (let id = 0; id < 5; id++) {
|
||||||
const res = await saveView(createView(newTable._id!))
|
newViews.push(await config.createViewV2({ tableId: newTable._id }))
|
||||||
newViews.push(res.body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/v2/views?tableId=${newTable._id}`)
|
.get(`/api/v2/views?tableId=${newTable._id}`)
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
|
@ -117,7 +100,7 @@ describe("/v2/views", () => {
|
||||||
describe("getView", () => {
|
describe("getView", () => {
|
||||||
let view: ViewV2
|
let view: ViewV2
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
view = (await saveView(createView(table._id!))).body
|
view = await config.createViewV2()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can fetch the expected view", async () => {
|
it("can fetch the expected view", async () => {
|
||||||
|
@ -142,8 +125,16 @@ describe("/v2/views", () => {
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("persist the view when the view is successfully created", async () => {
|
it("persist the view when the view is successfully created", async () => {
|
||||||
const newView = createView(table._id!)
|
const newView: ViewV2 = {
|
||||||
const res = await saveView(newView)
|
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.status).toBe(200)
|
||||||
expect(res.body._id).toBeDefined()
|
expect(res.body._id).toBeDefined()
|
||||||
|
|
||||||
|
@ -159,8 +150,8 @@ describe("/v2/views", () => {
|
||||||
let view: ViewV2
|
let view: ViewV2
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
table = await config.createTable(priceTable())
|
await config.createTable(priceTable())
|
||||||
view = (await saveView(createView(table._id!))).body
|
view = await config.createViewV2()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can delete an existing view", async () => {
|
it("can delete an existing view", async () => {
|
||||||
|
|
|
@ -50,6 +50,7 @@ import {
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
UserRoles,
|
UserRoles,
|
||||||
Automation,
|
Automation,
|
||||||
|
ViewV2,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
|
import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ class TestConfiguration {
|
||||||
user: any
|
user: any
|
||||||
globalUserId: any
|
globalUserId: any
|
||||||
userMetadataId: any
|
userMetadataId: any
|
||||||
table: any
|
table?: Table
|
||||||
linkedTable: any
|
linkedTable: any
|
||||||
automation: any
|
automation: any
|
||||||
datasource: any
|
datasource: any
|
||||||
|
@ -525,7 +526,7 @@ class TestConfiguration {
|
||||||
async updateTable(config?: any): Promise<Table> {
|
async updateTable(config?: any): Promise<Table> {
|
||||||
config = config || basicTable()
|
config = config || basicTable()
|
||||||
this.table = await this._req(config, null, controllers.table.save)
|
this.table = await this._req(config, null, controllers.table.save)
|
||||||
return this.table
|
return this.table!
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTable(config?: Table) {
|
async createTable(config?: Table) {
|
||||||
|
@ -536,7 +537,7 @@ class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTable(tableId?: string) {
|
async getTable(tableId?: string) {
|
||||||
tableId = tableId || this.table._id
|
tableId = tableId || this.table?._id
|
||||||
return this._req(null, { tableId }, controllers.table.find)
|
return this._req(null, { tableId }, controllers.table.find)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,7 +578,7 @@ class TestConfiguration {
|
||||||
throw "Test requires table to be configured."
|
throw "Test requires table to be configured."
|
||||||
}
|
}
|
||||||
const tableId = (config && config.tableId) || this.table._id
|
const tableId = (config && config.tableId) || this.table._id
|
||||||
config = config || basicRow(tableId)
|
config = config || basicRow(tableId!)
|
||||||
return this._req(config, { tableId }, controllers.row.save)
|
return this._req(config, { tableId }, controllers.row.save)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,14 +588,14 @@ class TestConfiguration {
|
||||||
|
|
||||||
async getRows(tableId: string) {
|
async getRows(tableId: string) {
|
||||||
if (!tableId && this.table) {
|
if (!tableId && this.table) {
|
||||||
tableId = this.table._id
|
tableId = this.table._id!
|
||||||
}
|
}
|
||||||
return this._req(null, { tableId }, controllers.row.fetch)
|
return this._req(null, { tableId }, controllers.row.fetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchRows(tableId: string, searchParams: SearchFilters = {}) {
|
async searchRows(tableId: string, searchParams: SearchFilters = {}) {
|
||||||
if (!tableId && this.table) {
|
if (!tableId && this.table) {
|
||||||
tableId = this.table._id
|
tableId = this.table._id!
|
||||||
}
|
}
|
||||||
const body = {
|
const body = {
|
||||||
query: searchParams,
|
query: searchParams,
|
||||||
|
@ -634,6 +635,18 @@ class TestConfiguration {
|
||||||
return this._req(view, null, controllers.view.v1.save)
|
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
|
// AUTOMATION
|
||||||
|
|
||||||
async createAutomation(config?: any) {
|
async createAutomation(config?: any) {
|
||||||
|
|
Loading…
Reference in a new issue