Skip to content

Commit

Permalink
feat: Migrate enable-program with 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 24, 2024
1 parent bc53ea2 commit 64c8936
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { ICommandDefinition } from "@zowe/imperative";

describe("cics enable urimap", () => {
const ENABLE_RESOURCES = 2;
const ENABLE_RESOURCES = 3;

it("should not have changed", () => {
const definition: ICommandDefinition = require("../../../src/enable/Enable.definition");
Expand Down
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 program", () => {
it("should not have changed", () => {
const definition: ICommandDefinition = require("../../../../src/enable/program/Program.definition").ProgramDefinition;
expect(definition).toBeDefined();
delete definition.handler;
expect(definition).toMatchSnapshot();
});
});
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 { ProgramDefinition } from "../../../../src/enable/program/Program.definition";
import ProgramHandler from "../../../../src/enable/program/Program.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", "program"],
definition: ProgramDefinition,
profiles: PROFILES,
});

describe("enableProgramHandler", () => {
const programName = "testProgram";
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, "enableProgram");

beforeEach(() => {
functionSpy.mockClear();
functionSpy.mockImplementation(async () => defaultReturn);
});

it("should call the enableProgram api", async () => {
const handler = new ProgramHandler();

const commandParameters = { ...DEFAULT_PARAMETERS };
commandParameters.arguments = {
...commandParameters.arguments,
name: programName,
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: programName,
regionName,
}
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cics enable program should not have changed 1`] = `
{
"aliases": [
"prog",
],
"description": "Enable a program from CICS.",
"examples": [
{
"description": "Enable a program named PROGRAM1 from the region named MYREGION",
"options": "PROGRAM1 --region-name MYREGION",
},
],
"name": "program",
"options": [
{
"description": "The CICS region name in which to enable the program",
"name": "region-name",
"type": "string",
},
{
"description": "The name of the CICSPlex to which to enable the program",
"name": "cics-plex",
"type": "string",
},
],
"positionals": [
{
"description": "The name of the program to enable. The maximum length is eight characters.",
"name": "name",
"required": true,
"type": "string",
},
],
"profile": {
"optional": [
"cics",
],
},
"type": "command",
}
`;

exports[`cics enable urimap should not have changed 1`] = `
{
"aliases": [
"prog",
],
"description": "Enable a program from CICS.",
"examples": [
{
"description": "Enable a program named PROGRAM1 from the region named MYREGION",
"options": "PROGRAM1 --region-name MYREGION",
},
],
"name": "program",
"options": [
{
"description": "The CICS region name in which to enable the program",
"name": "region-name",
"type": "string",
},
{
"description": "The name of the CICSPlex to which to enable the program",
"name": "cics-plex",
"type": "string",
},
],
"positionals": [
{
"description": "The name of the program to enable. The maximum length is eight characters.",
"name": "name",
"required": true,
"type": "string",
},
],
"profile": {
"optional": [
"cics",
],
},
"type": "command",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`enableProgramHandler should call the enableProgram api 1`] = `"The program '%s' was enabled successfully."`;

exports[`enableProgramHandler should call the enableProgram api 2`] = `
{
"response": {
"records": "testing",
"resultsummary": {
"api_response1": "1024",
"api_response2": "0",
"displayed_recordcount": "0",
"recordcount": "0",
},
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { ICommandDefinition } from "@zowe/imperative";

describe("cics enable urimap", () => {
describe("cics enable transaction", () => {
it("should not have changed", () => {
const definition: ICommandDefinition = require("../../../../src/enable/transaction/Transaction.definition").TransactionDefinition;
expect(definition).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cics enable transaction should not have changed 1`] = `
{
"aliases": [
"tran",
],
"description": "Enable a transaction from CICS.",
"examples": [
{
"description": "Enable a transaction named TRN1 from the region named MYREGION",
"options": "TRN1 --region-name MYREGION",
},
],
"name": "transaction",
"options": [
{
"description": "The CICS region name in which to enable the transaction",
"name": "region-name",
"type": "string",
},
{
"description": "The name of the CICSPlex to which to enable the transaction",
"name": "cics-plex",
"type": "string",
},
],
"positionals": [
{
"description": "The name of the transaction to enable. The maximum length is four characters.",
"name": "name",
"required": true,
"type": "string",
},
],
"profile": {
"optional": [
"cics",
],
},
"type": "command",
}
`;

exports[`cics enable urimap should not have changed 1`] = `
{
"aliases": [
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ export default {
SUMMARY: "Enable resources from CICS",
DESCRIPTION: "Enable resources from CICS through IBM CMCI.",
RESOURCES: {
PROGRAM: {
DESCRIPTION: "Enable a program from CICS.",
POSITIONALS: {
NAME: "The name of the program to enable. The maximum length is eight characters.",
},
OPTIONS: {
REGIONNAME: "The CICS region name in which to enable the program",
CICSPLEX: "The name of the CICSPlex to which to enable the program",
},
MESSAGES: {
SUCCESS: "The program '%s' was enabled successfully.",
},
EXAMPLES: {
EX1: "Enable a program named PROGRAM1 from the region named MYREGION",
},
},
TRANSACTION: {
DESCRIPTION: "Enable a transaction from CICS.",
POSITIONALS: {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/enable/Enable.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UrimapDefinition } from "./urimap/Urimap.definition";
import i18nTypings from "../-strings-/en";
import { CicsSession } from "../CicsSession";
import { TransactionDefinition } from "./transaction/Transaction.definition";
import { ProgramDefinition } from "./program/Program.definition";

// 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;
Expand All @@ -28,7 +29,7 @@ const definition: ICommandDefinition = {
summary: strings.SUMMARY,
description: strings.DESCRIPTION,
type: "group",
children: [TransactionDefinition, UrimapDefinition],
children: [ProgramDefinition, TransactionDefinition, UrimapDefinition],
passOn: [
{
property: "options",
Expand Down
52 changes: 52 additions & 0 deletions packages/cli/src/enable/program/Program.definition.ts
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.PROGRAM;

export const ProgramDefinition: ICommandDefinition = {
name: "program",
aliases: ["prog"],
description: strings.DESCRIPTION,
handler: __dirname + "/Program.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: "PROGRAM1 --region-name MYREGION",
},
],
};
Loading

0 comments on commit 64c8936

Please sign in to comment.