Use api for testing

This commit is contained in:
Adria Navarro 2023-09-12 20:17:21 +02:00
parent f0872c1fa3
commit 458de1282e
6 changed files with 36 additions and 28 deletions

View File

@ -6,13 +6,11 @@ import * as setup from "./utilities"
import { context, roles, tenancy } from "@budibase/backend-core"
import { quotas } from "@budibase/pro"
import {
Datasource,
FieldType,
MonthlyQuotaName,
PermissionLevel,
QuotaUsageType,
Row,
SaveRowRequest,
SaveTableRequest,
SortOrder,
SortType,

View File

@ -1,6 +1,6 @@
import { generator } from "@budibase/backend-core/tests"
import { events, context } from "@budibase/backend-core"
import { FieldType, Table } from "@budibase/types"
import { FieldType, Table, ViewCalculation } from "@budibase/types"
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
import * as setup from "./utilities"
const { basicTable } = setup.structures
@ -90,8 +90,10 @@ describe("/tables", () => {
await config.createLegacyView({
name: "TestView",
field: "Price",
calculation: "stats",
tableId: testTable._id,
calculation: ViewCalculation.STATISTICS,
tableId: testTable._id!,
schema: {},
filters: [],
})
const testRow = await request
@ -254,7 +256,7 @@ describe("/tables", () => {
}))
await config.api.viewV2.create({ tableId })
await config.createLegacyView({ tableId, name: generator.guid() })
await config.createLegacyView()
const res = await config.api.table.fetch()
@ -366,7 +368,7 @@ describe("/tables", () => {
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.message).toEqual(`Table ${testTable._id} deleted.`)
const dependentTable = await config.getTable(linkedTable._id)
const dependentTable = await config.api.table.get(linkedTable._id!)
expect(dependentTable.schema.TestTable).not.toBeDefined()
})

View File

@ -6,6 +6,7 @@ import {
SortOrder,
SortType,
Table,
UIFieldMetadata,
UpdateViewRequest,
ViewV2,
} from "@budibase/types"
@ -418,9 +419,12 @@ describe.each([
const res = await config.api.viewV2.create(newView)
const view = await config.api.viewV2.get(res.id)
expect(view!.schema?.Price).toBeUndefined()
const updatedTable = await config.getTable(table._id!)
const viewSchema = updatedTable.views[view!.name!].schema
expect(viewSchema.Price.visible).toEqual(false)
const updatedTable = await config.api.table.get(table._id!)
const viewSchema = updatedTable.views![view!.name!].schema as Record<
string,
UIFieldMetadata
>
expect(viewSchema.Price?.visible).toEqual(false)
})
})
})

View File

@ -397,7 +397,7 @@ describe("postgres integrations", () => {
expect(res.status).toBe(200)
expect(res.body).toEqual(updatedRow)
const persistedRow = await config.getRow(
const persistedRow = await config.api.row.get(
primaryPostgresTable._id!,
row.id
)

View File

@ -557,11 +557,6 @@ class TestConfiguration {
return this.updateTable(config, options)
}
async getTable(tableId?: string) {
tableId = tableId || this.table?._id
return this._req(null, { tableId }, controllers.table.find)
}
async createLinkedTable(
config?: Table,
relationshipType = RelationshipType.ONE_TO_MANY,
@ -609,11 +604,7 @@ class TestConfiguration {
}
const tableId = (config && config.tableId) || this.table._id
config = config || basicRow(tableId!)
return this._req(config, { tableId }, controllers.row.save)
}
async getRow(tableId: string, rowId: string): Promise<Row> {
return this._req(null, { tableId, rowId }, controllers.row.find)
return this.api.row.save(tableId!, config)
}
async getRows(tableId: string) {
@ -648,7 +639,7 @@ class TestConfiguration {
}
const view = config || {
tableId: this.table!._id,
name: "ViewTest",
name: generator.guid(),
}
return this._req(view, null, controllers.view.v1.save)
}
@ -721,12 +712,8 @@ class TestConfiguration {
}
async updateDatasource(datasource: Datasource): Promise<Datasource> {
const response = await this._req(
datasource,
{ datasourceId: datasource._id },
controllers.datasource.update
)
this.datasource = response.datasource
const response = await this.api.datasource.update(datasource)
this.datasource = response
return this.datasource!
}

View File

@ -29,6 +29,23 @@ export class DatasourceAPI extends TestAPI {
return result.body.datasource as Datasource
}
update = async (
config: Datasource,
{ expectStatus } = { expectStatus: 200 }
): Promise<Datasource> => {
const body: CreateDatasourceRequest = {
datasource: config,
tablesFilter: [],
}
const result = await this.request
.put(`/api/datasources/${config._id}`)
.send(body)
.set(this.config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(expectStatus)
return result.body.datasource as Datasource
}
verify = async (
data: VerifyDatasourceRequest,
{ expectStatus } = { expectStatus: 200 }