From e5ae064d2c3366401d03c06346e66e6d0ddc6517 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 6 Aug 2024 14:14:42 +0100 Subject: [PATCH 1/3] Fix tables showing up multiple times for Oracle in the datasource info endpoint. --- .../src/api/routes/tests/datasource.spec.ts | 45 +++++++++++++------ packages/server/src/integrations/oracle.ts | 6 ++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index 127ebaa6ae..83ce3f6fdd 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -17,9 +17,15 @@ import { SupportedSqlTypes, JsonFieldSubType, } 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 nock from "nock" +import { Knex } from "knex" +import { uuid } from "@budibase/backend-core/tests/core/utilities/structures" describe("/datasources", () => { const config = setup.getConfig() @@ -167,9 +173,12 @@ describe("/datasources", () => { [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], ])("%s", (_, dsProvider) => { let rawDatasource: Datasource + let client: Knex + beforeEach(async () => { rawDatasource = await dsProvider datasource = await config.api.datasource.create(rawDatasource) + client = await knexClient(rawDatasource) }) describe("get", () => { @@ -434,21 +443,29 @@ describe("/datasources", () => { }) }) - describe("info", () => { - it("should fetch information about a datasource", async () => { - const table = await config.api.table.save( - tableForDatasource(datasource, { - schema: { - name: { - name: "name", - type: FieldType.STRING, - }, - }, - }) - ) + describe.only("info", () => { + it("should fetch information about a datasource with a single table", async () => { + const tableName = uuid() + await client.schema.createTable(tableName, table => { + table.increments("id").primary() + table.string("name") + }) 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)) }) }) }) diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index 545cbf40f6..6139b18844 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -423,7 +423,11 @@ class OracleIntegration extends Sql implements DatasourcePlus { const columnsResponse = await this.internalQuery({ sql: OracleIntegration.COLUMNS_SQL, }) - return (columnsResponse.rows || []).map(row => row.TABLE_NAME) + const tableNames = new Set() + for (const row of columnsResponse.rows || []) { + tableNames.add(row.TABLE_NAME) + } + return Array.from(tableNames) } async testConnection() { From 00970d5db3426a7bb8d214b71dce3c5f51a145fa Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 6 Aug 2024 14:21:07 +0100 Subject: [PATCH 2/3] Fix lint. --- .../server/src/api/routes/tests/datasource.spec.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index 83ce3f6fdd..e79f7f4f48 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -25,7 +25,6 @@ import { import { tableForDatasource } from "../../../tests/utilities/structures" import nock from "nock" import { Knex } from "knex" -import { uuid } from "@budibase/backend-core/tests/core/utilities/structures" describe("/datasources", () => { const config = setup.getConfig() @@ -443,9 +442,9 @@ describe("/datasources", () => { }) }) - describe.only("info", () => { + describe("info", () => { it("should fetch information about a datasource with a single table", async () => { - const tableName = uuid() + const tableName = generator.guid() await client.schema.createTable(tableName, table => { table.increments("id").primary() table.string("name") @@ -456,7 +455,12 @@ describe("/datasources", () => { }) it("should fetch information about a datasource with multiple tables", async () => { - const tableNames = [uuid(), uuid(), uuid(), uuid()] + const tableNames = [ + generator.guid(), + generator.guid(), + generator.guid(), + generator.guid(), + ] for (const tableName of tableNames) { await client.schema.createTable(tableName, table => { table.increments("id").primary() From 3b603bdd35eb79d326eaab376728ec58c554ac7c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 6 Aug 2024 14:29:31 +0100 Subject: [PATCH 3/3] Fix datasource.spec.ts tests. --- .../src/api/routes/tests/datasource.spec.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index e79f7f4f48..237133e639 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -444,6 +444,10 @@ describe("/datasources", () => { describe("info", () => { it("should fetch information about a datasource with a single table", async () => { + const existingTableNames = ( + await config.api.datasource.info(datasource) + ).tableNames + const tableName = generator.guid() await client.schema.createTable(tableName, table => { table.increments("id").primary() @@ -451,10 +455,17 @@ describe("/datasources", () => { }) const info = await config.api.datasource.info(datasource) - expect(info.tableNames).toEqual([tableName]) + expect(info.tableNames).toEqual( + expect.arrayContaining([tableName, ...existingTableNames]) + ) + expect(info.tableNames).toHaveLength(existingTableNames.length + 1) }) it("should fetch information about a datasource with multiple tables", async () => { + const existingTableNames = ( + await config.api.datasource.info(datasource) + ).tableNames + const tableNames = [ generator.guid(), generator.guid(), @@ -469,7 +480,12 @@ describe("/datasources", () => { } const info = await config.api.datasource.info(datasource) - expect(info.tableNames).toEqual(expect.arrayContaining(tableNames)) + expect(info.tableNames).toEqual( + expect.arrayContaining([...tableNames, ...existingTableNames]) + ) + expect(info.tableNames).toHaveLength( + existingTableNames.length + tableNames.length + ) }) }) })