Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed Feb 7, 2024
1 parent f1b45f5 commit d435129
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 28 deletions.
51 changes: 24 additions & 27 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ import { ExecutionConsole } from "../../src/utils/executionConsole";
import * as queryUtils from "../../src/utils/queryUtils";
import { Connection } from "../../src/models/connection";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const srvCommand = require("../../src/commands/serverCommand");

// eslint-disable-next-line @typescript-eslint/no-var-requires
const dsCmd = require("../../src/commands/dataSourceCommand");

Expand Down Expand Up @@ -458,7 +455,7 @@ describe("dataSourceCommand2", () => {
dataSourceUtils,
"checkIfTimeParamIsCorrect",
);
getDataInsightsStub = sinon.stub(srvCommand, "getDataInsights");
getDataInsightsStub = sinon.stub(serverCommand, "getDataInsights");
handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults");
handleScratchpadTableRes = sinon.stub(
queryUtils,
Expand Down Expand Up @@ -520,7 +517,7 @@ describe("dataSourceCommand2", () => {
let handleScratchpadTableRes: sinon.SinonStub;

beforeEach(() => {
getDataInsightsStub = sinon.stub(srvCommand, "getDataInsights");
getDataInsightsStub = sinon.stub(serverCommand, "getDataInsights");
handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults");
handleScratchpadTableRes = sinon.stub(
queryUtils,
Expand Down Expand Up @@ -564,7 +561,7 @@ describe("dataSourceCommand2", () => {
let handleScratchpadTableRes: sinon.SinonStub;

beforeEach(() => {
getDataInsightsStub = sinon.stub(srvCommand, "getDataInsights");
getDataInsightsStub = sinon.stub(serverCommand, "getDataInsights");
handleWSResultsStub = sinon.stub(queryUtils, "handleWSResults");
handleScratchpadTableRes = sinon.stub(
queryUtils,
Expand Down Expand Up @@ -746,21 +743,21 @@ describe("dataSourceCommand2", () => {
ext.outputChannel = vscode.window.createOutputChannel("kdb");

beforeEach(() => {
getMetaStub = sinon.stub(srvCommand, "getMeta");
getMetaStub = sinon.stub(serverCommand, "getMeta");
isVisibleStub = sinon.stub(ext.resultsViewProvider, "isVisible");
handleWSResultsStub = sinon
.stub(queryUtils, "handleWSResults")
.returns("dummy results");
handleScratchpadTableRes = sinon
.stub(queryUtils, "handleScratchpadTableRes")
.returns("dummy results");
getDataInsightsStub = sinon.stub(srvCommand, "getDataInsights");
getDataInsightsStub = sinon.stub(serverCommand, "getDataInsights");
writeQueryResultsToViewStub = sinon.stub(
srvCommand,
serverCommand,
"writeQueryResultsToView",
);
writeQueryResultsToConsoleStub = sinon.stub(
srvCommand,
serverCommand,
"writeQueryResultsToConsole",
);
});
Expand Down Expand Up @@ -904,9 +901,9 @@ describe("serverCommand", () => {
const qpStub = sinon.stub(window, "showQuickPick").returns(undefined);

const spy = sinon.spy();
const kdbMock = sinon.mock(srvCommand);
const kdbMock = sinon.mock(serverCommand);
kdbMock.expects("addKdbConnection").never();
const insMock = sinon.mock(srvCommand);
const insMock = sinon.mock(serverCommand);
insMock.expects("addInsightsConnection").never();

await serverCommand.addNewConnection();
Expand All @@ -930,7 +927,7 @@ describe("serverCommand", () => {

const qpStub = sinon.stub(window, "showQuickPick").resolves(qpItem);
const kdbStub = sinon
.stub(srvCommand, "addKdbConnection")
.stub(serverCommand, "addKdbConnection")
.returns(undefined);

await serverCommand.addNewConnection();
Expand Down Expand Up @@ -965,7 +962,7 @@ describe("serverCommand", () => {

const qpStub = sinon.stub(window, "showQuickPick").resolves(qpItem);
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);

await serverCommand.addNewConnection();
Expand All @@ -990,7 +987,7 @@ describe("serverCommand", () => {
.onSecondCall()
.resolves("https://insights.test");
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);

await serverCommand.addNewConnection();
Expand All @@ -1016,7 +1013,7 @@ describe("serverCommand", () => {
.onSecondCall()
.resolves("https://insights.test");
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);

await serverCommand.addNewConnection();
Expand All @@ -1042,7 +1039,7 @@ describe("serverCommand", () => {
.onSecondCall()
.resolves("https://insights.test");
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);
const getInsightsStub = sinon
.stub(insModule, "getInsights")
Expand Down Expand Up @@ -1076,7 +1073,7 @@ describe("serverCommand", () => {
.onSecondCall()
.resolves("https://insights.test");
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);
const getInsightsStub = sinon
.stub(insModule, "getInsights")
Expand Down Expand Up @@ -1114,7 +1111,7 @@ describe("serverCommand", () => {
.onSecondCall()
.resolves("https://insights.test");
const insStub = sinon
.stub(srvCommand, "addInsightsConnection")
.stub(serverCommand, "addInsightsConnection")
.returns(undefined);
const getInsightsStub = sinon
.stub(insModule, "getInsights")
Expand Down Expand Up @@ -1168,7 +1165,7 @@ describe("serverCommand", () => {
ext.openSslVersion = null;
showErrorMessageStub.resolves("More Info");

await srvCommand.enableTLS("test");
await serverCommand.enableTLS("test");

sinon.assert.calledOnce(showErrorMessageStub);
sinon.assert.calledWith(
Expand All @@ -1184,7 +1181,7 @@ describe("serverCommand", () => {
ext.openSslVersion = "1.0.2";
getServersStub.returns({});

await srvCommand.enableTLS("test");
await serverCommand.enableTLS("test");

sinon.assert.calledOnce(showErrorMessageStub);
sinon.assert.calledWith(
Expand Down Expand Up @@ -1226,7 +1223,7 @@ describe("serverCommand", () => {
managed: false,
},
});
await srvCommand.enableTLS("test");
await serverCommand.enableTLS("test");
sinon.assert.calledOnce(updateServersStub);
});
});
Expand Down Expand Up @@ -1258,11 +1255,11 @@ describe("serverCommand", () => {
"appendQueryError",
);
writeQueryResultsToViewStub = sinon.stub(
srvCommand,
serverCommand,
"writeQueryResultsToView",
);
writeQueryResultsToConsoleStub = sinon.stub(
srvCommand,
serverCommand,
"writeQueryResultsToConsole",
);
isVisibleStub = sinon.stub(ext.resultsViewProvider, "isVisible");
Expand All @@ -1275,23 +1272,23 @@ describe("serverCommand", () => {
it("should write appendQueryError", () => {
scratchpadResult.error = true;
scratchpadResult.errorMsg = "error";
srvCommand.writeScratchpadResult(scratchpadResult, "dummy query");
serverCommand.writeScratchpadResult(scratchpadResult, "dummy query");
sinon.assert.notCalled(writeQueryResultsToViewStub);
sinon.assert.notCalled(writeQueryResultsToConsoleStub);
});

it("should write to view", () => {
scratchpadResult.data = "data";
isVisibleStub.returns(true);
srvCommand.writeScratchpadResult(scratchpadResult, "dummy query");
serverCommand.writeScratchpadResult(scratchpadResult, "dummy query");
sinon.assert.notCalled(writeQueryResultsToConsoleStub);
sinon.assert.notCalled(queryConsoleErrorStub);
});

it("should write to console", () => {
scratchpadResult.data = "data";
isVisibleStub.returns(false);
srvCommand.writeScratchpadResult(scratchpadResult, "dummy query");
serverCommand.writeScratchpadResult(scratchpadResult, "dummy query");
sinon.assert.notCalled(writeQueryResultsToViewStub);
});
});
Expand Down
32 changes: 31 additions & 1 deletion test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
DDateTimeClass,
DTimestampClass,
} from "../../src/ipc/cClasses";
import { DataSourceTypes } from "../../src/models/dataSource";

interface ITestItem extends vscode.QuickPickItem {
id: number;
Expand Down Expand Up @@ -492,7 +493,7 @@ describe("Utils", () => {

ext.connectionNode = kdbNode;

queryConsole.appendQueryError(query, output, true, serverName);
queryConsole.appendQueryError(query, output, true, serverName, true);
assert.strictEqual(ext.kdbQueryHistoryList.length, 1);
assert.strictEqual(ext.kdbQueryHistoryList[0].success, false);
assert.strictEqual(
Expand Down Expand Up @@ -544,6 +545,35 @@ describe("Utils", () => {
queryUtils.addQueryHistory(query, connectionName, connectionType, true);
assert.strictEqual(ext.kdbQueryHistoryList.length, 1);
});

it("addQueryHistory in python", () => {
const query = "SELECT * FROM table";
const connectionName = "test";
const connectionType = ServerType.KDB;

ext.kdbQueryHistoryList.length = 0;

queryUtils.addQueryHistory(
query,
connectionName,
connectionType,
true,
true,
);
assert.strictEqual(ext.kdbQueryHistoryList.length, 1);
});
});

describe("selectDSType", () => {
it("should return correct DataSourceTypes for given input", function () {
assert.equal(queryUtils.selectDSType("API"), DataSourceTypes.API);
assert.equal(queryUtils.selectDSType("QSQL"), DataSourceTypes.QSQL);
assert.equal(queryUtils.selectDSType("SQL"), DataSourceTypes.SQL);
});

it("should return undefined for unknown input", function () {
assert.equal(queryUtils.selectDSType("unknown"), undefined);
});
});

describe("getNonce", () => {
Expand Down

0 comments on commit d435129

Please sign in to comment.