Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
Signed-off-by: likhithanimma1 <[email protected]>
  • Loading branch information
likhithanimma1 committed Jan 10, 2025
1 parent 00e21da commit 8eb8f21
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ describe("ZosmfMvsApi", () => {
await zosmfApi.uploadFromBuffer(buf, "SOME.DS(MEMB)");
expect(uploadFileSpy).toHaveBeenCalledWith(zosmfApi.getSession(), buf, "SOME.DS(MEMB)", fakeProperties);
});

it("Test copyDataSetCrossLpar()", async () => {
const copySpy = jest.spyOn(zosfiles.Copy, "dataSetCrossLPAR").mockImplementation();
const zosmfApi = new ZoweExplorerZosmf.MvsApi(loadedProfile);
await zosmfApi.copyDataSetCrossLpar("TO.NAME", "TO.MEMBER", undefined as any, loadedProfile);
expect(copySpy).toHaveBeenCalled();
});
});

describe("ZosmfJesApi", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,35 @@ describe("Dataset Actions Unit Tests - Function pasteDataSet", () => {
await expect(DatasetActions.pasteDataSet(blockMocks.testDatasetTree, node)).resolves.not.toThrow();
});

it("If copyDataSet() is not present in mvsapi", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
const node = new ZoweDatasetNode({
label: "HLQ.TEST.DATASET",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
node.contextValue = Constants.DS_DS_CONTEXT;
clipboard.writeText(
JSON.stringify([
{
dataSetName: "HLQ.TEST.BEFORE.NODE",
profileName: blockMocks.imperativeProfile.name,
contextValue: Constants.DS_DS_CONTEXT,
},
])
);
mocked(vscode.window.showInputBox).mockImplementationOnce((options) => {
options.validateInput("nodeCopyCpy");
return Promise.resolve("nodeCopyCpy");
});

blockMocks.mvsApi.copyDataSet = null as any;
const errorSpy = jest.spyOn(Gui, "errorMessage").mockResolvedValue("Copying data sets is not supported.");
await expect(DatasetActions.pasteDataSet(blockMocks.testDatasetTree, node)).resolves.not.toThrow();
expect(errorSpy).toHaveBeenCalled();
});

it("Testing copySequentialDatasets() successfully runs cross profile", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocks();
Expand Down Expand Up @@ -1655,6 +1684,48 @@ describe("Dataset Actions Unit Tests - Function pasteDataSet", () => {
await expect(DatasetActions.pasteDataSet(blockMocks.testDatasetTree, node)).resolves.not.toThrow();
expect(errSpy).toHaveBeenCalled();
});

it("Testing refreshDataset() error handling", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
const testError = new Error("refreshDataset failed");
const refreshSpy = jest.spyOn(blockMocks.pdsSessionNode, "getChildren").mockRejectedValueOnce(testError);
await DatasetActions.refreshDataset(blockMocks.pdsSessionNode, blockMocks.testDatasetTree);
expect(refreshSpy).toHaveBeenCalled();
expect(mocked(Gui.errorMessage)).toHaveBeenCalled();
expect(mocked(Gui.errorMessage).mock.calls[0][0]).toContain(testError.message);
});

it("Testing refreshDataset() running successfully", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
const refreshSpy = jest.spyOn(blockMocks.pdsSessionNode, "getChildren").mockResolvedValueOnce(blockMocks.pdsMemberNode as any);
await DatasetActions.refreshDataset(blockMocks.pdsSessionNode, blockMocks.testDatasetTree);
expect(refreshSpy).toHaveBeenCalled();
});

it("If copyDataSetCrossLpar is not present in mvsapi", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
const node = new ZoweDatasetNode({
label: "HLQ.TEST.DATASET",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
clipboard.writeText(
JSON.stringify([
{
dataSetName: "HLQ.TEST.BEFORE.NODE",
profileName: "sestest1",
contextValue: Constants.DS_DS_CONTEXT,
},
])
);
blockMocks.mvsApi.copyDataSetCrossLpar = null as any;
const errorSpy = jest.spyOn(Gui, "errorMessage").mockResolvedValue("Not supported");
await expect(DatasetActions.pasteDataSet(blockMocks.testDatasetTree, node)).resolves.not.toThrow();
expect(errorSpy).toHaveBeenCalled();
});
});

describe("Dataset Actions Unit Tests - Function hMigrateDataSet", () => {
Expand Down
17 changes: 14 additions & 3 deletions packages/zowe-explorer/src/trees/dataset/DatasetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,10 +1465,11 @@ export class DatasetActions {
}

/**
* Paste members
* Paste Datasets
*
* @export
* @param datasetProvider - the tree which contains the nodes
* @param node - the node to which content is pasted
*/
public static async pasteDataSet(datasetProvider: Types.IZoweDatasetTreeType, node: ZoweDatasetNode): Promise<void> {
ZoweLogger.trace("dataset.actions.pasteDataSetMembers called.");
Expand Down Expand Up @@ -1496,7 +1497,8 @@ export class DatasetActions {
* copies given sequential dataset nodes
*
* @export
* @param {ZoweDatasetNode[]} nodes - nodes to be copied
* @param {ZoweDatasetNode} node - The node to which content is pasted
* @param clipboardContent - Copied clipboard content
*/
public static async copySequentialDatasets(clipboardContent, node: ZoweDatasetNode): Promise<void> {
ZoweLogger.trace("dataset.actions.copySequentialDatasets called.");
Expand Down Expand Up @@ -1569,6 +1571,14 @@ export class DatasetActions {
return;
}

/**
* copies given dataset members
*
* @export
* @param {ZoweDatasetNode} node - The node to which content is pasted
* @param clipboardContent - Copied clipboard content
*/

public static async copyDatasetMembers(clipboardContent, node: ZoweDatasetNode): Promise<void> {
ZoweLogger.trace("dataset.actions.copyDatasetMembers called.");
const mvsApi = ZoweExplorerApiRegister.getMvsApi(node.getProfile());
Expand Down Expand Up @@ -1637,7 +1647,8 @@ export class DatasetActions {
* copies given partitioned dataset nodes
*
* @export
* @param {ZoweDatasetNode[]} nodes - nodes to be copied
* @param {ZoweDatasetNode} node - The node to which content is pasted
* @param clipboardContent - Copied clipboard content
*/
public static async copyPartitionedDatasets(clipboardContent, node: ZoweDatasetNode): Promise<void> {
ZoweLogger.trace("dataset.actions.copyPartitionedDatasets called.");
Expand Down

0 comments on commit 8eb8f21

Please sign in to comment.