Skip to content

Commit

Permalink
updates for code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Pujal <[email protected]>
  • Loading branch information
pujal0909 committed Dec 12, 2024
1 parent 8e1a828 commit a4972b1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe("Copy", () => {
});
isPDSSpy = jest.spyOn(Copy as any, "isPDS").mockResolvedValue(false);
});

afterAll(() => {
isPDSSpy.mockRestore();
});
describe("Success Scenarios", () => {
describe("Sequential > Sequential", () => {
it("should send a request", async () => {
Expand Down Expand Up @@ -451,8 +453,9 @@ describe("Copy", () => {
});
isPDSSpy = jest.spyOn(Copy as any, "isPDS").mockResolvedValue(true);
});
afterEach(() => {
afterAll(() => {
copyPDSSpy.mockRestore();
isPDSSpy.mockRestore();
});
it("should call copyPDS to copy members of source PDS to target PDS", async () => {
const response = await Copy.dataSet(
Expand Down Expand Up @@ -561,6 +564,42 @@ describe("Copy", () => {
const toDataSetName = "USER.DATA.TO";
const readStream = jest.spyOn(IO, "createReadStream");
const rmSync = jest.spyOn(fs, "rmSync");
const listDatasetSpy = jest.spyOn(List, "dataSet");

const dsPO = {
dsname: fromDataSetName,
dsorg: "PO",
};
const dsPS = {
dsname: fromDataSetName,
dsorg: "PS",
};

it("should detect PDS datasets correctly during copy", async () => {
listDatasetSpy.mockImplementation(async (): Promise<any> => {
return {
apiResponse: {
items: [dsPO]
}
};
});
const response = await Copy.isPDS(dummySession, dsPO.dsname);
expect(response).toEqual(true);
expect(listDatasetSpy).toHaveBeenCalledWith(dummySession, dsPO.dsname, { attributes: true });
});

it("should return false if the data set is not partitioned", async () => {
listDatasetSpy.mockImplementation(async (): Promise<any> => {
return {
apiResponse: {
items: [dsPS]
}
};
});
const response = await Copy.isPDS(dummySession, dsPS.dsname);
expect(response).toEqual(false);
expect(listDatasetSpy).toHaveBeenCalledWith(dummySession, dsPS.dsname, { attributes: true });
});

it("should successfully copy members from source to target PDS", async () => {
const sourceResponse = {
Expand Down
6 changes: 2 additions & 4 deletions packages/zosfiles/src/methods/copy/Copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ export class Copy {
/**
* Private function that checks if a dataset is type PDS
**/
private static async isPDS(
public static async isPDS(
session: AbstractSession,
dataSetName: string
): Promise<boolean> {
try {
const response = await List.dataSet(session, dataSetName, {attributes: true});
const dsntp = response.apiResponse.items[0].dsntp;
const dsorg = response.apiResponse.items[0].dsorg;
return dsntp === "PDS" && dsorg === "PO";
// return response;
return dsorg === "POE" || dsorg === "PO";
}
catch(error) {
Logger.getAppLogger().error(error);
Expand Down

0 comments on commit a4972b1

Please sign in to comment.