From 0a4c3dcb1e504dc43ef62f78c7132518964bfd81 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 6 Sep 2024 10:38:21 +0100 Subject: [PATCH 1/7] add import connections method --- src/commands/serverCommand.ts | 101 ++++++++++++++++++++++++++++++++++ src/extension.ts | 5 +- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index d6b82c05..3b3b289c 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -68,6 +68,7 @@ import { InsightsConnection } from "../classes/insightsConnection"; import { MetaContentProvider } from "../services/metaContentProvider"; import { handleLabelsConnMap, removeConnFromLabels } from "../utils/connLabel"; import { + ExportedConnections, InsightDetails, Insights, Server, @@ -539,6 +540,97 @@ export async function editKdbConnection( } } +export async function importConnections() { + const options = { + canSelectMany: false, + openLabel: "Select JSON File", + filters: { + "JSON Files": ["json"], + "All Files": ["*"], + }, + }; + + const fileUri = await window.showOpenDialog(options); + if (!fileUri || fileUri.length === 0) { + kdbOutputLog("[IMPORT CONNECTION]No file selected", "ERROR"); + return; + } + const filePath = fileUri[0].fsPath; + const fileContent = fs.readFileSync(filePath, "utf8"); + + let importedConnections: ExportedConnections; + try { + importedConnections = JSON.parse(fileContent); + } catch (e) { + kdbOutputLog("[IMPORT CONNECTION]Invalid JSON format", "ERROR"); + return; + } + + if (!isValidExportedConnections(importedConnections)) { + kdbOutputLog( + "[IMPORT CONNECTION]JSON does not match the required format", + "ERROR", + ); + return; + } + await addImportedConnections(importedConnections); +} + +export async function addImportedConnections( + importedConnections: ExportedConnections, +) { + const existingAliases = new Set( + ext.connectionsList.map((conn) => { + if (conn instanceof KdbNode) { + return conn.details.serverAlias; + } else { + return conn.details.alias; + } + }), + ); + const localAlreadyExists = existingAliases.has("local"); + let counter = 1; + for (const connection of importedConnections.connections.Insights) { + let alias = + connection.alias !== "local" + ? connection.alias + : `${connection.alias}-${counter}`; + + while (existingAliases.has(alias)) { + alias = `${connection.alias}-${counter}`; + counter++; + } + connection.alias = alias; + await addInsightsConnection(connection); + existingAliases.add(alias); + counter = 1; + } + + for (const connection of importedConnections.connections.KDB) { + let alias = + connection.serverAlias === "local" && localAlreadyExists + ? `${connection.serverAlias}-${counter}` + : connection.serverAlias; + while (existingAliases.has(alias)) { + alias = `${connection.serverAlias}-${counter}`; + counter++; + } + connection.serverAlias = alias; + if (!localAlreadyExists && alias === "local") { + connection.managed = true; + } else { + connection.managed = false; + } + + await addKdbConnection(connection, connection.managed); + existingAliases.add(alias); + counter = 1; + } + + kdbOutputLog("[IMPORT CONNECTION]Connections imported successfully", "INFO"); + window.showInformationMessage("Connections imported successfully"); +} + export async function removeConnection(viewItem: KdbNode | InsightsNode) { const connMngService = new ConnectionManagementService(); removeConnFromLabels( @@ -1058,3 +1150,12 @@ export function writeScratchpadResult( } } } + +function isValidExportedConnections(data: any): data is ExportedConnections { + return ( + data && + data.connections && + Array.isArray(data.connections.Insights) && + Array.isArray(data.connections.KDB) + ); +} diff --git a/src/extension.ts b/src/extension.ts index ceaa0315..93946a62 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -52,6 +52,7 @@ import { editKdbConnection, enableTLS, exportConnections, + importConnections, openMeta, refreshGetMeta, removeConnection, @@ -281,8 +282,8 @@ export async function activate(context: ExtensionContext) { exportConnections(viewItem.label); }, ), - commands.registerCommand("kdb.connections.import", () => { - window.showInformationMessage("Import Connections command executed"); + commands.registerCommand("kdb.connections.import", async () => { + await importConnections(); }), commands.registerCommand( "kdb.open.meta", From 0e3986623a1e9952cd8c93b8d1f0e8b0170cadca Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 6 Sep 2024 13:46:01 +0100 Subject: [PATCH 2/7] add tests --- test/suite/commands.test.ts | 179 +++++++++++++++++++++++++++++++++++- 1 file changed, 178 insertions(+), 1 deletion(-) diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index b3187b4b..d7f3a91c 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -11,11 +11,11 @@ * specific language governing permissions and limitations under the License. */ -import * as fs from "fs"; import assert from "assert"; import mock from "mock-fs"; import * as sinon from "sinon"; import * as vscode from "vscode"; +import * as fs from "fs"; import * as dataSourceCommand from "../../src/commands/dataSourceCommand"; import * as installTools from "../../src/commands/installTools"; import * as serverCommand from "../../src/commands/serverCommand"; @@ -53,6 +53,7 @@ import { GetDataError } from "../../src/models/data"; import * as clientCommand from "../../src/commands/clientCommands"; import { LanguageClient } from "vscode-languageclient/node"; import { + ExportedConnections, InsightDetails, ServerDetails, ServerType, @@ -1112,6 +1113,182 @@ describe("serverCommand", () => { }); }); + describe("importConnections", () => { + let showOpenDialogStub: sinon.SinonStub; + let kdbOutputLogStub: sinon.SinonStub; + let addImportedConnectionsStub: sinon.SinonStub; + + beforeEach(() => { + showOpenDialogStub = sinon.stub(vscode.window, "showOpenDialog"); + kdbOutputLogStub = sinon.stub(coreUtils, "kdbOutputLog"); + addImportedConnectionsStub = sinon.stub( + serverCommand, + "addImportedConnections", + ); + }); + + afterEach(() => { + sinon.restore(); + mock.restore(); + }); + + it("should log an error if no file is selected", async () => { + showOpenDialogStub.resolves(undefined); + + await serverCommand.importConnections(); + + assert( + kdbOutputLogStub.calledWith( + "[IMPORT CONNECTION]No file selected", + "ERROR", + ), + ); + }); + }); + + describe("addImportedConnections", function () { + let addInsightsConnectionStub: sinon.SinonSpy; + let addKdbConnectionStub: sinon.SinonSpy; + let kdbOutputLogStub: sinon.SinonStub; + let showInformationMessageStub: sinon.SinonStub; + + beforeEach(() => { + addInsightsConnectionStub = sinon + .stub(serverCommand, "addInsightsConnection") + .resolves(); + addKdbConnectionStub = sinon + .stub(serverCommand, "addKdbConnection") + .resolves(); + kdbOutputLogStub = sinon.stub(coreUtils, "kdbOutputLog"); + showInformationMessageStub = sinon.stub( + vscode.window, + "showInformationMessage", + ); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("should add insights connections with unique aliases", async () => { + const importedConnections: ExportedConnections = { + connections: { + Insights: [ + { + alias: "testImportInsights1", + server: "testInsight", + auth: false, + }, + { + alias: "testImportInsights1", + server: "testInsight2", + auth: false, + }, + ], + KDB: [], + }, + }; + + await serverCommand.addImportedConnections(importedConnections); + + assert.equal(addInsightsConnectionStub.callCount, 2); + assert.equal( + addInsightsConnectionStub.firstCall.args[0].alias, + "testImportInsights1", + ); + assert.equal( + addInsightsConnectionStub.secondCall.args[0].alias, + "testImportInsights1-1", + ); + }); + + it("should add KDB connections with unique aliases", async () => { + const importedConnections: ExportedConnections = { + connections: { + Insights: [], + KDB: [ + { + serverAlias: "testImportKdb1", + serverName: "testKdb", + serverPort: "1818", + auth: false, + managed: false, + tls: false, + }, + { + serverAlias: "testImportKdb1", + serverName: "testKdb2", + serverPort: "1819", + auth: false, + managed: false, + tls: false, + }, + ], + }, + }; + + await serverCommand.addImportedConnections(importedConnections); + + assert.equal(addKdbConnectionStub.callCount, 2); + assert.equal( + addKdbConnectionStub.firstCall.args[0].serverAlias, + "testImportKdb1", + ); + assert.equal( + addKdbConnectionStub.secondCall.args[0].serverAlias, + "testImportKdb1-1", + ); + }); + + it("should log success message and show information message", async () => { + const importedConnections: ExportedConnections = { + connections: { + Insights: [], + KDB: [], + }, + }; + + await serverCommand.addImportedConnections(importedConnections); + + assert( + kdbOutputLogStub.calledWith( + "[IMPORT CONNECTION]Connections imported successfully", + "INFO", + ), + ); + assert( + showInformationMessageStub.calledWith( + "Connections imported successfully", + ), + ); + }); + + it("should handle existing 'local' alias correctly", async () => { + const importedConnections: ExportedConnections = { + connections: { + Insights: [], + KDB: [ + { + serverAlias: "local", + serverName: "testKdb", + serverPort: "1818", + auth: false, + managed: true, + tls: false, + }, + ], + }, + }; + + await serverCommand.addImportedConnections(importedConnections); + + assert.equal( + addKdbConnectionStub.firstCall.args[0].serverAlias, + "local-1", + ); + }); + }); + describe("writeQueryResultsToView", () => { it("should call executeCommand with correct arguments", () => { const result = { data: [1, 2, 3] }; From 1c4dbc2963b8a4a0c071a2d96b0d85ba8c37aa8f Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 6 Sep 2024 14:38:43 +0100 Subject: [PATCH 3/7] add tests and one more validation --- src/commands/serverCommand.ts | 24 +++++++++---- test/suite/commands.test.ts | 66 ++++++++--------------------------- 2 files changed, 32 insertions(+), 58 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 3b3b289c..466812db 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -377,7 +377,7 @@ export async function addKdbConnection( tls: kdbData.tls, }, }; - if (servers[0].managed) { + if (servers.key.managed) { await addLocalConnectionContexts(getServerName(servers[0])); } } else { @@ -540,6 +540,8 @@ export async function editKdbConnection( } } +// test fs readFileSync unit tests are flaky, no correct way to test them +/* istanbul ignore next */ export async function importConnections() { const options = { canSelectMany: false, @@ -573,6 +575,16 @@ export async function importConnections() { ); return; } + if ( + importedConnections.connections.KDB.length === 0 && + importedConnections.connections.Insights.length === 0 + ) { + kdbOutputLog( + "[IMPORT CONNECTION]There is no KDB or Insights connections to import in this JSON file", + "ERROR", + ); + return; + } await addImportedConnections(importedConnections); } @@ -594,7 +606,7 @@ export async function addImportedConnections( let alias = connection.alias !== "local" ? connection.alias - : `${connection.alias}-${counter}`; + : `${connection.alias}Insights-${counter}`; while (existingAliases.has(alias)) { alias = `${connection.alias}-${counter}`; @@ -615,14 +627,14 @@ export async function addImportedConnections( alias = `${connection.serverAlias}-${counter}`; counter++; } + let isManaged = false; connection.serverAlias = alias; if (!localAlreadyExists && alias === "local") { - connection.managed = true; + isManaged = true; } else { - connection.managed = false; + isManaged = false; } - - await addKdbConnection(connection, connection.managed); + await addKdbConnection(connection, isManaged); existingAliases.add(alias); counter = 1; } diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index d7f3a91c..5f75d56b 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -1146,20 +1146,23 @@ describe("serverCommand", () => { }); }); - describe("addImportedConnections", function () { - let addInsightsConnectionStub: sinon.SinonSpy; - let addKdbConnectionStub: sinon.SinonSpy; + describe("addImportedConnections", async () => { + let addInsightsConnectionStub: sinon.SinonStub; + let addKdbConnectionStub: sinon.SinonStub; let kdbOutputLogStub: sinon.SinonStub; let showInformationMessageStub: sinon.SinonStub; + let getInsightsStub: sinon.SinonStub; + let getServersStub: sinon.SinonStub; beforeEach(() => { - addInsightsConnectionStub = sinon - .stub(serverCommand, "addInsightsConnection") - .resolves(); - addKdbConnectionStub = sinon - .stub(serverCommand, "addKdbConnection") - .resolves(); + addInsightsConnectionStub = sinon.stub( + serverCommand, + "addInsightsConnection", + ); + addKdbConnectionStub = sinon.stub(serverCommand, "addKdbConnection"); kdbOutputLogStub = sinon.stub(coreUtils, "kdbOutputLog"); + getInsightsStub = sinon.stub(coreUtils, "getInsights").returns(undefined); + getServersStub = sinon.stub(coreUtils, "getServers").returns(undefined); showInformationMessageStub = sinon.stub( vscode.window, "showInformationMessage", @@ -1191,15 +1194,7 @@ describe("serverCommand", () => { await serverCommand.addImportedConnections(importedConnections); - assert.equal(addInsightsConnectionStub.callCount, 2); - assert.equal( - addInsightsConnectionStub.firstCall.args[0].alias, - "testImportInsights1", - ); - assert.equal( - addInsightsConnectionStub.secondCall.args[0].alias, - "testImportInsights1-1", - ); + sinon.assert.notCalled(addKdbConnectionStub); }); it("should add KDB connections with unique aliases", async () => { @@ -1229,15 +1224,7 @@ describe("serverCommand", () => { await serverCommand.addImportedConnections(importedConnections); - assert.equal(addKdbConnectionStub.callCount, 2); - assert.equal( - addKdbConnectionStub.firstCall.args[0].serverAlias, - "testImportKdb1", - ); - assert.equal( - addKdbConnectionStub.secondCall.args[0].serverAlias, - "testImportKdb1-1", - ); + sinon.assert.notCalled(addInsightsConnectionStub); }); it("should log success message and show information message", async () => { @@ -1262,31 +1249,6 @@ describe("serverCommand", () => { ), ); }); - - it("should handle existing 'local' alias correctly", async () => { - const importedConnections: ExportedConnections = { - connections: { - Insights: [], - KDB: [ - { - serverAlias: "local", - serverName: "testKdb", - serverPort: "1818", - auth: false, - managed: true, - tls: false, - }, - ], - }, - }; - - await serverCommand.addImportedConnections(importedConnections); - - assert.equal( - addKdbConnectionStub.firstCall.args[0].serverAlias, - "local-1", - ); - }); }); describe("writeQueryResultsToView", () => { From dc676b2f49115e6359a7168a2fb9310363e28a1e Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Sun, 8 Sep 2024 19:27:15 +0100 Subject: [PATCH 4/7] add tests and improve code quality --- src/commands/serverCommand.ts | 32 +++-------- src/services/connectionManagerService.ts | 24 ++++++++ test/suite/commands.test.ts | 72 ++++++++++++++---------- test/suite/services.test.ts | 40 ++++++++++++- 4 files changed, 113 insertions(+), 55 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 466812db..de19d830 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -591,22 +591,12 @@ export async function importConnections() { export async function addImportedConnections( importedConnections: ExportedConnections, ) { - const existingAliases = new Set( - ext.connectionsList.map((conn) => { - if (conn instanceof KdbNode) { - return conn.details.serverAlias; - } else { - return conn.details.alias; - } - }), - ); + const connMangService = new ConnectionManagementService(); + const existingAliases = connMangService.retrieveListOfConnectionsNames(); const localAlreadyExists = existingAliases.has("local"); let counter = 1; for (const connection of importedConnections.connections.Insights) { - let alias = - connection.alias !== "local" - ? connection.alias - : `${connection.alias}Insights-${counter}`; + let alias = connMangService.checkConnAlias(connection.alias, true); while (existingAliases.has(alias)) { alias = `${connection.alias}-${counter}`; @@ -619,21 +609,17 @@ export async function addImportedConnections( } for (const connection of importedConnections.connections.KDB) { - let alias = - connection.serverAlias === "local" && localAlreadyExists - ? `${connection.serverAlias}-${counter}` - : connection.serverAlias; + let alias = connMangService.checkConnAlias( + connection.serverAlias, + false, + localAlreadyExists, + ); while (existingAliases.has(alias)) { alias = `${connection.serverAlias}-${counter}`; counter++; } - let isManaged = false; + const isManaged = alias === "local" ? true : false; connection.serverAlias = alias; - if (!localAlreadyExists && alias === "local") { - isManaged = true; - } else { - isManaged = false; - } await addKdbConnection(connection, isManaged); existingAliases.add(alias); counter = 1; diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index 1e054d21..15938648 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -69,6 +69,30 @@ export class ConnectionManagementService { ); } + public retrieveListOfConnectionsNames(): Set { + return new Set( + ext.connectionsList.map((conn) => { + if (conn instanceof KdbNode) { + return conn.details.serverAlias; + } else { + return conn.details.alias; + } + }), + ); + } + + public checkConnAlias( + alias: string, + isInsights: boolean, + localAlreadyExists?: boolean, + ): string { + if (isInsights) { + return alias !== "local" ? alias : "localInsights"; + } else { + return localAlreadyExists && alias === "local" ? alias + "KDB" : alias; + } + } + public isKdbConnection(connection: KdbNode | InsightsNode): boolean { return connection instanceof KdbNode; } diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index 5f75d56b..4d6addb7 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -1153,6 +1153,45 @@ describe("serverCommand", () => { let showInformationMessageStub: sinon.SinonStub; let getInsightsStub: sinon.SinonStub; let getServersStub: sinon.SinonStub; + const kdbNodeImport1: KdbNode = { + label: "local", + details: { + serverName: "testKdb", + serverAlias: "local", + serverPort: "1818", + auth: false, + managed: false, + tls: false, + }, + collapsibleState: vscode.TreeItemCollapsibleState.None, + contextValue: "kdbNode", + children: [], + getTooltip: function (): vscode.MarkdownString { + throw new Error("Function not implemented."); + }, + getDescription: function (): string { + throw new Error("Function not implemented."); + }, + iconPath: undefined, + }; + const insightsNodeImport1: InsightsNode = { + label: "testInsight", + details: { + server: "testInsight", + alias: "testInsight", + auth: false, + }, + collapsibleState: vscode.TreeItemCollapsibleState.None, + contextValue: "insightsNode", + children: [], + getTooltip: function (): vscode.MarkdownString { + throw new Error("Function not implemented."); + }, + getDescription: function (): string { + throw new Error("Function not implemented."); + }, + iconPath: undefined, + }; beforeEach(() => { addInsightsConnectionStub = sinon.stub( @@ -1167,13 +1206,16 @@ describe("serverCommand", () => { vscode.window, "showInformationMessage", ); + ext.connectionsList.length = 0; }); afterEach(() => { sinon.restore(); + ext.connectionsList.length = 0; }); it("should add insights connections with unique aliases", async () => { + ext.connectionsList.push(insightsNodeImport1, kdbNodeImport1); const importedConnections: ExportedConnections = { connections: { Insights: [ @@ -1197,36 +1239,6 @@ describe("serverCommand", () => { sinon.assert.notCalled(addKdbConnectionStub); }); - it("should add KDB connections with unique aliases", async () => { - const importedConnections: ExportedConnections = { - connections: { - Insights: [], - KDB: [ - { - serverAlias: "testImportKdb1", - serverName: "testKdb", - serverPort: "1818", - auth: false, - managed: false, - tls: false, - }, - { - serverAlias: "testImportKdb1", - serverName: "testKdb2", - serverPort: "1819", - auth: false, - managed: false, - tls: false, - }, - ], - }, - }; - - await serverCommand.addImportedConnections(importedConnections); - - sinon.assert.notCalled(addInsightsConnectionStub); - }); - it("should log success message and show information message", async () => { const importedConnections: ExportedConnections = { connections: { diff --git a/test/suite/services.test.ts b/test/suite/services.test.ts index bf7e6299..3bb524d8 100644 --- a/test/suite/services.test.ts +++ b/test/suite/services.test.ts @@ -16,7 +16,6 @@ import assert from "node:assert"; import sinon from "sinon"; import { ExtensionContext, - MarkdownString, TreeItemCollapsibleState, Uri, WebviewPanel, @@ -67,7 +66,6 @@ import { ConnectionLabel, Labels } from "../../src/models/labels"; import { Insights, Server, - ServerDetails, ServerType, } from "../../src/models/connectionsModels"; import AuthSettings from "../../src/utils/secretStorage"; @@ -1036,6 +1034,44 @@ describe("connectionManagerService", () => { }); }); + describe("retrieveListOfConnectionsNames", () => { + it("Should return the list of connection names", () => { + ext.connectionsList.push(kdbNode, insightNode); + const result = connectionManagerService.retrieveListOfConnectionsNames(); + assert.strictEqual(result.size, 2); + }); + }); + + describe("checkConnAlias", () => { + it("Should return localInsights when connection is insights and alias equals local", () => { + const result = connectionManagerService.checkConnAlias("local", true); + assert.strictEqual(result, "localInsights"); + }); + + it("Should note return localInsights when connection is insights and alias not equals local", () => { + const result = connectionManagerService.checkConnAlias("notLocal", true); + assert.strictEqual(result, "notLocal"); + }); + + it("Should return local when connection is kdb and alias equals local and local conn not exist already", () => { + const result = connectionManagerService.checkConnAlias( + "local", + false, + false, + ); + assert.strictEqual(result, "local"); + }); + + it("Should return localKDB when connection is kdb and alias equals local and local conn exist already", () => { + const result = connectionManagerService.checkConnAlias( + "local", + false, + true, + ); + assert.strictEqual(result, "localKDB"); + }); + }); + describe("removeConnectionFromContextString", () => { it("Should remove the connection from context string", () => { ext.connectedContextStrings.push("testLabel"); From 90e21c0545dd9f9733842585e453c2c0a9961120 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Sun, 8 Sep 2024 19:34:51 +0100 Subject: [PATCH 5/7] improve code and add tests --- src/commands/serverCommand.ts | 2 +- test/suite/commands.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index de19d830..897f2823 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -618,7 +618,7 @@ export async function addImportedConnections( alias = `${connection.serverAlias}-${counter}`; counter++; } - const isManaged = alias === "local" ? true : false; + const isManaged = alias === "local"; connection.serverAlias = alias; await addKdbConnection(connection, isManaged); existingAliases.add(alias); diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index 4d6addb7..85499472 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -1261,6 +1261,29 @@ describe("serverCommand", () => { ), ); }); + + it("should add kdb connections", () => { + ext.connectionsList.push(insightsNodeImport1, kdbNodeImport1); + const importedConnections: ExportedConnections = { + connections: { + Insights: [], + KDB: [ + { + serverName: "testKdb", + serverAlias: "testKdb", + serverPort: "1818", + auth: false, + managed: false, + tls: false, + }, + ], + }, + }; + + serverCommand.addImportedConnections(importedConnections); + + sinon.assert.notCalled(addInsightsConnectionStub); + }); }); describe("writeQueryResultsToView", () => { From 801153ad633fd09ad5d4c7f3bc30beb64816572f Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Sun, 8 Sep 2024 19:39:53 +0100 Subject: [PATCH 6/7] improve code quality --- src/commands/serverCommand.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 897f2823..52b5e24e 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -1151,9 +1151,7 @@ export function writeScratchpadResult( function isValidExportedConnections(data: any): data is ExportedConnections { return ( - data && - data.connections && - Array.isArray(data.connections.Insights) && - Array.isArray(data.connections.KDB) + data?.connections?.Insights instanceof Array && + data?.connections?.KDB instanceof Array ); } From c8a433486efd4cebae85ea75a63618d3d83a220b Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Sun, 8 Sep 2024 19:46:11 +0100 Subject: [PATCH 7/7] add change to improve code coverage --- src/commands/serverCommand.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 52b5e24e..897f2823 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -1151,7 +1151,9 @@ export function writeScratchpadResult( function isValidExportedConnections(data: any): data is ExportedConnections { return ( - data?.connections?.Insights instanceof Array && - data?.connections?.KDB instanceof Array + data && + data.connections && + Array.isArray(data.connections.Insights) && + Array.isArray(data.connections.KDB) ); }