diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 263ce01339..5b544c80c2 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Zowe CLI package will be documented in this file. +## Recent Changes + +- BugFix: Fix bug where encoding is not passed to the Download USS Directory API [#1825](https://github.com/zowe/zowe-cli/issues/1825) + ## `7.18.7` - BugFix: Bump Imperative to `5.18.2` to fix issues with normalizing newlines on file uploads [#1815](https://github.com/zowe/zowe-cli/issues/1815) diff --git a/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/UssDir.handler.unit.test.ts b/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/UssDir.handler.unit.test.ts index 39cc44344a..64857d28ba 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/UssDir.handler.unit.test.ts +++ b/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/UssDir.handler.unit.test.ts @@ -104,6 +104,76 @@ describe("Download uss dir handler", () => { expect(logMessage).toMatchSnapshot(); }); + it("should download a uss dir in an encoding", async () => { + // Require the handler and create a new instance + const handlerReq = require("../../../../../src/zosfiles/download/ussdir/UssDir.handler"); + const handler = new handlerReq.default(); + const ussDirName = "/z/testingDirectory"; + + const localDownloadObj: IDownloadOptions = {...defaultDownloadObj, encoding: "IBM-037"}; + const localListObj: IUSSListOptions = {...defaultListObj}; + + // Vars populated by the mocked function + let error; + let apiMessage = ""; + let jsonObj; + let logMessage = ""; + let fakeSession = null; + + Download.ussDir = jest.fn(async (session) => { + fakeSession = session; + return { + success: true, + commandResponse: "downloaded" + }; + }); + + try { + // Invoke the handler with a full set of mocked arguments and response functions + await handler.process({ + arguments: { + $0: "fake", + _: ["fake"], + ussDirName, + encoding: "IBM-037", + ...UNIT_TEST_ZOSMF_PROF_OPTS + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: { + startBar: jest.fn((parms) => { + // do nothing + }), + endBar: jest.fn(() => { + // do nothing + }) + } + } + } as any); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(Download.ussDir).toHaveBeenCalledTimes(1); + expect(Download.ussDir).toHaveBeenCalledWith(fakeSession, ussDirName, localDownloadObj, localListObj); + expect(jsonObj).toMatchSnapshot(); + expect(apiMessage).toMatchSnapshot(); + expect(logMessage).toMatchSnapshot(); + }); + it("should download a uss dir and look for a particular file", async () => { // Require the handler and create a new instance const handlerReq = require("../../../../../src/zosfiles/download/ussdir/UssDir.handler"); diff --git a/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/__snapshots__/UssDir.handler.unit.test.ts.snap b/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/__snapshots__/UssDir.handler.unit.test.ts.snap index 26620955e6..4a6e5cc1b4 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/__snapshots__/UssDir.handler.unit.test.ts.snap +++ b/packages/cli/__tests__/zosfiles/__unit__/download/ussdir/__snapshots__/UssDir.handler.unit.test.ts.snap @@ -153,3 +153,17 @@ exports[`Download uss dir handler process method should download a uss dir if re " downloaded" `; + +exports[`Download uss dir handler process method should download a uss dir in an encoding 1`] = ` +Object { + "commandResponse": "downloaded", + "success": true, +} +`; + +exports[`Download uss dir handler process method should download a uss dir in an encoding 2`] = `""`; + +exports[`Download uss dir handler process method should download a uss dir in an encoding 3`] = ` +" +downloaded" +`; diff --git a/packages/cli/src/zosfiles/download/ussdir/UssDir.handler.ts b/packages/cli/src/zosfiles/download/ussdir/UssDir.handler.ts index d528546c4d..1b7f3e3f5a 100644 --- a/packages/cli/src/zosfiles/download/ussdir/UssDir.handler.ts +++ b/packages/cli/src/zosfiles/download/ussdir/UssDir.handler.ts @@ -37,7 +37,8 @@ export default class UssDirHandler extends ZosFilesBaseHandler { failFast: commandParameters.arguments.failFast, attributes: zosAttributes, includeHidden: commandParameters.arguments.includeHidden, - overwrite: commandParameters.arguments.overwrite + overwrite: commandParameters.arguments.overwrite, + encoding: commandParameters.arguments.encoding }; const listOptions: IUSSListOptions = { name: commandParameters.arguments.name ? commandParameters.arguments.name : "*",