Skip to content

Commit

Permalink
Add unit tests for loading profile security value
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed Apr 3, 2023
1 parent e46b273 commit 4127612
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as profileUtils from "../../../src/utils/ProfilesUtils";
import * as vscode from "vscode";
import * as zowe from "@zowe/cli";
import { Profiles } from "../../../src/Profiles";
import { SettingsConfig } from "../../../src/utils/SettingsConfig";

jest.mock("fs");
jest.mock("vscode");
Expand All @@ -35,6 +36,7 @@ describe("ProfileUtils unit tests", () => {
mockWriteFileSync: jest.fn(),
mockOpenSync: jest.fn().mockReturnValue(process.stdout.fd),
mockMkdirSync: jest.fn(),
mockGetDirectValue: jest.fn(),
mockFileRead: { overrides: { CredentialManager: "@zowe/cli" } },
zoweDir: path.normalize("__tests__/.zowe/settings/imperative.json"),
fileHandle: process.stdout.fd,
Expand All @@ -45,9 +47,10 @@ describe("ProfileUtils unit tests", () => {
Object.defineProperty(fs, "openSync", { value: newMocks.mockOpenSync, configurable: true });
Object.defineProperty(fs, "mkdirSync", { value: newMocks.mockMkdirSync, configurable: true });
Object.defineProperty(Gui, "errorMessage", { value: jest.fn(), configurable: true });
Object.defineProperty(globals, "setGlobalSecurityValue", { value: jest.fn(), configurable: true });
Object.defineProperty(SettingsConfig, "getDirectValue", { value: newMocks.mockGetDirectValue, configurable: true });
Object.defineProperty(globals, "LOG", { value: jest.fn(), configurable: true });
Object.defineProperty(globals.LOG, "error", { value: jest.fn(), configurable: true });
Object.defineProperty(globals, "PROFILE_SECURITY", { value: globals.ZOWE_CLI_SCM, configurable: true });
return newMocks;
}

Expand Down Expand Up @@ -307,16 +310,20 @@ describe("ProfileUtils unit tests", () => {
describe("initializeZoweFolder", () => {
it("should create directories and files that do not exist", async () => {
const blockMocks = createBlockMocks();
blockMocks.mockGetDirectValue.mockReturnValue(true);
blockMocks.mockExistsSync.mockReturnValue(false);
await profileUtils.initializeZoweFolder();
expect(globals.PROFILE_SECURITY).toBe(globals.ZOWE_CLI_SCM);
expect(blockMocks.mockMkdirSync).toHaveBeenCalledTimes(2);
expect(blockMocks.mockWriteFileSync).toHaveBeenCalledTimes(1);
});

it("should skip creating directories and files that already exist", async () => {
const blockMocks = createBlockMocks();
blockMocks.mockGetDirectValue.mockReturnValue(false);
blockMocks.mockExistsSync.mockReturnValue(true);
await profileUtils.initializeZoweFolder();
expect(globals.PROFILE_SECURITY).toBe(false);
expect(blockMocks.mockMkdirSync).toHaveBeenCalledTimes(0);
expect(blockMocks.mockWriteFileSync).toHaveBeenCalledTimes(0);
});
Expand Down

0 comments on commit 4127612

Please sign in to comment.