Skip to content

Commit

Permalink
tests: Resolve failing test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
  • Loading branch information
traeok committed Oct 14, 2024
1 parent 01f5ae5 commit 27a21db
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion packages/zowe-explorer-api/src/utils/ErrorCorrelator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ErrorCorrelator extends Singleton {
}

for (const apiError of [
...this.errorMatches.get(profileType)[api],
...(this.errorMatches.get(profileType)?.[api] ?? []),
...(api === ZoweExplorerApiType.All ? [] : this.errorMatches.get(profileType)[ZoweExplorerApiType.All] ?? []),
]) {
for (const match of Array.isArray(apiError.matches) ? apiError.matches : [apiError.matches]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe("mvsCommandActions unit testing", () => {
});
expect(showInputBox.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls[0][0]).toEqual("Error: fake testError");
expect(showErrorMessage.mock.calls[0][0]).toEqual("fake testError");
});

it("tests the issueMvsCommand function user escapes the quick pick box", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe("TsoCommandHandler unit testing", () => {
});
expect(showInputBox.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls[0][0]).toEqual("Error: fake testError");
expect(showErrorMessage.mock.calls[0][0]).toEqual("fake testError");
});

it("tests the issueTsoCommand function user escapes the quick pick box", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ describe("UnixCommand Actions Unit Testing", () => {
});
expect(showInputBox.mock.calls.length).toBe(2);
expect(showErrorMessage.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls[0][0]).toEqual("Error: fake testError");
expect(showErrorMessage.mock.calls[0][0]).toEqual("fake testError");
});

it("If nothing is entered in the inputbox of path", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as vscode from "vscode";
import { ProfilesCache, ZoweTreeNode } from "@zowe/zowe-explorer-api";
import { ProfilesCache, ZoweExplorerApiType, ZoweTreeNode } from "@zowe/zowe-explorer-api";
import { createIProfile, createISession } from "../../__mocks__/mockCreators/shared";
import { ZoweCommandProvider } from "../../../src/commands/ZoweCommandProvider";
import { Profiles } from "../../../src/configuration/Profiles";
Expand Down Expand Up @@ -85,7 +85,8 @@ describe("ZoweCommandProvider Unit Tests - function checkCurrentProfile", () =>
expect(errorHandlingSpy).toHaveBeenCalledWith(
"Profile Name " +
globalMocks.testProfile.name +
" is inactive. Please check if your Zowe server is active or if the URL and port in your profile is correct."
" is inactive. Please check if your Zowe server is active or if the URL and port in your profile is correct.",
{ apiType: ZoweExplorerApiType.Command, profile: globalMocks.testProfile }
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,14 @@ describe("Profiles Unit Tests - function validateProfile", () => {
throw testError;
});
const errorHandlingSpy = jest.spyOn(AuthUtils, "errorHandling");
await Profiles.getInstance().validateProfiles({
const profile = {
name: "test1",
message: "",
type: "",
failNotFound: false,
});
expect(errorHandlingSpy).toHaveBeenCalledWith(testError, "test1");
};
await Profiles.getInstance().validateProfiles(profile);
expect(errorHandlingSpy).toHaveBeenCalledWith(testError, { profile });
});
it("should return an object with profile validation status of 'unverified' from session status if validated profiles doesn't exist", async () => {
createBlockMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SharedActions } from "../../../../src/trees/shared/SharedActions";
import { Profiles } from "../../../../src/configuration/Profiles";
import { ZoweDatasetNode } from "../../../../src/trees/dataset/ZoweDatasetNode";
import { AuthUtils } from "../../../../src/utils/AuthUtils";
import { ZoweExplorerApiType } from "@zowe/zowe-explorer-api";

async function createGlobalMocks() {
const newMocks = {
Expand Down Expand Up @@ -241,8 +242,7 @@ describe("mvsNodeActions", () => {
jest.spyOn(mockMvsApi2, "putContents").mockRejectedValue(testError);
const errHandlerSpy = jest.spyOn(AuthUtils, "errorHandling").mockImplementation();
await DatasetActions.uploadDialog(node, testTree);

expect(errHandlerSpy).toHaveBeenCalledWith(testError, "sestest");
expect(errHandlerSpy).toHaveBeenCalledWith(testError, { apiType: ZoweExplorerApiType.Mvs, profile: globalMocks.profileOne });
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as vscode from "vscode";
import * as zosfiles from "@zowe/zos-files-for-zowe-sdk";
import { Gui, imperative, Validation, Types } from "@zowe/zowe-explorer-api";
import { Gui, imperative, Validation, Types, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { DatasetFSProvider } from "../../../../src/trees/dataset/DatasetFSProvider";
import { bindMvsApi, createMvsApi } from "../../../__mocks__/mockCreators/api";
import {
Expand Down Expand Up @@ -206,15 +206,15 @@ describe("Dataset Actions Unit Tests - Function createMember", () => {
});

mocked(vscode.window.showInputBox).mockResolvedValue("testMember");
mocked(zosfiles.Upload.bufferToDataSet).mockRejectedValueOnce(Error("test"));
mocked(zosfiles.Upload.bufferToDataSet).mockRejectedValueOnce(Error("Error when uploading to data set"));

try {
await DatasetActions.createMember(parent, blockMocks.testDatasetTree);
} catch (err) {
// Prevent exception from failing test
}

expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Unable to create member. Error: test");
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Error when uploading to data set", { items: ["More info"] });
mocked(zosfiles.Upload.bufferToDataSet).mockReset();
});
it("Checking of attempt to create member without name", async () => {
Expand Down Expand Up @@ -769,9 +769,9 @@ describe("Dataset Actions Unit Tests - Function deleteDataset", () => {
});

mocked(vscode.window.showQuickPick).mockResolvedValueOnce("Delete" as any);
jest.spyOn(DatasetFSProvider.instance, "delete").mockRejectedValueOnce(Error(""));
jest.spyOn(DatasetFSProvider.instance, "delete").mockRejectedValueOnce(Error("Deletion error"));
await expect(DatasetActions.deleteDataset(node, blockMocks.testDatasetTree)).rejects.toThrow("");
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Error");
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Deletion error", { items: ["More info"] });
});
it("Checking Favorite PDS dataset deletion", async () => {
createGlobalMocks();
Expand Down Expand Up @@ -1123,9 +1123,9 @@ describe("Dataset Actions Unit Tests - Function showAttributes", () => {
await expect(DatasetActions.showAttributes(node, blockMocks.testDatasetTree)).rejects.toEqual(
Error("No matching names found for query: AUSER.A1557332.A996850.TEST1")
);
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith(
"Unable to list attributes. Error: No matching names found for query: AUSER.A1557332.A996850.TEST1"
);
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("No matching names found for query: AUSER.A1557332.A996850.TEST1", {
items: ["More info"],
});
expect(mocked(vscode.window.createWebviewPanel)).not.toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -2395,7 +2395,7 @@ describe("Dataset Actions Unit Tests - Function createFile", () => {
// do nothing
}

expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Error encountered when creating data set. Error: Generic Error");
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Generic Error", { items: ["More info"] });
expect(mocked(vscode.workspace.getConfiguration)).toHaveBeenLastCalledWith(Constants.SETTINGS_DS_DEFAULT_PS);
expect(createDataSetSpy).toHaveBeenCalledWith(zosfiles.CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, "TEST", {
alcunit: "CYL",
Expand Down Expand Up @@ -2897,7 +2897,10 @@ describe("Dataset Actions Unit Tests - Function allocateLike", () => {
}

expect(errorHandlingSpy).toHaveBeenCalledTimes(1);
expect(errorHandlingSpy).toHaveBeenCalledWith(errorMessage, "test", "Unable to create data set.");
expect(errorHandlingSpy).toHaveBeenCalledWith(
errorMessage,
expect.objectContaining({ apiType: ZoweExplorerApiType.Mvs, scenario: "Unable to create data set." })
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe("ZoweDatasetNode Unit Tests - Function node.openDs()", () => {
// do nothing
}

expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("Error: testError");
expect(mocked(Gui.errorMessage)).toHaveBeenCalledWith("testError", { items: ["More info"] });
});

it("Checking of opening for PDS Member", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { JobActions } from "../../../../src/trees/job/JobActions";
import { DatasetActions } from "../../../../src/trees/dataset/DatasetActions";
import { Definitions } from "../../../../src/configuration/Definitions";
import { SpoolUtils } from "../../../../src/utils/SpoolUtils";
import { AuthUtils } from "../../../../src/utils/AuthUtils";

const activeTextEditorDocument = jest.fn();

Expand Down Expand Up @@ -415,8 +416,14 @@ describe("Jobs Actions Unit Tests - Function downloadJcl", () => {
});
it("Checking failed attempt to download Job JCL", async () => {
createGlobalMocks();
await JobActions.downloadJcl(undefined as any);
expect(mocked(Gui.errorMessage)).toHaveBeenCalled();
const showTextDocumentMock = jest.spyOn(vscode.workspace, "openTextDocument").mockImplementationOnce(() => {
throw new Error();
});
const errorHandlingMock = jest.spyOn(AuthUtils, "errorHandling").mockImplementation();
await JobActions.downloadJcl({ getProfile: jest.fn(), job: createIJobObject() } as any);
expect(showTextDocumentMock).toHaveBeenCalled();
expect(errorHandlingMock).toHaveBeenCalled();
errorHandlingMock.mockRestore();
});
});

Expand Down Expand Up @@ -1043,6 +1050,7 @@ describe("focusing on a job in the tree view", () => {
const existingJobSession = createJobSessionNode(session, profile);
const datasetSessionName = existingJobSession.label as string;
const jobTree = createTreeView();
const errorHandlingMock = jest.spyOn(AuthUtils, "errorHandling").mockImplementation();
const jobTreeProvider = createJobsTree(session, submittedJob, profile, jobTree);
jobTreeProvider.mSessionNodes.push(existingJobSession);
const testError = new Error("focusOnJob failed");
Expand All @@ -1053,8 +1061,7 @@ describe("focusing on a job in the tree view", () => {
await JobActions.focusOnJob(jobTreeProvider, datasetSessionName, submittedJob.jobid);
// assert
expect(mocked(jobTreeProvider.refreshElement)).toHaveBeenCalledWith(existingJobSession);
expect(mocked(Gui.errorMessage)).toHaveBeenCalled();
expect(mocked(Gui.errorMessage).mock.calls[0][0]).toContain(testError.message);
expect(errorHandlingMock).toHaveBeenCalled();
});
it("should handle error adding a new tree view session", async () => {
// arrange
Expand All @@ -1064,15 +1071,15 @@ describe("focusing on a job in the tree view", () => {
const newJobSession = createJobSessionNode(session, profile);
const datasetSessionName = newJobSession.label as string;
const jobTree = createTreeView();
const errorHandlingMock = jest.spyOn(AuthUtils, "errorHandling").mockImplementation();
const jobTreeProvider = createJobsTree(session, submittedJob, profile, jobTree);
const testError = new Error("focusOnJob failed");
jest.spyOn(jobTreeProvider, "addSession").mockRejectedValueOnce(testError);
// act
await JobActions.focusOnJob(jobTreeProvider, datasetSessionName, submittedJob.jobid);
// assert
expect(mocked(jobTreeProvider.addSession)).toHaveBeenCalledWith({ sessionName: datasetSessionName });
expect(mocked(Gui.errorMessage)).toHaveBeenCalled();
expect(mocked(Gui.errorMessage).mock.calls[0][0]).toContain(testError.message);
expect(errorHandlingMock).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,7 @@ describe("ZoweUSSNode Unit Tests - Function node.getChildren()", () => {

await blockMocks.childNode.getChildren();
expect(globalMocks.showErrorMessage.mock.calls.length).toEqual(1);
expect(globalMocks.showErrorMessage.mock.calls[0][0]).toEqual(
"Retrieving response from USS list API Error: Throwing an error to check error handling for unit tests!"
);
expect(globalMocks.showErrorMessage.mock.calls[0][0]).toEqual("Throwing an error to check error handling for unit tests!");
});

it("Tests that when passing a session node that is not dirty the node.getChildren() method is exited early", async () => {
Expand Down
Loading

0 comments on commit 27a21db

Please sign in to comment.