1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

Move some mysql.spec.ts and postgres.spec.ts tests into datasource.spec.ts.

This commit is contained in:
Sam Rose 2024-06-07 16:56:07 +01:00
parent d682320371
commit 85c372c4d6
No known key found for this signature in database
4 changed files with 67 additions and 97 deletions

View file

@ -156,8 +156,10 @@ describe("/datasources", () => {
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
])("%s", (_, dsProvider) => {
let rawDatasource: Datasource
beforeEach(async () => {
datasource = await config.api.datasource.create(await dsProvider)
rawDatasource = await dsProvider
datasource = await config.api.datasource.create(rawDatasource)
})
describe("get", () => {
@ -372,5 +374,58 @@ describe("/datasources", () => {
expect(updated).toEqual(expected)
})
})
describe("verify", () => {
it("should be able to verify the connection", async () => {
await config.api.datasource.verify(
{
datasource: rawDatasource,
},
{
body: {
connected: true,
},
}
)
})
it("should state an invalid datasource cannot connect", async () => {
await config.api.datasource.verify(
{
datasource: {
...rawDatasource,
config: {
...rawDatasource.config,
password: "wrongpassword",
},
},
},
{
body: {
connected: false,
error: /.*/, // error message differs between databases
},
}
)
})
})
describe("info", () => {
it("should fetch information about postgres datasource", async () => {
const table = await config.api.table.save(
tableForDatasource(datasource, {
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
},
})
)
const info = await config.api.datasource.info(datasource)
expect(info.tableNames).toContain(table.name)
})
})
})
})

View file

@ -109,54 +109,6 @@ describe("mysql integrations", () => {
})
})
describe("POST /api/datasources/verify", () => {
it("should be able to verify the connection", async () => {
await config.api.datasource.verify(
{
datasource: rawDatasource,
},
{
body: {
connected: true,
},
}
)
})
it("should state an invalid datasource cannot connect", async () => {
await config.api.datasource.verify(
{
datasource: {
...rawDatasource,
config: {
...rawDatasource.config,
password: "wrongpassword",
},
},
},
{
body: {
connected: false,
error:
"Access denied for the specified user. User does not have the necessary privileges or the provided credentials are incorrect. Please verify the credentials, and ensure that the user has appropriate permissions.",
},
}
)
})
})
describe("POST /api/datasources/info", () => {
it("should fetch information about mysql datasource", async () => {
const primaryName = primaryMySqlTable.name
const response = await makeRequest("post", "/api/datasources/info", {
datasource: datasource,
})
expect(response.status).toBe(200)
expect(response.body.tableNames).toBeDefined()
expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-1)
})
})
describe("Integration compatibility with mysql search_path", () => {
let datasource: Datasource, rawDatasource: Datasource
const database = generator.guid()

View file

@ -1035,54 +1035,6 @@ describe("postgres integrations", () => {
})
})
describe("POST /api/datasources/verify", () => {
it("should be able to verify the connection", async () => {
await config.api.datasource.verify(
{
datasource: await getDatasource(DatabaseName.POSTGRES),
},
{
body: {
connected: true,
},
}
)
})
it("should state an invalid datasource cannot connect", async () => {
const dbConfig = await getDatasource(DatabaseName.POSTGRES)
await config.api.datasource.verify(
{
datasource: {
...dbConfig,
config: {
...dbConfig.config,
password: "wrongpassword",
},
},
},
{
body: {
connected: false,
error: 'password authentication failed for user "postgres"',
},
}
)
})
})
describe("POST /api/datasources/info", () => {
it("should fetch information about postgres datasource", async () => {
const primaryName = primaryPostgresTable.name
const response = await makeRequest("post", "/api/datasources/info", {
datasource: datasource,
})
expect(response.status).toBe(200)
expect(response.body.tableNames).toBeDefined()
expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-1)
})
})
describe("POST /api/datasources/:datasourceId/schema", () => {
let tableName: string

View file

@ -6,6 +6,7 @@ import {
UpdateDatasourceRequest,
QueryJson,
BuildSchemaFromSourceResponse,
FetchDatasourceInfoResponse,
} from "@budibase/types"
import { Expectations, TestAPI } from "./base"
@ -83,4 +84,14 @@ export class DatasourceAPI extends TestAPI {
}
)
}
info = async (datasource: Datasource, expectations?: Expectations) => {
return await this._post<FetchDatasourceInfoResponse>(
`/api/datasources/info`,
{
body: { datasource },
expectations,
}
)
}
}