Skip to content

Commit

Permalink
fix broken 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 14, 2025
1 parent 17cfe1c commit 908360a
Showing 1 changed file with 1 addition and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
getTokenTypeName: () => imperative.SessConstants.TOKEN_TYPE_APIML,
login: () => "ajshdlfkjshdalfjhas",
} as never);
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
jest.spyOn(Profiles.getInstance() as any, "updateBaseProfileFileLogin").mockImplementation();
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
});
Expand All @@ -1239,7 +1238,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
login: () => "ajshdlfkjshdalfjhas",
getSession: () => globalMocks.testSession,
} as never);
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
});
it("should catch error getting token type and log warning", async () => {
Expand All @@ -1258,7 +1256,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
login: jest.fn(),
} as never);
const loginBaseProfMock = jest.spyOn(ZoweVsCodeExtension, "ssoLogin").mockRejectedValueOnce(new Error("test error."));
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
expect(ZoweLogger.error).toHaveBeenCalled();
loginBaseProfMock.mockRestore();
Expand All @@ -1271,7 +1268,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
const profileUpdatedEmitterSpy = jest.spyOn(ZoweVsCodeExtension.onProfileUpdatedEmitter, "fire");
const unlockProfileSpy = jest.spyOn(AuthHandler, "unlockProfile");
const loginBaseProfMock = jest.spyOn(ZoweVsCodeExtension, "ssoLogin").mockResolvedValueOnce(true);
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
expect(profileUpdatedEmitterSpy).toHaveBeenCalledTimes(1);
expect(profileUpdatedEmitterSpy).toHaveBeenCalledWith(globalMocks.testProfile);
Expand Down Expand Up @@ -1504,7 +1500,7 @@ describe("Profiles Unit Tests - function handleSwitchAuthentication", () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValue({
getTokenTypeName: () => "jwtToken",
} as never);
jest.spyOn(Profiles.getInstance() as any, "loginWithRegularProfile").mockResolvedValue(true);
jest.spyOn(ZoweVsCodeExtension as any, "directConnectLogin").mockResolvedValue(true);
await Profiles.getInstance().handleSwitchAuthentication(testNode);
expect(Gui.showMessage).toHaveBeenCalled();
expect(testNode.profile.profile.tokenType).toBe(modifiedTestNode.profile.profile.tokenType);
Expand Down Expand Up @@ -1562,7 +1558,6 @@ describe("Profiles Unit Tests - function handleSwitchAuthentication", () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValue({
getTokenTypeName: () => "jwtToken",
} as never);
jest.spyOn(Profiles.getInstance() as any, "loginWithRegularProfile").mockResolvedValue(false);
await Profiles.getInstance().handleSwitchAuthentication(testNode);
expect(Gui.errorMessage).toHaveBeenCalled();
expect(testNode.profile.profile.tokenType).toBe(modifiedTestNode.profile.profile.tokenType);
Expand Down Expand Up @@ -1977,36 +1972,6 @@ describe("Profiles Unit Tests - function validationArraySetup", () => {
});
});

describe("Profiles Unit Tests - function loginCredentialPrompt", () => {
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});

it("should show a gui message if there is not a newUser", async () => {
const privateProfile = Profiles.getInstance() as any;
Object.defineProperty(privateProfile, "userInfo", {
value: () => null,
});
const showMessageSpy = jest.spyOn(Gui, "showMessage").mockImplementation();
await expect(privateProfile.loginCredentialPrompt()).resolves.toEqual(undefined);
expect(showMessageSpy).toHaveBeenCalledTimes(1);
});

it("should show a gui message if there is not a newUser", async () => {
const privateProfile = Profiles.getInstance() as any;
Object.defineProperty(Profiles, "getInstance", {
value: () => ({
userInfo: () => "test",
passwordInfo: () => null,
}),
});
const showMessageSpy = jest.spyOn(Gui, "showMessage").mockImplementation();
await expect(privateProfile.loginCredentialPrompt()).resolves.toEqual(undefined);
expect(showMessageSpy).toHaveBeenCalledTimes(1);
});
});

describe("Profiles Unit Tests - function getSecurePropsForProfile", () => {
afterEach(() => {
jest.clearAllMocks();
Expand Down

0 comments on commit 908360a

Please sign in to comment.