From fad57db634e0675740c6e61cc7b368b92253984b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 12 May 2023 13:07:45 +0200 Subject: [PATCH] Implement the check as part of the integration --- packages/server/src/integrations/arangodb.ts | 26 +++++++------------ .../integrations/validators/arango.spec.ts | 11 ++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/server/src/integrations/arangodb.ts b/packages/server/src/integrations/arangodb.ts index 31bbffe060..297a164383 100644 --- a/packages/server/src/integrations/arangodb.ts +++ b/packages/server/src/integrations/arangodb.ts @@ -7,7 +7,7 @@ import { import { Database, aql } from "arangojs" -export interface ArangodbConfig { +interface ArangodbConfig { url: string username: string password: string @@ -74,6 +74,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) @@ -102,24 +111,9 @@ class ArangoDBIntegration implements IntegrationBase { 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 { schema: SCHEMA, integration: ArangoDBIntegration, - validateConnection, } diff --git a/qa-core/src/integrations/validators/arango.spec.ts b/qa-core/src/integrations/validators/arango.spec.ts index 716fc19087..51282de13f 100644 --- a/qa-core/src/integrations/validators/arango.spec.ts +++ b/qa-core/src/integrations/validators/arango.spec.ts @@ -6,8 +6,6 @@ jest.unmock("arangojs") describe("datasource validators", () => { describe("arangodb", () => { - const validator = integrations.getValidator[SourceName.ARANGODB] - let connectionSettings: { user: string password: string @@ -35,37 +33,40 @@ describe("datasource validators", () => { }) it("test valid connection string", async () => { - const result = await validator({ + 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 result = await validator({ + 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 result = await validator({ + 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", })