Skip to content

Commit

Permalink
updated unit tests, system tests and minor logic changes
Browse files Browse the repository at this point in the history
Signed-off-by: jace-roell <[email protected]>
  • Loading branch information
jace-roell committed Sep 12, 2024
1 parent e1af1b2 commit 96dbc94
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ exports[`issue command handler tests should issue command 1`] = `
},
undefined,
Object {
"addressSpaceOptions": Object {
"account": "fake",
"characterSet": undefined,
"codePage": undefined,
"columns": undefined,
"logonProcedure": undefined,
"regionSize": undefined,
"rows": undefined,
},
"isStateful": undefined,
"suppressStartupMessage": undefined,
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/zostso/issue/command/Command.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class Handler extends ZosTsoBaseHandler {
isStateful: params.arguments.stateful,
suppressStartupMessage:
params.arguments.suppressStartupMessages,
addressSpaceOptions: this.mTsoStart
}
);

Expand Down
44 changes: 40 additions & 4 deletions packages/zostso/__tests__/__system__/api.TsoIssue.system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import * as fs from "fs";
import { ITestEnvironment } from "@zowe/cli-test-utils";
import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment";
import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema";

import { IIssueTsoCmdParms } from "../../src";
import { IIssueTsoCmdOpts } from "../../src/doc/input/IIssueTsoCmdOpts";
let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
let systemProperties: ITestPropertiesSchema;
let REAL_SESSION: Session;
let ACCOUNT_NUMBER: string;

let START_PARAMS: IStartTsoParms;
let ISSUE_PARAMS: IIssueTsoParms;

let COMMAND_PARAMS: IIssueTsoCmdParms;
let AS_OPTIONS: IIssueTsoCmdOpts;
describe("IssueTso.issueTsoCommand", () => {

beforeAll(async () => {
Expand All @@ -50,9 +52,18 @@ describe("IssueTso.issueTsoCommand", () => {
accountNumber: ACCOUNT_NUMBER,
startParams: START_PARAMS
};

COMMAND_PARAMS = {
command: "TIME"
}
AS_OPTIONS = {
addressSpaceOptions: START_PARAMS
}
});
afterAll(async () => {
AS_OPTIONS = {
addressSpaceOptions: START_PARAMS
}
});

it("should display time", async () => {
let error: ImperativeError;
let response: IIssueResponse;
Expand Down Expand Up @@ -81,4 +92,29 @@ describe("IssueTso.issueTsoCommand", () => {
const regex = fs.readFileSync(__dirname + "/__regex__/d_time.regex").toString();
expect(new RegExp(regex, "g").test(response.commandResponse.toString())).toBe(true);
});
it("should display time - issueTsoCmd() - new API - pass", async () => {
let error: ImperativeError;
let response: IIssueResponse;
try {
response = await IssueTso.issueTsoCmd(REAL_SESSION, "TIME", AS_OPTIONS);
} catch (thrownError) {
error = thrownError;
}
expect(error).toBeUndefined();
expect(response).toBeDefined();
const regex = fs.readFileSync(__dirname + "/__regex__/d_time.regex").toString();
expect(new RegExp(regex, "g").test(response.commandResponse.toString())).toBe(true);
});
it("should fail - issueTsoCmd() - 404 error", async () => {
REAL_SESSION.ISession.basePath = "/bad/path/to/nothing"
let error: ImperativeError;
let response: IIssueResponse;
try {
response = await IssueTso.issueTsoCmd(REAL_SESSION, "TIME", AS_OPTIONS);
} catch (thrownError) {
error = thrownError;
}
expect(error).toBeDefined();
expect(response).toBeUndefined();
});
});
6 changes: 6 additions & 0 deletions packages/zostso/__tests__/__unit__/IssueTso.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ describe("TsoIssue issueTsoCommand - failing scenarios", () => {
expect(error).toBeDefined();
});
it("should fail when StartTSO fails", async () => {
jest.spyOn(CheckStatus, "isZosVersionGreaterThan").mockReturnValue(
Promise.resolve(false)
);
let error: ImperativeError;
let response: ISendResponse;

Expand Down Expand Up @@ -168,6 +171,9 @@ describe("TsoIssue issueTsoCommand - failing scenarios", () => {

describe("TsoIssue issueTsoCommand - Deprecated API", () => {
it("should succeed", async () => {
jest.spyOn(CheckStatus, "isZosVersionGreaterThan").mockReturnValue(
Promise.resolve(false)
);
(StartTso.start as any) = jest.fn(() => {
return new Promise((resolve) => {
process.nextTick(() => {
Expand Down
5 changes: 1 addition & 4 deletions packages/zostso/src/IssueTso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export class IssueTso {
let command: string | IIssueTsoCmdParms;
let version: string;
opts = opts || {};

let useNewApi =
opts.addressSpaceOptions == null &&
opts.addressSpaceOptions == null ||
await CheckStatus.isZosVersionGreaterThan(
session,
ZosmfConstants.VERSIONS.V2R4
Expand Down Expand Up @@ -78,8 +77,6 @@ export class IssueTso {
}
// Deprecated API Behavior [former issueTsoCommand() behavior]
if (opts.addressSpaceOptions != null || !useNewApi) {

Check warning

Code scanning / CodeQL

Useless conditional Warning

This negation always evaluates to true.
const profInfo = ImperativeConfig.instance.config.api.profiles.defaultGet("tso");
opts.addressSpaceOptions = { ...opts.addressSpaceOptions, ...profInfo};
command =
typeof commandInfo === "string"
? commandInfo
Expand Down

0 comments on commit 96dbc94

Please sign in to comment.