diff --git a/packages/zowe-explorer-api/__tests__/__unit__/profiles/ZoweExplorerZosmfApi.unit.test.ts b/packages/zowe-explorer-api/__tests__/__unit__/profiles/ZoweExplorerZosmfApi.unit.test.ts index 6a9f113f21..4df0e17aed 100644 --- a/packages/zowe-explorer-api/__tests__/__unit__/profiles/ZoweExplorerZosmfApi.unit.test.ts +++ b/packages/zowe-explorer-api/__tests__/__unit__/profiles/ZoweExplorerZosmfApi.unit.test.ts @@ -90,37 +90,43 @@ async function expectApiWithSession({ name, spy, args, transform }: ITestApi< expect(spy).toHaveBeenCalledWith(fakeSession, ...params); } +describe("CommonApi", () => { + describe("getSession", () => { + it("returns undefined and does not throw error if the session was not created", () => { + const api = new ZoweExplorerZosmf.CommonApi(); + let session: imperative.Session; + expect(() => (session = api.getSession())).not.toThrow(); + expect(session).toBe(undefined); + }); + it("returns a built session from _getSession and does not throw error", () => { + const api = new ZoweExplorerZosmf.CommonApi(loadedProfile); + let session: imperative.Session; + const _getSessionSpy = jest.spyOn(api as any, "_getSession"); + expect(() => (session = api.getSession())).not.toThrow(); + expect(_getSessionSpy).toHaveBeenCalledTimes(1); + expect(session).not.toBeUndefined(); + }); + }); +}); + describe("ZosmfUssApi", () => { afterEach(() => { jest.clearAllMocks(); }); describe("_getSession", () => { - const exampleProfile = { - message: "", - type: "zosmf", - failNotFound: false, - name: "test.zosmf", - profile: { - host: "localhost", - password: "password", - protocol: "http", - user: "aZosmfUser", - ...fakeProperties, - }, - } as imperative.IProfileLoaded; - const exampleSession = imperative.Session.createFromUrl(new URL("http://localhost")); - exampleSession.ISession.password = exampleProfile.profile?.password; - exampleSession.ISession.user = exampleProfile.profile?.user; - jest.spyOn(ProfilesCache, "getProfileSessionWithVscProxy").mockReturnValueOnce(exampleSession as any); + const exampleSession = Object.assign(Object.create(Object.getPrototypeOf(fakeSession)), fakeSession); + exampleSession.ISession.password = loadedProfile.profile?.password; + exampleSession.ISession.user = loadedProfile.profile?.user; + jest.spyOn(ProfilesCache, "getProfileSessionWithVscProxy").mockReturnValueOnce(exampleSession); it("should include profile properties in the built session object", () => { const api = new ZoweExplorerZosmf.UssApi(loadedProfile); - const transformedProps: Record = { ...exampleProfile.profile, hostname: exampleProfile.profile?.host, ...fakeProperties }; + const transformedProps: Record = { ...loadedProfile.profile, hostname: loadedProfile.profile?.host, ...fakeProperties }; delete transformedProps["host"]; delete transformedProps["responseTimeout"]; - expect((api as any)._getSession(exampleProfile).mISession).toMatchObject(transformedProps); + expect((api as any)._getSession(loadedProfile).mISession).toMatchObject(transformedProps); }); }); diff --git a/packages/zowe-explorer-api/src/profiles/ZoweExplorerZosmfApi.ts b/packages/zowe-explorer-api/src/profiles/ZoweExplorerZosmfApi.ts index e71dbcecd4..2aa8285d74 100644 --- a/packages/zowe-explorer-api/src/profiles/ZoweExplorerZosmfApi.ts +++ b/packages/zowe-explorer-api/src/profiles/ZoweExplorerZosmfApi.ts @@ -29,7 +29,7 @@ export namespace ZoweExplorerZosmf { /** * An implementation of the Zowe Explorer API Common interface for zOSMF. */ - class CommonApi implements MainframeInteraction.ICommon { + export class CommonApi implements MainframeInteraction.ICommon { public static getProfileTypeName(): string { return zosmf.ZosmfProfile.type; } @@ -55,7 +55,7 @@ export namespace ZoweExplorerZosmf { // todo: initialize and use logging imperative.Logger.getAppLogger().error(error as string); } - return ProfilesCache.getProfileSessionWithVscProxy(this.session); + return this.session ? ProfilesCache.getProfileSessionWithVscProxy(this.session) : undefined; } private _getSession(serviceProfile: imperative.IProfileLoaded): imperative.Session { diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index cd8b280e4f..da692418ee 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen ### Bug fixes +- Fixed an issue where a TypeError occurred when applying VS Code proxy settings to an invalid session. [#3425](https://github.com/zowe/zowe-explorer-vscode/issues/3425) - Fixed issue where the 'Delete' key binding for the USS tree returns a 'contextValue' error. [#2796](https://github.com/zowe/zowe-explorer-vscode/issues/2796) ## `3.1.0`