From 7827720e43f3850c15373b5dd56b83ef1738dd12 Mon Sep 17 00:00:00 2001 From: Tian Na Date: Tue, 4 Jun 2024 15:44:22 +0800 Subject: [PATCH] add checking files length as well and update unit test Signed-off-by: Tian Na --- .../SpoolFilesByJobid.Handler.test.ts | 5 ++--- .../SpoolFilesByJobid.Handler.test.ts.snap | 15 --------------- .../SpoolFilesByJobid.Handler.ts | 2 +- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/__tests__/__unit__/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.test.ts b/__tests__/__unit__/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.test.ts index 963e3acd..5c9ac4f4 100644 --- a/__tests__/__unit__/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.test.ts +++ b/__tests__/__unit__/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.test.ts @@ -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[] = []; @@ -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 () => { diff --git a/__tests__/__unit__/cli/list/spool-files-by-jobid/__snapshots__/SpoolFilesByJobid.Handler.test.ts.snap b/__tests__/__unit__/cli/list/spool-files-by-jobid/__snapshots__/SpoolFilesByJobid.Handler.test.ts.snap index 52bf413c..110b347f 100644 --- a/__tests__/__unit__/cli/list/spool-files-by-jobid/__snapshots__/SpoolFilesByJobid.Handler.test.ts.snap +++ b/__tests__/__unit__/cli/list/spool-files-by-jobid/__snapshots__/SpoolFilesByJobid.Handler.test.ts.snap @@ -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 [], -} -`; diff --git a/src/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.ts b/src/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.ts index bf7cd339..eacb18d9 100644 --- a/src/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.ts +++ b/src/cli/list/spool-files-by-jobid/SpoolFilesByJobid.Handler.ts @@ -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);