Skip to content

Commit

Permalink
add directConnectLogout and node.getSession unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Billie Simmons <[email protected]>
  • Loading branch information
JillieBeanSim committed Feb 17, 2025
1 parent 2cf6145 commit 57ce468
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -947,23 +947,34 @@ describe("ZoweVsCodeExtension", () => {
updateCachedProfile: jest.fn(),
});
vals.testNode = {
setProfileToChoice: jest.fn(),
getProfile: jest.fn().mockReturnValue(vals.serviceProfile),
getSession: jest.fn().mockReturnValue(new imperative.Session(JSON.parse(JSON.stringify(expectedSession.ISession)))),
} as any;
return vals;
}
beforeEach(() => {
blockMocks = createBlockMocks();
});
it("directConnectLogin should obtain a JWT and return true", async () => {
it("directConnectLogin should obtain a JWT and return true using profile to get session", async () => {
blockMocks.promptSpy.mockResolvedValue(["user", "pass"]);
const response = await (ZoweVsCodeExtension as any).directConnectLogin(blockMocks.serviceProfile, blockMocks.testRegister);
expect(response).toEqual(true);
expect(await (ZoweVsCodeExtension as any).directConnectLogin(blockMocks.serviceProfile, blockMocks.testRegister)).toEqual(true);
});
it("directConnectLogin should not obtain a JWT and return false due to no credentials entered", async () => {
it("directConnectLogin should obtain a JWT and return true using node to get session", async () => {
blockMocks.promptSpy.mockResolvedValue(["user", "pass"]);
expect(
await (ZoweVsCodeExtension as any).directConnectLogin(blockMocks.serviceProfile, blockMocks.testRegister, blockMocks.testNode)
).toEqual(true);
});
it("directConnectLogin should not obtain a JWT and return false due to no credentials entered using profile to get session", async () => {
blockMocks.promptSpy.mockResolvedValue(undefined);
const response = await (ZoweVsCodeExtension as any).directConnectLogin(blockMocks.serviceProfile, blockMocks.testRegister);
expect(response).toEqual(false);
expect(await (ZoweVsCodeExtension as any).directConnectLogin(blockMocks.serviceProfile, blockMocks.testRegister)).toEqual(false);
});
it("directConnectLogout should retire JWT and return true using profile to get session", async () => {
expect(await (ZoweVsCodeExtension as any).directConnectLogout(blockMocks.serviceProfile, blockMocks.testRegister)).toEqual(true);
});
it("directConnectLogout should retire JWT and return true using node to get session", async () => {
expect(
await (ZoweVsCodeExtension as any).directConnectLogout(blockMocks.serviceProfile, blockMocks.testRegister, blockMocks.testNode)
).toEqual(true);
});
});
});
9 changes: 8 additions & 1 deletion packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,14 @@ export class ZoweVsCodeExtension {
zeRegister: Types.IApiRegisterClient,
node?: Types.IZoweNodeType
): Promise<boolean> {
await zeRegister.getCommonApi(serviceProfile).logout(node.getSession());
const zeCommon = zeRegister.getCommonApi(serviceProfile);
let session: imperative.Session;
if (node) {
session = node.getSession();
} else {
session = zeCommon?.getSession();
}
await zeCommon.logout(session);
await ZoweVsCodeExtension.profilesCache.updateCachedProfile(serviceProfile, node);
return true;
}
Expand Down

0 comments on commit 57ce468

Please sign in to comment.