Adding test for postgres verify.

This commit is contained in:
Michael Drury 2023-05-19 12:19:55 +01:00
parent 2223027d28
commit d85bcbc7e5
3 changed files with 22 additions and 5 deletions

View File

@ -154,7 +154,7 @@ export async function verify(
} }
} }
export async function tables( export async function fetchTables(
ctx: UserCtx<void, FetchTablesDatasourceResponse> ctx: UserCtx<void, FetchTablesDatasourceResponse>
) { ) {
const datasourceId = ctx.params.datasourceId const datasourceId = ctx.params.datasourceId

View File

@ -23,7 +23,7 @@ router
.get( .get(
"/api/datasources/:datasourceId/tables", "/api/datasources/:datasourceId/tables",
authorized(permissions.BUILDER), authorized(permissions.BUILDER),
datasourceController.tables datasourceController.fetchTables
) )
.get( .get(
"/api/datasources/:datasourceId", "/api/datasources/:datasourceId",

View File

@ -52,8 +52,8 @@ describe("row api - postgres", () => {
makeRequest = generateMakeRequest(apiKey, true) makeRequest = generateMakeRequest(apiKey, true)
}) })
beforeEach(async () => { function pgDatasourceConfig() {
postgresDatasource = await config.createDatasource({ return {
datasource: { datasource: {
type: "datasource", type: "datasource",
source: SourceName.POSTGRES, source: SourceName.POSTGRES,
@ -70,7 +70,11 @@ describe("row api - postgres", () => {
ca: false, ca: false,
}, },
}, },
}) }
}
beforeEach(async () => {
postgresDatasource = await config.createDatasource(pgDatasourceConfig())
async function createAuxTable(prefix: string) { async function createAuxTable(prefix: string) {
return await config.createTable({ return await config.createTable({
@ -439,6 +443,19 @@ 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,