Adding negative test case for connections and adding test of table name fetching for postgres.

This commit is contained in:
Michael Drury 2023-05-19 13:36:05 +01:00
parent d85bcbc7e5
commit 38e39cf2f2
3 changed files with 43 additions and 17 deletions

View File

@ -163,9 +163,9 @@ export async function fetchTables(
if (!connector.getTableNames) { if (!connector.getTableNames) {
ctx.throw(400, "Table name fetching not supported by datasource") ctx.throw(400, "Table name fetching not supported by datasource")
} }
const tables = await connector.getTableNames() const tableNames = await connector.getTableNames()
ctx.body = { ctx.body = {
tables, tableNames,
} }
} }

View File

@ -26,7 +26,7 @@ jest.setTimeout(30000)
jest.unmock("pg") jest.unmock("pg")
describe("row api - postgres", () => { describe("postgres integrations", () => {
let makeRequest: MakeRequestResponse, let makeRequest: MakeRequestResponse,
postgresDatasource: Datasource, postgresDatasource: Datasource,
primaryPostgresTable: Table, 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", () => { describe("DELETE /api/:tableId/rows", () => {
const deleteRow = ( const deleteRow = (
tableId: string | undefined, 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)
})
})
}) })

View File

@ -24,7 +24,7 @@ export interface VerifyDatasourceResponse {
} }
export interface FetchTablesDatasourceResponse { export interface FetchTablesDatasourceResponse {
tables: string[] tableNames: string[]
} }
export interface UpdateDatasourceRequest extends Datasource { export interface UpdateDatasourceRequest extends Datasource {