Skip to content

Commit

Permalink
tests: resolve failing ProfilesUtils cases
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Dec 19, 2024
1 parent b9ea559 commit aefbbb4
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ describe("ProfilesUtils unit tests", () => {
const scenario = "Task failed successfully";
const showMessageSpy = jest.spyOn(Gui, "errorMessage").mockImplementation(() => Promise.resolve("Update Credentials"));
const promptCredsSpy = jest.fn();
const ssoLoginSpy = jest.fn();
const profile = { type: "zosmf" } as any;
Object.defineProperty(Constants, "PROFILES_CACHE", {
value: {
promptCredentials: promptCredsSpy,
ssoLogin: ssoLoginSpy,
getProfileInfo: profileInfoMock,
getLoadedProfConfig: () => profile,
getDefaultProfile: () => ({}),
Expand All @@ -168,6 +170,7 @@ describe("ProfilesUtils unit tests", () => {
await AuthUtils.errorHandling(errorDetails, { profile, scenario });
expect(showMessageSpy).toHaveBeenCalledTimes(1);
expect(promptCredsSpy).toHaveBeenCalledTimes(1);
expect(ssoLoginSpy).not.toHaveBeenCalled();
showMessageSpy.mockClear();
promptCredsSpy.mockClear();
});
Expand All @@ -181,6 +184,7 @@ describe("ProfilesUtils unit tests", () => {
const showErrorSpy = jest.spyOn(Gui, "errorMessage");
const showMessageSpy = jest.spyOn(Gui, "showMessage").mockImplementation(() => Promise.resolve("Log in to Authentication Service"));
const ssoLoginSpy = jest.fn();
const promptCredentialsSpy = jest.fn();
const profile = { type: "zosmf" } as any;
Object.defineProperty(Constants, "PROFILES_CACHE", {
value: {
Expand All @@ -189,13 +193,15 @@ describe("ProfilesUtils unit tests", () => {
getDefaultProfile: () => ({}),
getSecurePropsForProfile: () => ["tokenValue"],
ssoLogin: ssoLoginSpy,
promptCredentials: promptCredentialsSpy,
},
configurable: true,
});
await AuthUtils.errorHandling(errorDetails, { profile, scenario });
expect(showMessageSpy).toHaveBeenCalledTimes(1);
expect(ssoLoginSpy).toHaveBeenCalledTimes(1);
expect(showErrorSpy).not.toHaveBeenCalled();
expect(promptCredentialsSpy).not.toHaveBeenCalled();
showErrorSpy.mockClear();
showMessageSpy.mockClear();
ssoLoginSpy.mockClear();
Expand All @@ -216,10 +222,12 @@ describe("ProfilesUtils unit tests", () => {
const showErrorSpy = jest.spyOn(Gui, "errorMessage").mockResolvedValue(undefined);
const showMsgSpy = jest.spyOn(Gui, "showMessage");
const promptCredentialsSpy = jest.fn();
const ssoLogin = jest.fn();
const profile = { type: "zosmf" } as any;
Object.defineProperty(Constants, "PROFILES_CACHE", {
value: {
promptCredentials: promptCredentialsSpy,
ssoLogin,
getProfileInfo: profileInfoMock,
getLoadedProfConfig: () => profile,
getDefaultProfile: () => ({}),
Expand All @@ -230,6 +238,7 @@ describe("ProfilesUtils unit tests", () => {
await AuthUtils.errorHandling(errorDetails, { profile, scenario: moreInfo });
expect(showErrorSpy).toHaveBeenCalledTimes(1);
expect(promptCredentialsSpy).not.toHaveBeenCalled();
expect(ssoLogin).not.toHaveBeenCalled();
expect(showMsgSpy).not.toHaveBeenCalledWith("Operation Cancelled");
showErrorSpy.mockClear();
showMsgSpy.mockClear();
Expand Down Expand Up @@ -456,6 +465,7 @@ describe("ProfilesUtils unit tests", () => {
const updCredsMock = jest.spyOn(Constants.PROFILES_CACHE, "promptCredentials").mockResolvedValueOnce(["test", "test"]);
await ProfilesUtils.promptCredentials({
getProfile: () => testConfig,
setProfileToChoice: jest.fn(),
} as any);
expect(updCredsMock).toHaveBeenCalled();
expect(Gui.showMessage).toHaveBeenCalledWith("Credentials for testConfig were successfully updated");
Expand Down

0 comments on commit aefbbb4

Please sign in to comment.