Validate arango

This commit is contained in:
Adria Navarro 2023-05-12 11:17:14 +02:00
parent cb398dad02
commit 901bff5399
2 changed files with 66 additions and 3 deletions

View File

@ -5,9 +5,9 @@ import {
IntegrationBase, IntegrationBase,
} from "@budibase/types" } from "@budibase/types"
const { Database, aql } = require("arangojs") import { Database, aql } from "arangojs"
interface ArangodbConfig { export interface ArangodbConfig {
url: string url: string
username: string username: string
password: string password: string
@ -58,7 +58,7 @@ const SCHEMA: Integration = {
class ArangoDBIntegration implements IntegrationBase { class ArangoDBIntegration implements IntegrationBase {
private config: ArangodbConfig private config: ArangodbConfig
private client: any private client
constructor(config: ArangodbConfig) { constructor(config: ArangodbConfig) {
const newConfig = { const newConfig = {
@ -102,9 +102,24 @@ class ArangoDBIntegration implements IntegrationBase {
this.client.close() this.client.close()
} }
} }
async check() {
await this.client.get()
}
}
async function validateConnection(config: ArangodbConfig) {
const integration = new ArangoDBIntegration(config)
try {
await integration.check()
return true
} catch (e: any) {
return { error: e.message as string }
}
} }
export default { export default {
schema: SCHEMA, schema: SCHEMA,
integration: ArangoDBIntegration, integration: ArangoDBIntegration,
validateConnection,
} }

View File

@ -0,0 +1,48 @@
import { GenericContainer, Wait } from "testcontainers"
import arangodb from "../../../../packages/server/src/integrations/arangodb"
import { generator } from "../../shared"
jest.unmock("arangojs")
describe("datasource validators", () => {
describe("arangodb", () => {
const validator = integrations.getValidator[SourceName.ARANGODB]
let connectionSettings: {
user: string
password: string
url: string
}
beforeAll(async () => {
const user = "root"
const password = generator.hash()
const container = await new GenericContainer("arangodb")
.withExposedPorts(8529)
.withEnv("ARANGO_ROOT_PASSWORD", password)
.withWaitStrategy(
Wait.forLogMessage("is ready for business. Have fun!")
)
.start()
connectionSettings = {
user,
password,
url: `http://${container.getContainerIpAddress()}:${container.getMappedPort(
8529
)}`,
}
})
it("test valid connection string", async () => {
const result = await validator({
url: connectionSettings.url,
username: connectionSettings.user,
password: connectionSettings.password,
databaseName: "",
collection: "",
})
expect(result).toBe(true)
})
})
})