Skip to content

Commit

Permalink
Test for a prompt when deleting profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Gene Johnston <[email protected]>
  • Loading branch information
gejohnston committed Mar 28, 2024
1 parent 1607890 commit 214b89f
Showing 1 changed file with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@
*
*/

import * as fs from "fs";
import * as fsExtra from "fs-extra";
import { keyring as keytar } from "@zowe/secrets-for-zowe-sdk";
import { Config, ConvertV1Profiles, ConfigSchema } from "../../../../../config";
import { ConvertV1Profiles } from "../../../../../config";
import { IHandlerParameters } from "../../../../../cmd";
import { V1ProfileRead } from "../../../../../profiles";
import { AppSettings } from "../../../../../settings";
import { ImperativeConfig } from "../../../../../utilities";
import * as npmInterface from "../../../../src/plugins/utilities/npm-interface";
import { PluginIssues } from "../../../../src/plugins/utilities/PluginIssues";
import ConvertProfilesHandler from "../../../../src/config/cmd/convert-profiles/convert-profiles.handler";

let stdout: string = "";
Expand All @@ -43,7 +35,10 @@ const getIHandlerParametersObject = (): IHandlerParameters => {
stderr += errors;
}),
errorHeader: jest.fn(() => undefined),
prompt: jest.fn()
prompt: jest.fn((promptString) => {
stdout += promptString;
return "y";
})
}
},
arguments: {},
Expand All @@ -52,35 +47,58 @@ const getIHandlerParametersObject = (): IHandlerParameters => {
};

describe("Configuration Convert Profiles command handler", () => {
const handler = new ConvertProfilesHandler();

it("should report a set of converted profiles", async () => {
const handler = new ConvertProfilesHandler();
// pretend that convert worked
const convertSpy = jest.spyOn(ConvertV1Profiles, "convert").mockResolvedValue(Promise.resolve({
msgs: [
{ msgFormat: 1, msgText: "Report Msg 1" },
{ msgFormat: 1, msgText: "Report Msg 2" },
{ msgFormat: 2, msgText: "Error Msg 1" },
{ msgFormat: 2, msgText: "Error Msg 2" }
],
cfgFilePathNm: ConvertV1Profiles["noCfgFilePathNm"],
numProfilesFound: 0,
profilesConverted: {
zosmf: ["zosmfProfNm1", "zosmfProfNm2", "zosmfProfNm3"],
tso: ["tsoProfNm1", "tsoProfNm2", "tsoProfNm3"],
ssh: ["sshProfNm1", "sshProfNm2", "sshProfNm3"]
},
profilesFailed: [
{ name: "zosmfProfNm4:", type: "zosmf", error: new Error("This profile stinks") },
{ name: "zosmfProfNm5:", type: "zosmf", error: new Error("This profile also stinks") }
]
}));

// pretend that convert worked
const convertSpy = jest.spyOn(ConvertV1Profiles, "convert").mockResolvedValue(Promise.resolve({
msgs: [
{ msgFormat: 1, msgText: "Report Msg 1" },
{ msgFormat: 1, msgText: "Report Msg 2" },
{ msgFormat: 2, msgText: "Error Msg 1" },
{ msgFormat: 2, msgText: "Error Msg 2"}
],
cfgFilePathNm: ConvertV1Profiles["noCfgFilePathNm"],
numProfilesFound: 0,
profilesConverted: {
zosmf: ["zosmfProfNm1", "zosmfProfNm2", "zosmfProfNm3"],
tso: ["tsoProfNm1", "tsoProfNm2", "tsoProfNm3"],
ssh: ["sshProfNm1", "sshProfNm2", "sshProfNm3"]
},
profilesFailed: [
{ name: "zosmfProfNm4:", type: "zosmf", error: new Error("This profile stinks") },
{ name: "zosmfProfNm5:", type: "zosmf", error: new Error("This profile also stinks") }
]
}));
it("should report a set of converted profiles and NOT do any prompt", async () => {
const params = getIHandlerParametersObject();

await handler.process(params);

expect(stdout).not.toContain("If you confirm the deletion of V1 profiles, they are deleted from disk");
expect(stdout).not.toContain("after a successful conversion. Otherwise, they remain but no longer used.");
expect(stdout).not.toContain("You can also delete your V1 profiles later.");
expect(stdout).not.toContain("Do you want to delete your V1 profiles now [y/N]:");

expect(stdout).toContain("Report Msg 1");
expect(stdout).toContain("Report Msg 2");
expect(stdout).toContain("Error Msg 1");
expect(stdout).toContain("Error Msg 2");
expect(stderr).toBe("");
});

it("should prompt for confirmation when delete is requested", async () => {
const params = getIHandlerParametersObject();
params.arguments.delete = true;
params.arguments.prompt = true;

await handler.process(params);

expect(stdout).toContain("If you confirm the deletion of V1 profiles, they are deleted from disk");
expect(stdout).toContain("after a successful conversion. Otherwise, they remain but no longer used.");
expect(stdout).toContain("You can also delete your V1 profiles later.");
expect(stdout).toContain("Do you want to delete your V1 profiles now [y/N]:");

expect(stdout).toContain("Report Msg 1");
expect(stdout).toContain("Report Msg 2");
expect(stdout).toContain("Error Msg 1");
Expand Down

0 comments on commit 214b89f

Please sign in to comment.