Skip to content

Commit

Permalink
fix: add ProfileInfo.getTeamConfig.exists check to v1 profile prompt
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
  • Loading branch information
traeok committed Oct 17, 2024
1 parent a37a5a0 commit a1d2b8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ async function createGlobalMocks() {
"zowe.automaticProfileValidation": true,
}),
});
jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({
getTeamConfig: jest.fn().mockReturnValue({
exists: jest.fn(),
}),
} as any);
Object.defineProperty(globalMocks.mockProfilesCache, "getProfileInfo", {
value: jest.fn(() => {
return { value: globalMocks.mockProfCacheProfileInfo, configurable: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ describe("ProfilesUtils unit tests", () => {
{ name: null, type: "zosmf", error: "failed" as any },
],
} as any);
jest.spyOn(ZoweLocalStorage, "getValue").mockReturnValue(Definitions.V1MigrationStatus.JustMigrated);
jest.spyOn(ZoweLocalStorage, "setValue").mockImplementation();
Object.defineProperty(vscode.workspace, "openTextDocument", { value: jest.fn().mockReturnValue({}), configurable: true });
Object.defineProperty(Gui, "showTextDocument", { value: jest.fn(), configurable: true });
const onlyV1ProfsExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", {
Expand Down Expand Up @@ -1070,13 +1072,22 @@ describe("ProfilesUtils unit tests", () => {

it("should prompt user if v1 profiles detected and Create New is selected", async () => {
const mockReadProfilesFromDisk = jest.fn();
jest.spyOn(vscode.workspace, "getConfiguration").mockReturnValue({
persistent: true,
get: jest.fn(),
has: jest.fn(),
inspect: jest.fn(),
update: jest.fn(),
});
const profInfoSpy = jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({
readProfilesFromDisk: mockReadProfilesFromDisk,
getTeamConfig: jest.fn().mockReturnValue([]),
getAllProfiles: jest.fn().mockReturnValue([createValidIProfile(), createAltTypeIProfile()]),
} as never);
const infoMsgSpy = jest.spyOn(Gui, "infoMessage").mockResolvedValueOnce("Create New");

jest.spyOn(ZoweLocalStorage, "getValue").mockReturnValue(Definitions.V1MigrationStatus.JustMigrated);
jest.spyOn(ZoweLocalStorage, "setValue").mockImplementation();
const onlyV1ProfsExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", {
configurable: true,
get: () => true,
Expand All @@ -1102,12 +1113,17 @@ describe("ProfilesUtils unit tests", () => {
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
blockMocks.getValueMock.mockReturnValueOnce(Definitions.V1MigrationStatus.JustMigrated);
blockMocks.setValueMock.mockImplementation();
jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({
getTeamConfig: jest.fn().mockReturnValue({ exists: false }),
} as any);
const onlyV1ProfilesExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", { get: () => true });
const v1ProfileOptsMock = jest.spyOn(ProfilesUtils as any, "v1ProfileOptions").mockResolvedValue(ProfilesConvertStatus.CreateNewSelected);
await ProfilesUtils.handleV1MigrationStatus();
expect(executeCommandMock.mock.lastCall?.[0]).toBe("zowe.ds.addSession");
expect(v1ProfileOptsMock).toHaveBeenCalled();
blockMocks.getValueMock.mockRestore();
blockMocks.setValueMock.mockRestore();
onlyV1ProfilesExistMock[Symbol.dispose]();
});

it("should reload the window once if the user just migrated from v1", async () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/zowe-explorer/src/utils/ProfilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,20 @@ export class ProfilesUtils {
// VS Code registers our updated TreeView IDs. Otherwise, VS Code's "Refresh Extensions" option will break v3 init.
const ussPersistentSettings = vscode.workspace.getConfiguration("Zowe-USS-Persistent");
const upgradingFromV1 = ZoweLocalStorage.getValue<Definitions.V1MigrationStatus>(Definitions.LocalStorageKey.V1_MIGRATION_STATUS);
const mProfileInfo = await ProfilesUtils.getProfileInfo();
if (ussPersistentSettings != null && upgradingFromV1 == null && imperative.ProfileInfo.onlyV1ProfilesExist) {
await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, Definitions.V1MigrationStatus.JustMigrated);
await vscode.commands.executeCommand("workbench.action.reloadWindow");
}
const userSelection = imperative.ProfileInfo.onlyV1ProfilesExist ? await this.v1ProfileOptions() : undefined;

if (upgradingFromV1 == null || mProfileInfo.getTeamConfig().exists || !imperative.ProfileInfo.onlyV1ProfilesExist) {
return;
}
const userSelection = await this.v1ProfileOptions();

// Open the "Add Session" quick pick if the user selected "Create New" in the v1 migration prompt.
if (userSelection === ProfilesConvertStatus.CreateNewSelected) {
vscode.commands.executeCommand("zowe.ds.addSession", SharedTreeProviders.ds);
await vscode.commands.executeCommand("zowe.ds.addSession", SharedTreeProviders.ds);
}
}

Expand Down Expand Up @@ -563,10 +568,12 @@ export class ProfilesUtils {
switch (selection) {
case createButton:
ZoweLogger.info("Create new team configuration chosen.");
await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, undefined);
return ProfilesConvertStatus.CreateNewSelected;
case convertButton:
ZoweLogger.info("Convert v1 profiles to team configuration chosen.");
await this.convertV1Profs();
await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, undefined);
return ProfilesConvertStatus.ConvertSelected;
default:
return undefined;
Expand Down

0 comments on commit a1d2b8e

Please sign in to comment.