Skip to content

Commit

Permalink
add checking files length as well and update unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Tian Na <[email protected]>
  • Loading branch information
tiantn committed Jun 4, 2024
1 parent a2fcbc7 commit 7827720
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TestUtils from "../../TestUtils";

describe("List spool files by job id handler", () => {

// eslint-disable-next-line jest/no-focused-tests
it("should return no spool file if the no spool file is not found.", async () => {
const handler = new ListSpoolFilesByJobidHandler();
const files: any[] = [];
Expand All @@ -34,9 +35,7 @@ describe("List spool files by job id handler", () => {
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.setObj.mock.calls[0][0]).toMatchSnapshot();
expect(mockResponse.format.output.mock.calls[0][0]).toMatchSnapshot();
expect(mockResponse.console.log.mock.calls[0]).toContain("No spool file.");
});

it("should return correct message if at least one spool file is found.", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,3 @@ Object {
],
}
`;

exports[`List spool files by job id handler should return no spool file if the no spool file is not found. 1`] = `Array []`;

exports[`List spool files by job id handler should return no spool file if the no spool file is not found. 2`] = `
Object {
"fields": Array [
"id",
"ddName",
"procStep",
"stepName",
],
"format": "table",
"output": Array [],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class ListSpoolFilesByJobidHandler extends FTPBaseHandler {
this.log.debug("Listing spool files for job ID %s", params.arguments.jobId);
const job = await JobUtils.findJobByID(params.connection, params.arguments.jobId);
const files = job.spoolFiles;
if (files) {
if (files?.length > 0) {
const successMessage = this.log.info(`"${files.length}" spool files obtained for job "${job.jobName}(${job.jobId})"`);
// Set the object, message, and log the prettified object
params.response.data.setObj(files);
Expand Down

0 comments on commit 7827720

Please sign in to comment.