Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed Feb 8, 2024
1 parent 1115b48 commit 4484095
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,10 @@ export function rerunQuery(rerunQueryElement: QueryHistory) {
context,
rerunQueryElement.language !== "q",
);
} else if (
rerunQueryElement.datasourceType &&
rerunQueryElement.isDatasource
) {
} else {
const dsFile = rerunQueryElement.query as DataSourceFiles;
runDataSource(dsFile);
}
console.log(rerunQueryElement);
}

export async function loadServerObjects(): Promise<ServerObject[]> {
Expand Down
47 changes: 47 additions & 0 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import * as dataSourceUtils from "../../src/utils/dataSource";
import { ExecutionConsole } from "../../src/utils/executionConsole";
import * as queryUtils from "../../src/utils/queryUtils";
import { Connection } from "../../src/models/connection";
import { QueryHistory } from "../../src/models/queryHistory";
import { ServerType } from "../../src/models/server";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const dsCmd = require("../../src/commands/dataSourceCommand");
Expand Down Expand Up @@ -1689,6 +1691,51 @@ describe("serverCommand", () => {
);
});
});

describe("rerunQuery", function () {
let executeQueryStub, runDataSourceStub: sinon.SinonStub;
beforeEach(() => {
runDataSourceStub = sinon
.stub(dataSourceCommand, "runDataSource")
.resolves();

executeQueryStub = sinon.stub(serverCommand, "executeQuery").resolves();
});
this.afterEach(() => {
sinon.restore();
});
it("should execute query for non-datasource query", async function () {
const rerunQueryElement: QueryHistory = {
isDatasource: false,
query: "SELECT * FROM table",
language: "q",
time: "",
success: true,
connectionName: "",
connectionType: ServerType.KDB,
};

serverCommand.rerunQuery(rerunQueryElement);
sinon.assert.notCalled(runDataSourceStub);
});

it("should run datasource for datasource query", async function () {
const ds = createDefaultDataSourceFile();
const rerunQueryElement: QueryHistory = {
isDatasource: true,
datasourceType: DataSourceTypes.QSQL,
query: ds,
connectionName: "",
connectionType: ServerType.INSIGHTS,
time: "",
success: false,
};

await serverCommand.rerunQuery(rerunQueryElement);

sinon.assert.notCalled(executeQueryStub);
});
});
});

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

0 comments on commit 4484095

Please sign in to comment.