Fix tables showing up multiple times for Oracle in the datasource info endpoint.

This commit is contained in:
Sam Rose 2024-08-06 14:14:42 +01:00
parent 589909c3a2
commit e5ae064d2c
No known key found for this signature in database
2 changed files with 36 additions and 15 deletions

View File

@ -17,9 +17,15 @@ import {
SupportedSqlTypes, SupportedSqlTypes,
JsonFieldSubType, JsonFieldSubType,
} from "@budibase/types" } from "@budibase/types"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" import {
DatabaseName,
getDatasource,
knexClient,
} from "../../../integrations/tests/utils"
import { tableForDatasource } from "../../../tests/utilities/structures" import { tableForDatasource } from "../../../tests/utilities/structures"
import nock from "nock" import nock from "nock"
import { Knex } from "knex"
import { uuid } from "@budibase/backend-core/tests/core/utilities/structures"
describe("/datasources", () => { describe("/datasources", () => {
const config = setup.getConfig() const config = setup.getConfig()
@ -167,9 +173,12 @@ describe("/datasources", () => {
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("%s", (_, dsProvider) => { ])("%s", (_, dsProvider) => {
let rawDatasource: Datasource let rawDatasource: Datasource
let client: Knex
beforeEach(async () => { beforeEach(async () => {
rawDatasource = await dsProvider rawDatasource = await dsProvider
datasource = await config.api.datasource.create(rawDatasource) datasource = await config.api.datasource.create(rawDatasource)
client = await knexClient(rawDatasource)
}) })
describe("get", () => { describe("get", () => {
@ -434,21 +443,29 @@ describe("/datasources", () => {
}) })
}) })
describe("info", () => { describe.only("info", () => {
it("should fetch information about a datasource", async () => { it("should fetch information about a datasource with a single table", async () => {
const table = await config.api.table.save( const tableName = uuid()
tableForDatasource(datasource, { await client.schema.createTable(tableName, table => {
schema: { table.increments("id").primary()
name: { table.string("name")
name: "name",
type: FieldType.STRING,
},
},
}) })
)
const info = await config.api.datasource.info(datasource) const info = await config.api.datasource.info(datasource)
expect(info.tableNames).toContain(table.name) expect(info.tableNames).toEqual([tableName])
})
it("should fetch information about a datasource with multiple tables", async () => {
const tableNames = [uuid(), uuid(), uuid(), uuid()]
for (const tableName of tableNames) {
await client.schema.createTable(tableName, table => {
table.increments("id").primary()
table.string("name")
})
}
const info = await config.api.datasource.info(datasource)
expect(info.tableNames).toEqual(expect.arrayContaining(tableNames))
}) })
}) })
}) })

View File

@ -423,7 +423,11 @@ class OracleIntegration extends Sql implements DatasourcePlus {
const columnsResponse = await this.internalQuery<OracleColumnsResponse>({ const columnsResponse = await this.internalQuery<OracleColumnsResponse>({
sql: OracleIntegration.COLUMNS_SQL, sql: OracleIntegration.COLUMNS_SQL,
}) })
return (columnsResponse.rows || []).map(row => row.TABLE_NAME) const tableNames = new Set<string>()
for (const row of columnsResponse.rows || []) {
tableNames.add(row.TABLE_NAME)
}
return Array.from(tableNames)
} }
async testConnection() { async testConnection() {