-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate enable-localFile with unit tests
Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
451 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/cli/__tests__/__unit__/enable/localFile/LocalFile.definition.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
import { ICommandDefinition } from "@zowe/imperative"; | ||
|
||
describe("cics enable localFile", () => { | ||
it("should not have changed", () => { | ||
const definition: ICommandDefinition = require("../../../../src/enable/localFile/LocalFile.definition").LocalFileDefinition; | ||
expect(definition).toBeDefined(); | ||
delete definition.handler; | ||
expect(definition).toMatchSnapshot(); | ||
}); | ||
}); |
102 changes: 102 additions & 0 deletions
102
packages/cli/__tests__/__unit__/enable/localFile/LocalFile.handler.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
import { mockHandlerParameters } from "@zowe/cli-test-utils"; | ||
import { CommandProfiles, IHandlerParameters, IProfile, Session } from "@zowe/imperative"; | ||
import { ICMCIApiResponse } from "../../../../src"; | ||
import { LocalFileDefinition } from "../../../../src/enable/localFile/LocalFile.definition"; | ||
import LocalFileHandler from "../../../../src/enable/localFile/LocalFile.handler"; | ||
|
||
jest.mock("@zowe/cics-for-zowe-sdk"); | ||
const Enable = require("@zowe/cics-for-zowe-sdk"); | ||
|
||
const host = "somewhere.com"; | ||
const port = "43443"; | ||
const user = "someone"; | ||
const password = "somesecret"; | ||
const protocol = "http"; | ||
const rejectUnauthorized = false; | ||
|
||
const PROFILE_MAP = new Map<string, IProfile[]>(); | ||
PROFILE_MAP.set("cics", [ | ||
{ | ||
name: "cics", | ||
type: "cics", | ||
host, | ||
port, | ||
user, | ||
password, | ||
protocol, | ||
rejectUnauthorized, | ||
}, | ||
]); | ||
const PROFILES: CommandProfiles = new CommandProfiles(PROFILE_MAP); | ||
const DEFAULT_PARAMETERS: IHandlerParameters = mockHandlerParameters({ | ||
positionals: ["cics", "enable", "localFile"], | ||
definition: LocalFileDefinition, | ||
profiles: PROFILES, | ||
}); | ||
|
||
describe("enableLocalFileHandler", () => { | ||
const localFileName = "testLocalFile"; | ||
const regionName = "testRegion"; | ||
|
||
const defaultReturn: ICMCIApiResponse = { | ||
response: { | ||
resultsummary: { api_response1: "1024", api_response2: "0", recordcount: "0", displayed_recordcount: "0" }, | ||
records: "testing", | ||
}, | ||
}; | ||
|
||
const functionSpy = jest.spyOn(Enable, "enableLocalFile"); | ||
|
||
beforeEach(() => { | ||
functionSpy.mockClear(); | ||
functionSpy.mockImplementation(async () => defaultReturn); | ||
}); | ||
|
||
it("should call the enableLocalFile api", async () => { | ||
const handler = new LocalFileHandler(); | ||
|
||
const commandParameters = { ...DEFAULT_PARAMETERS }; | ||
commandParameters.arguments = { | ||
...commandParameters.arguments, | ||
name: localFileName, | ||
regionName, | ||
host, | ||
port, | ||
user, | ||
password, | ||
protocol, | ||
rejectUnauthorized, | ||
}; | ||
|
||
await handler.process(commandParameters); | ||
|
||
expect(functionSpy).toHaveBeenCalledTimes(1); | ||
const testProfile = PROFILE_MAP.get("cics")[0]; | ||
expect(functionSpy).toHaveBeenCalledWith( | ||
new Session({ | ||
type: "basic", | ||
hostname: testProfile.host, | ||
port: testProfile.port, | ||
user: testProfile.user, | ||
password: testProfile.password, | ||
rejectUnauthorized, | ||
protocol, | ||
}), | ||
{ | ||
name: localFileName, | ||
regionName, | ||
} | ||
); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
.../__tests__/__unit__/enable/localFile/__snapshots__/LocalFile.definition.unit.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`cics enable localFile should not have changed 1`] = ` | ||
{ | ||
"aliases": [ | ||
"lf", | ||
], | ||
"description": "Enable a local file from CICS.", | ||
"examples": [ | ||
{ | ||
"description": "Enable a local file named FILE from the region named MYREGION", | ||
"options": "FILE --region-name MYREGION", | ||
}, | ||
], | ||
"name": "local-file", | ||
"options": [ | ||
{ | ||
"description": "The CICS region name in which to enable the local file", | ||
"name": "region-name", | ||
"type": "string", | ||
}, | ||
{ | ||
"description": "The name of the CICSPlex to which to enable the local file", | ||
"name": "cics-plex", | ||
"type": "string", | ||
}, | ||
], | ||
"positionals": [ | ||
{ | ||
"description": "The name of the local file to enable.", | ||
"name": "name", | ||
"required": true, | ||
"type": "string", | ||
}, | ||
], | ||
"profile": { | ||
"optional": [ | ||
"cics", | ||
], | ||
}, | ||
"type": "command", | ||
} | ||
`; |
17 changes: 17 additions & 0 deletions
17
...cli/__tests__/__unit__/enable/localFile/__snapshots__/LocalFile.handler.unit.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`enableLocalFileHandler should call the enableLocalFile api 1`] = `"The local file '%s' was enabled successfully."`; | ||
|
||
exports[`enableLocalFileHandler should call the enableLocalFile api 2`] = ` | ||
{ | ||
"response": { | ||
"records": "testing", | ||
"resultsummary": { | ||
"api_response1": "1024", | ||
"api_response2": "0", | ||
"displayed_recordcount": "0", | ||
"recordcount": "0", | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
import { ICommandDefinition } from "@zowe/imperative"; | ||
|
||
import i18nTypings from "../../-strings-/en"; | ||
|
||
// Does not use the import in anticipation of some internationalization work to be done later. | ||
const strings = (require("../../-strings-/en").default as typeof i18nTypings).ENABLE.RESOURCES.LOCALFILE; | ||
|
||
export const LocalFileDefinition: ICommandDefinition = { | ||
name: "local-file", | ||
aliases: ["lf"], | ||
description: strings.DESCRIPTION, | ||
handler: __dirname + "/LocalFile.handler", | ||
type: "command", | ||
positionals: [ | ||
{ | ||
name: "name", | ||
description: strings.POSITIONALS.NAME, | ||
type: "string", | ||
required: true, | ||
}, | ||
], | ||
options: [ | ||
{ | ||
name: "region-name", | ||
description: strings.OPTIONS.REGIONNAME, | ||
type: "string", | ||
}, | ||
{ | ||
name: "cics-plex", | ||
description: strings.OPTIONS.CICSPLEX, | ||
type: "string", | ||
}, | ||
], | ||
profile: { optional: ["cics"] }, | ||
examples: [ | ||
{ | ||
description: strings.EXAMPLES.EX1, | ||
options: "FILE --region-name MYREGION", | ||
}, | ||
], | ||
}; |
Oops, something went wrong.