From 0557c8efcc2b06f19cc0e49bbb54de53428381b0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 15 May 2023 16:24:26 +0200 Subject: [PATCH] Split tests --- .../src/integrations/validators/mssql.spec.ts | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 qa-core/src/integrations/validators/mssql.spec.ts diff --git a/qa-core/src/integrations/validators/mssql.spec.ts b/qa-core/src/integrations/validators/mssql.spec.ts new file mode 100644 index 0000000000..89af8e87c0 --- /dev/null +++ b/qa-core/src/integrations/validators/mssql.spec.ts @@ -0,0 +1,64 @@ +import { GenericContainer, Wait } from "testcontainers" +import { Duration, TemporalUnit } from "node-duration" + +import mssql from "../../../../packages/server/src/integrations/microsoftSqlServer" + +jest.unmock("mssql") + +describe("datasource validators", () => { + describe("mssql", () => { + let host: string, port: number + + const password = "Str0Ng_p@ssW0rd!" + + beforeAll(async () => { + const container = await new GenericContainer( + "mcr.microsoft.com/mssql/server" + ) + .withExposedPorts(1433) + .withEnv("ACCEPT_EULA", "Y") + .withEnv("MSSQL_SA_PASSWORD", password) + .withEnv("MSSQL_PID", "Developer") + .withWaitStrategy(Wait.forHealthCheck()) + .withHealthCheck({ + test: `/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${password}" -Q "SELECT 1" -b -o /dev/null`, + interval: new Duration(1000, TemporalUnit.MILLISECONDS), + timeout: new Duration(3, TemporalUnit.SECONDS), + retries: 20, + startPeriod: new Duration(100, TemporalUnit.MILLISECONDS), + }) + .start() + + host = container.getContainerIpAddress() + port = container.getMappedPort(1433) + }) + + it("test valid connection string", async () => { + const integration = new mssql.integration({ + user: "sa", + password, + server: host, + port: port, + database: "master", + schema: "dbo", + }) + const result = await integration.testConnection() + expect(result).toBe(true) + }) + + it("test invalid password", async () => { + const integration = new mssql.integration({ + user: "sa", + password: "wrong_pwd", + server: host, + port: port, + database: "master", + schema: "dbo", + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: "ConnectionError: Login failed for user 'sa'.", + }) + }) + }) +})