Skip to content

Commit

Permalink
fix all unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Mar 5, 2024
1 parent ba9b195 commit b187943
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe("Download all spool by job id handler", () => {
}
];
const jobDetails = {
jobid: "jobid1",
jobname: "job1",
jobId: "jobid1",
jobName: "job1",
spoolFiles
};

Expand Down
12 changes: 6 additions & 6 deletions __tests__/__unit__/cli/download/data-set/DataSet.Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe("Download data set handler", () => {
file: "invalid.txt☻"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
},
response: mockResponse
};
Expand All @@ -56,7 +56,7 @@ describe("Download data set handler", () => {
dataSet: "ds1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files))
}
};
try {
Expand All @@ -83,14 +83,14 @@ describe("Download data set handler", () => {
rdw: true,
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
},
response: mockResponse
};
await handler.processFTP(mockParams);
expect(mockResponse.console.log.mock.calls[0][0]).toBe(ZosFilesMessages.datasetDownloadedSuccessfully.message);
expect(mockResponse.console.log.mock.calls[0][1]).toBe("ds1");
expect(mockParams.connection.getDataset.mock.calls[0][1]).toBe("binary_rdw");
expect(mockParams.connection.downloadDataset.mock.calls[0][1]).toBe("binary_rdw");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe("Download uss file handler", () => {
ussFile: "ussFile1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getUssFile: jest.fn().mockReturnValue(Promise.resolve(""))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadFile: jest.fn().mockReturnValue(Promise.resolve(""))
}
};
try {
Expand All @@ -47,8 +47,8 @@ describe("Download uss file handler", () => {
ussFile: "ussFile1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadFile: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
},
response: mockResponse
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ However, the pattern cannot begin with any of these sequences.
"positionals": Array [
Object {
"description": "The z/OS JOBID of the job with the spool files you want to list. No pre-validation of the JOBID is performed.",
"name": "jobid",
"name": "jobId",
"required": true,
"type": "string",
},
Expand Down
4 changes: 2 additions & 2 deletions __tests__/__unit__/cli/list/data-set/DataSet.Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("List data set handler", () => {
pattern: "ds*"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("List data set handler", () => {
pattern: "ds*"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down
11 changes: 7 additions & 4 deletions __tests__/__unit__/cli/list/jobs/Jobs.Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
*
*/

import { Job } from "zos-node-accessor/lib/interfaces/Job";
import ListJobsHandler from "../../../../../src/cli/list/jobs/Jobs.Handler";
import TestUtils from "../../TestUtils";

describe("List jobs handler", () => {
beforeEach(() => {
jest.restoreAllMocks();
});

it("should return no job if the job is not found.", async () => {
const handler = new ListJobsHandler();
Expand All @@ -35,10 +39,9 @@ describe("List jobs handler", () => {

it("should return correct message if the job is found.", async () => {
const handler = new ListJobsHandler();
const jobs: any[] = [
"JOBNAME, JOBID, OWNER, STATUS, CLASS",
"JOBNAME1, JOBID1, OWNER1, STATUS1, CLASS1",
"JOBNAME2, JOBID2, OWNER2, STATUS2, CLASS2"
const jobs: Job[] = [
{ jobName: "JOBNAME1", jobId: "JOBID1", owner: "OWNER1", status: "STATUS1", class: "CLASS1" },
{ jobName: "JOBNAME2", jobId: "JOBID2", owner: "OWNER2", status: "STATUS2", class: "CLASS2" },
];

const mockResponse = TestUtils.getMockResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ describe("List spool files by job id handler", () => {
const handler = new ListSpoolFilesByJobidHandler();
const files: any[] = [];
const jobDetails = {
jobname: "jobname1",
jobid: "jobid1",
jobName: "jobName1",
jobId: "jobId1",
spoolFiles: files
};

const mockResponse = TestUtils.getMockResponse();
const mockParams: any = {
arguments: {
jobid: "jobid1"
jobId: "jobId1"
},
connection: {
getJobStatus: jest.fn().mockReturnValue(Promise.resolve(jobDetails))
},
response: mockResponse
};
await handler.processFTP(mockParams);
expect(mockResponse.data.setMessage.mock.calls[0][0]).toBe("\"0\" spool files obtained for job \"jobname1(jobid1)\"");
expect(mockResponse.data.setMessage.mock.calls[0][0]).toBe("\"0\" spool files obtained for job \"jobName1(jobId1)\"");
expect(mockResponse.data.setObj.mock.calls[0][0]).toMatchSnapshot();
expect(mockResponse.format.output.mock.calls[0][0]).toMatchSnapshot();
});

it("should return correct message if at least one spool file is found.", async () => {
const handler = new ListSpoolFilesByJobidHandler();
const jobDetails = {
jobname: "jobname1",
jobid: "jobid1",
jobName: "jobName1",
jobId: "jobId1",
spoolFiles: [
{
name: "file1"
Expand All @@ -57,15 +57,15 @@ describe("List spool files by job id handler", () => {
const mockResponse = TestUtils.getMockResponse();
const mockParams: any = {
arguments: {
jobid: "jobid1"
jobId: "jobId1"
},
connection: {
getJobStatus: jest.fn().mockReturnValue(Promise.resolve(jobDetails))
},
response: mockResponse
};
await handler.processFTP(mockParams);
expect(mockResponse.data.setMessage.mock.calls[0][0]).toBe("\"2\" spool files obtained for job \"jobname1(jobid1)\"");
expect(mockResponse.data.setMessage.mock.calls[0][0]).toBe("\"2\" spool files obtained for job \"jobName1(jobId1)\"");
expect(mockResponse.format.output.mock.calls[0][0]).toMatchSnapshot();
expect(mockResponse.data.setObj.mock.calls[0][0]).toMatchSnapshot();
expect(mockResponse.format.output.mock.calls[0][0]).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("List uss files handler", () => {
directory: "/u/user"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down Expand Up @@ -52,7 +52,7 @@ describe("List uss files handler", () => {
directory: "/u/user"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand All @@ -78,7 +78,7 @@ describe("List uss files handler", () => {
directory: "/u/user/ds*"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Rename data set handler", () => {
newDataSet: "newname"
},
connection: {
rename: jest.fn().mockReturnValue(Promise.resolve(files))
renameDataset: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Rename uss files handler", () => {
newuss: "newname"
},
connection: {
rename: jest.fn().mockReturnValue(Promise.resolve(files))
renameFile: jest.fn().mockReturnValue(Promise.resolve(files))
},
response: mockResponse
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe("Submit data set handler", () => {
dataSet: "ds1"
},
connection: {
getDataset: jest.fn().mockReturnValue(Promise.resolve(getStream())),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(getStream())),
submitJCL: jest.fn().mockReturnValue(Promise.resolve("jobid1")),
getJobStatus: jest.fn().mockReturnValue(Promise.resolve(jobDetails)),
listDataset: jest.fn().mockReturnValue(Promise.resolve([''])),
listDatasets: jest.fn().mockReturnValue(Promise.resolve([''])),
},
response: mockResponse
};
Expand Down Expand Up @@ -66,11 +66,11 @@ describe("Submit data set handler", () => {
wait: "5,10"
},
connection: {
getDataset: jest.fn().mockReturnValue(Promise.resolve(getStream())),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(getStream())),
submitJCL: jest.fn().mockReturnValue(Promise.resolve("jobid2")),
getJobStatus: jest.fn().mockReturnValueOnce(Promise.resolve(jobRuning)).mockReturnValueOnce(Promise.resolve(jobRuning))
.mockReturnValue(Promise.resolve(jobDetails)),
listDataset: jest.fn().mockReturnValue(Promise.resolve([''])),
listDatasets: jest.fn().mockReturnValue(Promise.resolve([''])),
},
response: mockResponse
};
Expand Down
8 changes: 4 additions & 4 deletions __tests__/__unit__/cli/view/data-set/DataSet.Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe("View data set handler", () => {
dataSet: "ds1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(""))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(""))
}
};
try {
Expand All @@ -46,8 +46,8 @@ describe("View data set handler", () => {
dataSet: "ds1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
listDatasets: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
},
response: mockResponse
};
Expand Down
8 changes: 4 additions & 4 deletions __tests__/__unit__/cli/view/uss-file/UssFile.Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe("View uss file handler", () => {
ussFile: "ussFile1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getUssFile: jest.fn().mockReturnValue(Promise.resolve(""))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadFile: jest.fn().mockReturnValue(Promise.resolve(""))
}
};
try {
Expand All @@ -47,8 +47,8 @@ describe("View uss file handler", () => {
ussFile: "ussFile1"
},
connection: {
listDataset: jest.fn().mockReturnValue(Promise.resolve(files)),
getDataset: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
listFiles: jest.fn().mockReturnValue(Promise.resolve(files)),
downloadFile: jest.fn().mockReturnValue(Promise.resolve(TestUtils.getSingleLineStream()))
},
response: mockResponse
};
Expand Down
7 changes: 4 additions & 3 deletions src/api/CoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { ICommandProfileTypeConfiguration, IImperativeError, Logger } from "@zowe/imperative";
import * as stream from "stream";
import { IDatasetEntry } from "./doc/DataSetInterface";
import { ITransferMode } from "./doc";
import { ITransferMode, IUSSEntry } from "./doc";

export class CoreUtils {

Expand Down Expand Up @@ -71,7 +71,8 @@ export class CoreUtils {
});
}

public static addLowerCaseKeysToObject(obj: IDatasetEntry): IDatasetEntry {
public static addLowerCaseKeysToObject(obj: IDatasetEntry | IUSSEntry): IDatasetEntry | IUSSEntry {

const result: { [key: string]: string } = {};
for (const key of Object.keys(obj)) {
// turn the object into a similar format to that returned by
Expand All @@ -80,7 +81,7 @@ export class CoreUtils {
this.log.trace("Remapping key for data set to match core CLI. Old key '%s' New key '%s'", key, key.toLowerCase());
result[key.toLowerCase()] = obj[key];
}
return result as IDatasetEntry;
return result as typeof obj;
}

public static async getProfileMeta(): Promise<ICommandProfileTypeConfiguration[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/api/DataSetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DataSetUtils {

this.log.debug("Found %d matching data sets", files.length);
const filteredFiles = files.map((file: IDatasetEntry) => CoreUtils.addLowerCaseKeysToObject(file));
return filteredFiles;
return filteredFiles as IDatasetEntry[];
}

/**
Expand All @@ -52,7 +52,7 @@ export class DataSetUtils {
this.log.debug("Found %d members", members.length);
const filteredMembers = members.map((file: IDatasetEntry) => CoreUtils.addLowerCaseKeysToObject(file));

return filteredMembers;
return filteredMembers as IDatasetEntry[];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/FTPConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ export class FTPConfig {
* @returns true if the user has specified any secure connection options
*/
private static profileHasSecureOptions(args: Partial<ICommandArguments>): boolean {
return (args.rejectUnauthorized != null) || (args.serverName !== null);
return (args.rejectUnauthorized != null) || (args.serverName != null);
}
}
2 changes: 1 addition & 1 deletion src/api/JobUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class JobUtils {
* @returns spool files with content
*/
public static async getSpoolFiles(connection: ZosAccessor, jobId: string): Promise<ISpoolFile[]> {
const jobDetails = (await JobUtils.findJobByID(connection, jobId));
const jobDetails = await JobUtils.findJobByID(connection, jobId);
const fullSpoolFiles: ISpoolFile[] = [];
for (const spoolFileToDownload of jobDetails.spoolFiles) {
this.log.debug("Requesting spool files for job %s(%s) spool file ID %d", jobDetails.jobName, jobDetails.jobId, spoolFileToDownload.id);
Expand Down
Loading

0 comments on commit b187943

Please sign in to comment.