Skip to content

Commit

Permalink
wip(tests): resolve multiple failing tests
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 1216b03 commit b9ea559
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ async function createGlobalMocks() {
"zowe.copyExternalLink",
"zowe.revealOutputChannel",
"zowe.troubleshootError",
"zowe.getTreeProviders",
"zowe.placeholderCommand",
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe("readFile", () => {
it("throws an error if the entry does not have a profile", async () => {
const _lookupAsFileMock = jest
.spyOn(DatasetFSProvider.instance as any, "_lookupAsFile")
.mockReturnValueOnce({ ...testEntries.ps, metadata: { profile: null } });
.mockReturnValueOnce({ ...testEntries.ps, metadata: { profile: undefined } });

let err;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe("fetchSpoolAtUri", () => {
throw new Error("Failed to download spool");
}),
};
const promptForAuthErrorMock = jest.spyOn(AuthUtils, "promptForAuthError").mockImplementation();
const promptForAuthErrorMock = jest.spyOn(AuthUtils, "lockProfileOnAuthError").mockImplementation();
const jesApiMock = jest.spyOn(ZoweExplorerApiRegister, "getJesApi").mockReturnValueOnce(mockJesApi as any);
await expect(JobFSProvider.instance.fetchSpoolAtUri(testUris.spool)).rejects.toThrow();
expect(promptForAuthErrorMock).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import { Disposable, FilePermission, FileSystemError, FileType, TextEditor, Uri, workspace } from "vscode";
import { BaseProvider, DirEntry, FileEntry, Gui, UssDirectory, UssFile, ZoweExplorerApiType, ZoweScheme } from "@zowe/zowe-explorer-api";
import { AuthHandler, BaseProvider, DirEntry, FileEntry, Gui, UssDirectory, UssFile, ZoweExplorerApiType, ZoweScheme } from "@zowe/zowe-explorer-api";
import { Profiles } from "../../../../src/configuration/Profiles";
import { createIProfile } from "../../../__mocks__/mockCreators/shared";
import { ZoweExplorerApiRegister } from "../../../../src/extending/ZoweExplorerApiRegister";
Expand Down Expand Up @@ -466,6 +466,8 @@ describe("autoDetectEncoding", () => {
let mockUssApi;

beforeEach(() => {
jest.spyOn(AuthHandler, "lockProfile").mockImplementation();
jest.spyOn(AuthHandler, "unlockProfile").mockImplementation();
mockUssApi = jest.spyOn(ZoweExplorerApiRegister, "getUssApi").mockReturnValue({
getTag: getTagMock.mockClear(),
} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,49 @@
*
*/

import { ErrorCorrelator, Gui, imperative, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { AuthHandler, ErrorCorrelator, Gui, imperative, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { AuthUtils } from "../../../src/utils/AuthUtils";
import { Constants } from "../../../src/configuration/Constants";
import { MockedProperty } from "../../__mocks__/mockUtils";

describe("AuthUtils", () => {
describe("promptForAuthError", () => {
describe("lockProfileOnAuthError", () => {
it("should prompt for authentication", async () => {
const errorDetails = new imperative.ImperativeError({
errorCode: 401 as unknown as string,
msg: "All configured authentication methods failed",
});
const profile = { name: "aProfile", type: "zosmf" } as any;
const profilesCacheMock = new MockedProperty(Constants, "PROFILES_CACHE", {
value: {
ssoLogin: jest.fn().mockImplementation(),
promptCredentials: jest.fn().mockImplementation(),
} as any,
configurable: true,
});
const correlateErrorMock = jest.spyOn(ErrorCorrelator.getInstance(), "correlateError");
const correlatedError = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, errorDetails, {
const errorCorrelation = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, errorDetails, {
templateArgs: {
profileName: profile.name,
},
});
const promptForAuthenticationMock = jest
.spyOn(AuthUtils, "promptForAuthentication")
.mockImplementation(async () => Promise.resolve(true));
AuthUtils.promptForAuthError(errorDetails, profile);
const isUsingTokenAuthMock = jest.spyOn(AuthUtils, "isUsingTokenAuth").mockResolvedValueOnce(false);
const promptForAuthenticationMock = jest.spyOn(AuthHandler, "promptForAuthentication").mockResolvedValueOnce(true);
await AuthUtils.lockProfileOnAuthError(errorDetails, profile);
expect(correlateErrorMock).toHaveBeenCalledWith(ZoweExplorerApiType.All, errorDetails, {
templateArgs: {
profileName: profile.name,
},
});
expect(promptForAuthenticationMock).toHaveBeenCalledWith(errorDetails, profile, correlatedError);
expect(promptForAuthenticationMock).toHaveBeenCalledWith(
errorDetails,
profile,
expect.objectContaining({
errorCorrelation,
isUsingTokenAuth: false,
})
);
profilesCacheMock[Symbol.dispose]();
});
});
describe("promptForSsoLogin", () => {
Expand Down

0 comments on commit b9ea559

Please sign in to comment.