diff --git a/packages/server/src/integrations/arangodb.ts b/packages/server/src/integrations/arangodb.ts index 9b34cf3848..544dc12377 100644 --- a/packages/server/src/integrations/arangodb.ts +++ b/packages/server/src/integrations/arangodb.ts @@ -6,7 +6,7 @@ import { DatasourceFeature, } from "@budibase/types" -const { Database, aql } = require("arangojs") +import { Database, aql } from "arangojs" interface ArangodbConfig { url: string @@ -60,7 +60,7 @@ const SCHEMA: Integration = { class ArangoDBIntegration implements IntegrationBase { private config: ArangodbConfig - private client: any + private client constructor(config: ArangodbConfig) { const newConfig = { @@ -76,6 +76,15 @@ class ArangoDBIntegration implements IntegrationBase { this.client = new Database(newConfig) } + async testConnection() { + try { + await this.client.get() + return true + } catch (e: any) { + return { error: e.message as string } + } + } + async read(query: { sql: any }) { try { const result = await this.client.query(query.sql) diff --git a/qa-core/src/integrations/validators/arango.spec.ts b/qa-core/src/integrations/validators/arango.spec.ts new file mode 100644 index 0000000000..51282de13f --- /dev/null +++ b/qa-core/src/integrations/validators/arango.spec.ts @@ -0,0 +1,75 @@ +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", () => { + 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 integration = new arangodb.integration({ + url: connectionSettings.url, + username: connectionSettings.user, + password: connectionSettings.password, + databaseName: "", + collection: "", + }) + const result = await integration.testConnection() + expect(result).toBe(true) + }) + + it("test wrong password", async () => { + const integration = new arangodb.integration({ + url: connectionSettings.url, + username: connectionSettings.user, + password: "wrong", + databaseName: "", + collection: "", + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: "not authorized to execute this request", + }) + }) + + it("test wrong url", async () => { + const integration = new arangodb.integration({ + url: "http://not.here", + username: connectionSettings.user, + password: connectionSettings.password, + databaseName: "", + collection: "", + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: "getaddrinfo ENOTFOUND not.here", + }) + }) + }) +})