Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for deleting profiles #689

Merged
merged 21 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __mocks__/@zowe/imperative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export class CliProfileManager {
public getAllProfileNames(){
return ["name1", "name2"];
}
public delete(){
return { name: "profile1", profile: {}, type: "zosmf" };
}
}

// tslint:disable-next-line:max-classes-per-file
Expand Down
215 changes: 212 additions & 3 deletions __tests__/__unit__/Profiles.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,73 @@ import * as path from "path";
import * as os from "os";
import * as vscode from "vscode";
import * as child_process from "child_process";
import { Logger, IProfileLoaded } from "@zowe/imperative";
import * as testConst from "../../resources/testProfileData";
import * as globals from "../../src/globals";
import { Logger, ISession, CliProfileManager, IProfileLoaded, Session } from "@zowe/imperative";
import { Profiles, ValidProfileEnum } from "../../src/Profiles";
import { ZosmfSession } from "@zowe/cli";
import { ZosmfSession, IJob } from "@zowe/cli";
import { ZoweUSSNode } from "../../src/uss/ZoweUSSNode";
import { ZoweDatasetNode } from "../../src/dataset/ZoweDatasetNode";
import { Job } from "../../src/job/ZoweJobNode";
import { IZoweDatasetTreeNode, IZoweUSSTreeNode, IZoweJobTreeNode, IZoweNodeType } from "../../src/api/IZoweTreeNode";
import { IZoweTree } from "../../src/api/IZoweTree";
import { DatasetTree } from "../../src/dataset/DatasetTree";
import { USSTree } from "../../src/uss/USSTree";
import { ZosJobsProvider } from "../../src/job/ZosJobsProvider";
import * as testConst from "../../resources/testProfileData";

describe("Profile class unit tests", () => {
// Mocking log.debug
const log = Logger.getAppLogger();

const profileOne = { name: "profile1", profile: {}, type: "zosmf" };
const profileTwo = { name: "profile2", profile: {}, type: "zosmf" };
const mockLoadNamedProfile = jest.fn();
const profileThree: IProfileLoaded = {
name: "profile3",
profile: {
user: undefined,
password: undefined
},
type: "zosmf",
message: "",
failNotFound: false
};
mockLoadNamedProfile.mockReturnValue(profileThree);

const session = new Session({
user: "fake",
password: "fake",
hostname: "fake",
protocol: "https",
type: "basic",
});

const iJob: IJob = {
"jobid": "JOB1234",
"jobname": "TESTJOB",
"files-url": "fake/files",
"job-correlator": "correlator",
"phase-name": "PHASE",
"reason-not-running": "",
"step-data": [{
"proc-step-name": "",
"program-name": "",
"step-name": "",
"step-number": 1,
"active": "",
"smfid": ""

}],
"class": "A",
"owner": "USER",
"phase": 0,
"retcode": "",
"status": "ACTIVE",
"subsystem": "SYS",
"type": "JOB",
"url": "fake/url"
};

const inputBox: vscode.InputBox = {
value: "input",
title: null,
Expand Down Expand Up @@ -68,6 +124,10 @@ describe("Profile class unit tests", () => {
Object.defineProperty(vscode.workspace, "getConfiguration", { value: getConfiguration });
Object.defineProperty(ZosmfSession, "createBasicZosmfSession", { value: createBasicZosmfSession });

const sessTree: IZoweTree<IZoweDatasetTreeNode> = new DatasetTree();
const ussTree: IZoweTree<IZoweUSSTreeNode> = new USSTree();
const jobsTree: IZoweTree<IZoweJobTreeNode> = new ZosJobsProvider();

beforeEach(() => {
mockJSONParse.mockReturnValue({
overrides: {
Expand Down Expand Up @@ -397,6 +457,155 @@ describe("Profile class unit tests", () => {

});

describe("Deleting Profiles", () => {
let profiles: Profiles;
crawr marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(async () => {
profiles = await Profiles.createInstance(log);
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
return {
allProfiles: [{name: "profile1"}, {name: "profile2"}, {name: "profile3"}],
defaultProfile: {name: "profile1"},
loadNamedProfile: mockLoadNamedProfile,
promptCredentials: jest.fn(()=> {
return {};
}),
createNewConnection: jest.fn(()=>{
return {};
}),
listProfile: jest.fn(()=>{
return {};
}),
saveProfile: jest.fn(()=>{
return {profile: {}};
}),
validateAndParseUrl: jest.fn(()=>{
return {};
}),
updateProfile: jest.fn(()=>{
return {};
}),
getDeleteProfile: jest.fn(()=>{
return {};
}),
deletePrompt: jest.fn(()=>{
return {};
}),
deleteProf: jest.fn(()=>{
return {};
})
};
})
});
});

afterEach(() => {
showInputBox.mockReset();
showQuickPick.mockReset();
createInputBox.mockReset();
showInformationMessage.mockReset();
showErrorMessage.mockReset();
});

it("should delete profile from command palette", async () => {
showQuickPick.mockResolvedValueOnce("profile1");
showQuickPick.mockResolvedValueOnce("Yes");
await profiles.deleteProfile(sessTree, ussTree, jobsTree);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Profile profile1 was deleted.");
});

it("should handle missing selection: profile name", async () => {
showQuickPick.mockResolvedValueOnce(undefined);
await profiles.deleteProfile(sessTree, ussTree, jobsTree);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Operation Cancelled");
});

it("should handle case where user selects No", async () => {
showQuickPick.mockResolvedValueOnce("profile1");
showQuickPick.mockResolvedValueOnce("No");
await profiles.deleteProfile(sessTree, ussTree, jobsTree);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Operation Cancelled");
});

it("should handle case where there are no profiles to delete", async () => {
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
return {
allProfiles: []
};
})
});
profiles.refresh();
await profiles.deleteProfile(sessTree, ussTree, jobsTree);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("No profiles available");
});

it("should delete profile from context menu", async () => {
const dsNode = new ZoweDatasetNode(
"profile3", vscode.TreeItemCollapsibleState.Expanded, null, session, undefined, undefined, profileThree);
dsNode.contextValue = globals.DS_SESSION_CONTEXT;
showQuickPick.mockResolvedValueOnce("Yes");
await profiles.deleteProfile(sessTree, ussTree, jobsTree, dsNode);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Profile profile3 was deleted.");
});

it("should delete session from Data Set tree", async () => {
const startLength = sessTree.mSessionNodes.length;
const favoriteLength = sessTree.mFavorites.length;
const dsNode = new ZoweDatasetNode(
"profile3", vscode.TreeItemCollapsibleState.Expanded, null, session, undefined, undefined, profileThree);
dsNode.contextValue = globals.DS_SESSION_CONTEXT;
sessTree.mSessionNodes.push(dsNode);
sessTree.addFavorite(dsNode);
showQuickPick.mockResolvedValueOnce("Yes");
await profiles.deleteProfile(sessTree, ussTree, jobsTree, dsNode);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Profile profile3 was deleted.");
expect(sessTree.mSessionNodes.length).toEqual(startLength);
expect(sessTree.mFavorites.length).toEqual(favoriteLength);
});

it("should delete session from USS tree", async () => {
const startLength = ussTree.mSessionNodes.length;
const favoriteLength = ussTree.mFavorites.length;
const ussNode = new ZoweUSSNode(
"[profile3]: profile3", vscode.TreeItemCollapsibleState.Expanded,
null, session, null, false, profileThree.name, null, profileThree);
ussNode.contextValue = globals.USS_SESSION_CONTEXT;
ussNode.profile = profileThree;
ussTree.addSession("profile3");
ussTree.mSessionNodes.push(ussNode);
ussTree.mFavorites.push(ussNode);
showQuickPick.mockResolvedValueOnce("Yes");
await profiles.deleteProfile(sessTree, ussTree, jobsTree, ussNode);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Profile profile3 was deleted.");
expect(ussTree.mSessionNodes.length).toEqual(startLength);
expect(ussTree.mFavorites.length).toEqual(favoriteLength);
});

it("should delete session from Jobs tree", async () => {
const startLength = jobsTree.mSessionNodes.length;
const favoriteLength = jobsTree.mFavorites.length;
const jobNode = new Job(
"profile3", vscode.TreeItemCollapsibleState.Expanded, null, session, iJob, profileThree);
jobNode.contextValue = globals.JOBS_SESSION_CONTEXT;
jobsTree.mSessionNodes.push(jobNode);
jobsTree.addFavorite(jobNode);
showQuickPick.mockResolvedValueOnce("Yes");
await profiles.deleteProfile(sessTree, ussTree, jobsTree, jobNode);
expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Profile profile3 was deleted.");
expect(jobsTree.mSessionNodes.length).toEqual(startLength);
expect(jobsTree.mFavorites.length).toEqual(favoriteLength);
});
});

it("should route through to spawn. Covers conditional test", async () => {
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
Expand Down
18 changes: 18 additions & 0 deletions __tests__/__unit__/__snapshots__/extension.unit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ Array [
"group": "inline",
"when": "view == zowe.explorer && viewItem =~ /^(?!.*_fav.*)session.*/",
},
Object {
"command": "zowe.deleteProfile",
"group": "6_modification@4",
"when": "view == zowe.explorer && viewItem =~ /^(?!.*_fav.*)session.*/",
},
Object {
"command": "zowe.removeSession",
"group": "6_modification@3",
"when": "view == zowe.explorer && viewItem =~ /^(?!.*_fav.*)session.*/",
},
Object {
Expand All @@ -220,8 +226,14 @@ Array [
"group": "inline",
"when": "viewItem =~ /^ussSession.*/",
},
Object {
"command": "zowe.uss.deleteProfile",
"group": "6_modification@4",
"when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/",
},
Object {
"command": "zowe.uss.removeSession",
"group": "6_modification@3",
"when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/",
},
Object {
Expand All @@ -244,6 +256,11 @@ Array [
"group": "inline",
"when": "view == zowe.jobs && viewItem =~ /^(?!.*_fav.*)server.*/",
},
Object {
"command": "zowe.jobs.deleteProfile",
"group": "6_modification@4",
"when": "view == zowe.jobs && viewItem =~ /^(?!.*_fav.*)server.*/",
},
Object {
"command": "zowe.setOwner",
"when": "view == zowe.jobs && viewItem =~ /^(?!.*_fav.*)server.*/",
Expand All @@ -254,6 +271,7 @@ Array [
},
Object {
"command": "zowe.removeJobsSession",
"group": "6_modification@3",
"when": "view == zowe.jobs && viewItem =~ /^(?!.*_fav.*)server.*/",
},
Object {
Expand Down
8 changes: 6 additions & 2 deletions __tests__/__unit__/extension.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ describe("Extension Unit Tests", () => {
expect(createTreeView.mock.calls[0][0]).toBe("zowe.explorer");
expect(createTreeView.mock.calls[1][0]).toBe("zowe.uss.explorer");
// tslint:disable-next-line: no-magic-numbers
expect(registerCommand.mock.calls.length).toBe(68);
expect(registerCommand.mock.calls.length).toBe(72);
crawr marked this conversation as resolved.
Show resolved Hide resolved
registerCommand.mock.calls.forEach((call, i ) => {
expect(registerCommand.mock.calls[i][1]).toBeInstanceOf(Function);
});
Expand Down Expand Up @@ -761,7 +761,11 @@ describe("Extension Unit Tests", () => {
"zowe.jobs.saveSearch",
"zowe.jobs.removeSearchFavorite",
"zowe.openRecentMember",
"zowe.searchInAllLoadedItems"
"zowe.searchInAllLoadedItems",
"zowe.deleteProfile",
"zowe.cmd.deleteProfile",
"zowe.uss.deleteProfile",
"zowe.jobs.deleteProfile",
];
expect(actualCommands).toEqual(expectedCommands);
expect(onDidSaveTextDocument.mock.calls.length).toBe(1);
Expand Down
8 changes: 5 additions & 3 deletions i18n/sample/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"removeFavorite": "Remove Favorite",
"uss.removeFavorite": "Remove Favorite",
"removeSavedSearch": "Remove Search",
"removeSession": "Remove Profile",
"removeSession": "Hide Profile",
crawr marked this conversation as resolved.
Show resolved Hide resolved
"saveSearch": "Add to Favorites",
"submitJcl": "Submit JCL",
"submitMember": "Submit Job",
Expand All @@ -37,7 +37,7 @@
"uss.editFile": "Edit",
"uss.fullPath": "Search Unix System Services (USS) by Entering a Path",
"uss.refreshUSS": "Pull from Mainframe",
"uss.removeSession": "Remove Profile",
"uss.removeSession": "Hide Profile",
"uss.binary": "Toggle Binary",
"uss.uploadDialog": "Upload Files...",
"uss.text": "Toggle Text",
Expand All @@ -50,7 +50,7 @@
"refreshJobsServer": "Refresh",
"refreshAll": "Refresh All",
"addJobsSession": "Add Profile",
"removeJobsSession": "Remove Profile",
"removeJobsSession": "Hide Profile",
"downloadSpool": "Download Spool",
"getJobJcl": "Get JCL",
"setJobSpool": "Set Spool",
Expand All @@ -68,6 +68,8 @@
"Zowe-Default-Commands-Persistent-Favorites": "Toggle if Commands persist locally",
"Zowe-Environment": "Environment where the extension is running, default is VSCode",
"issueMvsCmd": "Zowe: Issue MVS Command...",
"deleteProfile": "Delete Profile",
"cmd.deleteProfile": "Zowe: Delete a Profile Permanently...",
"rename": "Rename",
"copy": "Copy",
"paste": "Paste",
Expand Down
11 changes: 10 additions & 1 deletion i18n/sample/src/Profiles.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@
"promptcredentials.invalidusername": "Please enter your z/OS username. Operation Cancelled",
"promptcredentials.option.prompt.password.placeholder": "Password",
"promptcredentials.option.prompt.password": "Enter a password for the connection",
"promptcredentials.invalidpassword": "Please enter your z/OS password. Operation Cancelled"
"promptcredentials.invalidpassword": "Please enter your z/OS password. Operation Cancelled",
"deleteProfile.quickPickOption": "Are you sure you want to permanently delete ",
"deleteProfile.undefined.profilename": "Operation Cancelled",
"deleteProfile.noProfilesLoaded": "No profiles available",
"deleteProfile.log.debug": "Deleting profile ",
"deleteProfile.showQuickPick.yes": "Yes",
"deleteProfile.showQuickPick.no": "No",
"deleteProfile.showQuickPick.log.debug": "User picked no. Cancelling delete of profile",
"deleteProfile.delete.log.error": "Error encountered when deleting profile! ",
"deleteProfile.noSelected": "Operation Cancelled"
}
Loading