diff --git a/.editorconfig b/.editorconfig index 2536d66b..5760be58 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_style = space -indent_size = 4 +indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 725f6ccd..18d05390 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -36,9 +36,7 @@ rules: "@typescript-eslint/explicit-function-return-type": off "@typescript-eslint/restrict-template-expressions": off indent": off - "@typescript-eslint/indent": - - error - - 2 + "@typescript-eslint/indent": off # There are several errors falling under these rules; resolve "@typescript-eslint/no-for-in-array": off diff --git a/package.json b/package.json index e5a5ec89..89d72baa 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,7 @@ "test": "npm run test --workspaces", "test:system": "npm run test:system --workspaces", "test:unit": "npm run test:unit --workspaces", - "lint": "npm run lint --workspaces", - "lintErrors": "npm run lintErrors --workspaces", + "lint": "turbo lint", "prepare": "husky install", "pretty": "turbo pretty", "license": "node scripts/updateLicenses.js" diff --git a/packages/cli/__tests__/__unit__/enable/Enable.definition.unit.test.ts b/packages/cli/__tests__/__unit__/enable/Enable.definition.unit.test.ts index cc8542a8..98cc1966 100644 --- a/packages/cli/__tests__/__unit__/enable/Enable.definition.unit.test.ts +++ b/packages/cli/__tests__/__unit__/enable/Enable.definition.unit.test.ts @@ -12,7 +12,7 @@ import { ICommandDefinition } from "@zowe/imperative"; describe("cics enable urimap", () => { - const ENABLE_RESOURCES = 1; + const ENABLE_RESOURCES = 2; it("should not have changed", () => { const definition: ICommandDefinition = require("../../../src/enable/Enable.definition"); diff --git a/packages/cli/__tests__/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap b/packages/cli/__tests__/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap index 16ad1161..17455936 100644 --- a/packages/cli/__tests__/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap @@ -5,7 +5,7 @@ exports[`cics enable urimap should not have changed 1`] = ` "aliases": [ "en", ], - "description": "Enable resources (for example, urimaps) from CICS through IBM CMCI.", + "description": "Enable resources from CICS through IBM CMCI.", "name": "enable", "passOn": [ { diff --git a/packages/cli/__tests__/__unit__/enable/transaction/Transaction.definition.unit.test.ts b/packages/cli/__tests__/__unit__/enable/transaction/Transaction.definition.unit.test.ts new file mode 100644 index 00000000..025977df --- /dev/null +++ b/packages/cli/__tests__/__unit__/enable/transaction/Transaction.definition.unit.test.ts @@ -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 urimap", () => { + it("should not have changed", () => { + const definition: ICommandDefinition = require("../../../../src/enable/transaction/Transaction.definition").TransactionDefinition; + expect(definition).toBeDefined(); + delete definition.handler; + expect(definition).toMatchSnapshot(); + }); +}); diff --git a/packages/cli/__tests__/__unit__/enable/transaction/Transaction.handler.unit.test.ts b/packages/cli/__tests__/__unit__/enable/transaction/Transaction.handler.unit.test.ts new file mode 100644 index 00000000..78846995 --- /dev/null +++ b/packages/cli/__tests__/__unit__/enable/transaction/Transaction.handler.unit.test.ts @@ -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 { TransactionDefinition } from "../../../../src/enable/transaction/Transaction.definition"; +import TransactionHandler from "../../../../src/enable/transaction/Transaction.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(); +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", "transaction"], + definition: TransactionDefinition, + profiles: PROFILES, +}); + +describe("enableTransactionHandler", () => { + const transactionName = "testTransaction"; + 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, "enableTransaction"); + + beforeEach(() => { + functionSpy.mockClear(); + functionSpy.mockImplementation(async () => defaultReturn); + }); + + it("should call the enableTransaction api", async () => { + const handler = new TransactionHandler(); + + const commandParameters = { ...DEFAULT_PARAMETERS }; + commandParameters.arguments = { + ...commandParameters.arguments, + name: transactionName, + 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: transactionName, + regionName, + } + ); + }); +}); diff --git a/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.definition.unit.test.ts.snap b/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.definition.unit.test.ts.snap new file mode 100644 index 00000000..b1791f1b --- /dev/null +++ b/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.definition.unit.test.ts.snap @@ -0,0 +1,43 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`cics enable urimap 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", +} +`; diff --git a/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.handler.unit.test.ts.snap b/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.handler.unit.test.ts.snap new file mode 100644 index 00000000..184c9b78 --- /dev/null +++ b/packages/cli/__tests__/__unit__/enable/transaction/__snapshots__/Transaction.handler.unit.test.ts.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`enableTransactionHandler should call the enableTransaction api 1`] = `"The transaction '%s' was enabled successfully."`; + +exports[`enableTransactionHandler should call the enableTransaction api 2`] = ` +{ + "response": { + "records": "testing", + "resultsummary": { + "api_response1": "1024", + "api_response2": "0", + "displayed_recordcount": "0", + "recordcount": "0", + }, + }, +} +`; diff --git a/packages/sdk/__tests__/__unit__/enable/Enable.transaction.unit.test.ts b/packages/sdk/__tests__/__unit__/enable/Enable.transaction.unit.test.ts new file mode 100644 index 00000000..d13bfa26 --- /dev/null +++ b/packages/sdk/__tests__/__unit__/enable/Enable.transaction.unit.test.ts @@ -0,0 +1,106 @@ +/** + * 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 { Session } from "@zowe/imperative"; +import { CicsCmciConstants, CicsCmciRestClient, enableTransaction, ICMCIApiResponse, IBaseParms } from "../../../src"; + +describe("CMCI - enable transaction", () => { + const transaction = "transaction"; + const region = "region"; + const content = "ThisIsATest" as unknown as ICMCIApiResponse; + + const enableParms: IBaseParms = { + regionName: region, + name: transaction, + }; + + const dummySession = new Session({ + user: "fake", + password: "fake", + hostname: "fake", + port: 1490, + }); + + let error: any; + let response: any; + let endPoint: any; + let requestBody: any; + + describe("validation", () => { + beforeEach(() => { + response = undefined; + error = undefined; + enableParms.regionName = region; + enableParms.name = transaction; + }); + + it("should throw an error if no region name is specified", async () => { + enableParms.regionName = undefined; + try { + response = await enableTransaction(dummySession, enableParms); + } catch (err) { + error = err; + } + expect(response).toBeUndefined(); + expect(error).toBeDefined(); + expect(error.message).toContain("CICS region name is required"); + }); + + it("should throw an error if no transaction name is specified", async () => { + enableParms.name = undefined; + try { + response = await enableTransaction(dummySession, enableParms); + } catch (err) { + error = err; + } + expect(response).toBeUndefined(); + expect(error).toBeDefined(); + expect(error.message).toContain("CICS Transaction name is required"); + }); + }); + + describe("success scenarios", () => { + const enableSpy = jest.spyOn(CicsCmciRestClient, "putExpectParsedXml").mockResolvedValue(content); + + beforeEach(() => { + response = undefined; + error = undefined; + enableSpy.mockClear(); + enableSpy.mockResolvedValue(content); + enableParms.regionName = region; + enableParms.name = transaction; + }); + + it("should be able to enable a transaction", async () => { + endPoint = + "/" + + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + + "/" + + CicsCmciConstants.CICS_LOCAL_TRANSACTION + + "/" + + region + + `?CRITERIA=(TRANID=${enableParms.name})`; + requestBody = { + request: { + action: { + $: { + name: "ENABLE", + }, + }, + }, + }; + + response = await enableTransaction(dummySession, enableParms); + expect(response).toContain(content); + expect(enableSpy).toHaveBeenCalledWith(dummySession, endPoint, [], requestBody); + }); + }); +}); diff --git a/turbo.json b/turbo.json index 72f34d55..529343e9 100644 --- a/turbo.json +++ b/turbo.json @@ -2,7 +2,7 @@ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { - "dependsOn": ["^build"], + "dependsOn": ["lint", "^build"], "outputs": ["dist/**", "lib/**"] }, "watch": { @@ -12,10 +12,10 @@ "dependsOn": ["build"], "inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts", "test/**/*.tsx"] }, - "lint": {}, - "pretty": { - "cache": false + "lint": { + "dependsOn": ["pretty"] }, + "pretty": {}, "package": { "dependsOn": ["build"], "cache": false