Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed May 20, 2024
1 parent d65fb39 commit 4709f50
Showing 1 changed file with 118 additions and 40 deletions.
158 changes: 118 additions & 40 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,71 +111,149 @@ describe("Utils", () => {
getConfigurationStub.restore();
});

describe("server alias", () => {
beforeEach(() => {
ext.kdbConnectionAliasList.length = 0;
it("should update configuration and set hideDetailedConsoleQueryOutput to true when setting is undefined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(undefined),
update: sinon.stub(),
});

afterEach(() => {
ext.kdbConnectionAliasList.length = 0;
await coreUtils.getHideDetailedConsoleQueryOutput();

sinon.assert.calledTwice(getConfigurationStub);
assert.strictEqual(ext.hideDetailedConsoleQueryOutput, true);
});

it("should set hideDetailedConsoleQueryOutput to setting when setting is defined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(false),
update: sinon.stub(),
});

it("should add insights alias to the list getInsightsAlias", () => {
const insightsDetail: InsightDetails = {
alias: "test",
server: "test",
auth: true,
};
coreUtils.getInsightsAlias([insightsDetail]);
assert.strictEqual(ext.kdbConnectionAliasList.length, 1);
await coreUtils.getHideDetailedConsoleQueryOutput();

sinon.assert.calledOnce(getConfigurationStub);
assert.strictEqual(ext.hideDetailedConsoleQueryOutput, false);
});
});

describe("getNetworkChangesWatcher", () => {
let getConfigurationStub: sinon.SinonStub;

beforeEach(() => {
getConfigurationStub = sinon.stub(
vscode.workspace,
"getConfiguration",
) as sinon.SinonStub;
});

afterEach(() => {
getConfigurationStub.restore();
});

it("should update configuration and set getNetworkChangesWatcher to true when setting is undefined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(undefined),
update: sinon.stub(),
});

it("should add alias only from kdb server that have alias using getServerAlias", () => {
const serverList: ServerDetails[] = [
{
serverName: "test",
serverAlias: "test",
serverPort: "5001",
managed: false,
auth: false,
tls: false,
},
{
serverName: "test2",
serverAlias: undefined,
serverPort: "5001",
managed: false,
auth: false,
tls: false,
},
];
coreUtils.getServerAlias(serverList);
assert.strictEqual(ext.kdbConnectionAliasList.length, 1);
await coreUtils.getNetworkChangesWatcher();

sinon.assert.calledTwice(getConfigurationStub);
assert.strictEqual(ext.networkChangesWatcher, true);
});

it("should set getNetworkChangesWatcher to setting when setting is defined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(false),
update: sinon.stub(),
});

await coreUtils.getNetworkChangesWatcher();

sinon.assert.calledOnce(getConfigurationStub);
assert.strictEqual(ext.networkChangesWatcher, false);
});
});

it("should update configuration and set hideDetailedConsoleQueryOutput to true when setting is undefined", async () => {
describe("getInsightsHydrate", () => {
let getConfigurationStub: sinon.SinonStub;

beforeEach(() => {
getConfigurationStub = sinon.stub(
vscode.workspace,
"getConfiguration",
) as sinon.SinonStub;
});

afterEach(() => {
getConfigurationStub.restore();
});

it("should update configuration and set getInsightsHydrate to true when setting is undefined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(undefined),
update: sinon.stub(),
});

await coreUtils.getHideDetailedConsoleQueryOutput();
await coreUtils.getInsightsHydrate();

sinon.assert.calledTwice(getConfigurationStub);
assert.strictEqual(ext.hideDetailedConsoleQueryOutput, true);
assert.strictEqual(ext.insightsHydrate, true);
});

it("should set hideDetailedConsoleQueryOutput to setting when setting is defined", async () => {
it("should set getInsightsHydrate to setting when setting is defined", async () => {
getConfigurationStub.returns({
get: sinon.stub().returns(false),
update: sinon.stub(),
});

await coreUtils.getHideDetailedConsoleQueryOutput();
await coreUtils.getInsightsHydrate();

sinon.assert.calledOnce(getConfigurationStub);
assert.strictEqual(ext.hideDetailedConsoleQueryOutput, false);
assert.strictEqual(ext.insightsHydrate, false);
});
});

describe("server alias", () => {
beforeEach(() => {
ext.kdbConnectionAliasList.length = 0;
});

afterEach(() => {
ext.kdbConnectionAliasList.length = 0;
});

it("should add insights alias to the list getInsightsAlias", () => {
const insightsDetail: InsightDetails = {
alias: "test",
server: "test",
auth: true,
};
coreUtils.getInsightsAlias([insightsDetail]);
assert.strictEqual(ext.kdbConnectionAliasList.length, 1);
});

it("should add alias only from kdb server that have alias using getServerAlias", () => {
const serverList: ServerDetails[] = [
{
serverName: "test",
serverAlias: "test",
serverPort: "5001",
managed: false,
auth: false,
tls: false,
},
{
serverName: "test2",
serverAlias: undefined,
serverPort: "5001",
managed: false,
auth: false,
tls: false,
},
];
coreUtils.getServerAlias(serverList);
assert.strictEqual(ext.kdbConnectionAliasList.length, 1);
});
});

Expand Down

0 comments on commit 4709f50

Please sign in to comment.