diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index 0650305ac1..9ae72ddf50 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -163,9 +163,9 @@ export async function fetchTables( if (!connector.getTableNames) { ctx.throw(400, "Table name fetching not supported by datasource") } - const tables = await connector.getTableNames() + const tableNames = await connector.getTableNames() ctx.body = { - tables, + tableNames, } } diff --git a/packages/server/src/integration-test/postgres.spec.ts b/packages/server/src/integration-test/postgres.spec.ts index c34f2a9bff..b1455f4419 100644 --- a/packages/server/src/integration-test/postgres.spec.ts +++ b/packages/server/src/integration-test/postgres.spec.ts @@ -26,7 +26,7 @@ jest.setTimeout(30000) jest.unmock("pg") -describe("row api - postgres", () => { +describe("postgres integrations", () => { let makeRequest: MakeRequestResponse, postgresDatasource: Datasource, primaryPostgresTable: Table, @@ -443,19 +443,6 @@ describe("row api - postgres", () => { }) }) - describe("POST /api/datasources/verify", () => { - it("should be able to verify the connection", async () => { - const config = pgDatasourceConfig() - const response = await makeRequest( - "post", - "/api/datasources/verify", - config - ) - expect(response.status).toBe(200) - expect(response.body.connected).toBe(true) - }) - }) - describe("DELETE /api/:tableId/rows", () => { const deleteRow = ( tableId: string | undefined, @@ -1041,4 +1028,43 @@ describe("row api - postgres", () => { }) }) }) + + describe("POST /api/datasources/verify", () => { + it("should be able to verify the connection", async () => { + const config = pgDatasourceConfig() + const response = await makeRequest( + "post", + "/api/datasources/verify", + config + ) + expect(response.status).toBe(200) + expect(response.body.connected).toBe(true) + }) + + it("should state an invalid datasource cannot connect", async () => { + const config = pgDatasourceConfig() + config.datasource.config.password = "wrongpassword" + const response = await makeRequest( + "post", + "/api/datasources/verify", + config + ) + expect(response.status).toBe(200) + expect(response.body.connected).toBe(false) + expect(response.body.error).toBeDefined() + }) + }) + + describe("GET /api/datasources/:datasourceId/tables", () => { + it("should fetch tables within postgres datasource", async () => { + const primaryName = primaryPostgresTable.name + const response = await makeRequest( + "get", + `/api/datasources/${postgresDatasource._id}/tables` + ) + expect(response.status).toBe(200) + expect(response.body.tableNames).toBeDefined() + expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-10) + }) + }) }) diff --git a/packages/types/src/api/web/app/datasource.ts b/packages/types/src/api/web/app/datasource.ts index 12c9753aa1..0d0406fe55 100644 --- a/packages/types/src/api/web/app/datasource.ts +++ b/packages/types/src/api/web/app/datasource.ts @@ -24,7 +24,7 @@ export interface VerifyDatasourceResponse { } export interface FetchTablesDatasourceResponse { - tables: string[] + tableNames: string[] } export interface UpdateDatasourceRequest extends Datasource {