Skip to content

Commit

Permalink
Merge pull request #171 from zowe/get-resource-query-params
Browse files Browse the repository at this point in the history
Add CMCI query parameters to SDK getResource
  • Loading branch information
zFernand0 authored Dec 17, 2024
2 parents 1c1b848 + 6204253 commit 1ea123b
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 47 deletions.
4 changes: 4 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the IBM® CICS® Plug-in for Zowe CLI will be documented in this file.

## Recent Changes

- Enhancement: Add optional query parameters on getResource SDK method. [#168](https://github.com/zowe/cics-for-zowe-client/issues/168)

## `6.1.0`

- Enhancement: Made the region name optional on the getResource SDK method. [#162](https://github.com/zowe/cics-for-zowe-client/issues/162)
Expand Down
69 changes: 69 additions & 0 deletions packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,74 @@ describe("CMCI - Get resource", () => {
expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a resource with SUMMONLY specified", async () => {
resourceParms.cicsPlex = "plex1";
resourceParms.regionName = "reg1";
resourceParms.queryParams = {
summonly: true,
};
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?SUMMONLY`;
response = await getResource(dummySession, resourceParms);

expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a resource with NODISCARD specified", async () => {
resourceParms.cicsPlex = "plex1";
resourceParms.regionName = "reg1";
resourceParms.queryParams = {
nodiscard: true,
};
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?NODISCARD`;
response = await getResource(dummySession, resourceParms);

expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a resource with OVERRIDEWARNINGCOUNT specified", async () => {
resourceParms.cicsPlex = "plex1";
resourceParms.regionName = "reg1";
resourceParms.queryParams = {
overrideWarningCount: true,
};
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);

expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a resource with all query params specified", async () => {
resourceParms.cicsPlex = "plex1";
resourceParms.regionName = "reg1";
resourceParms.queryParams = {
overrideWarningCount: true,
summonly: true,
nodiscard: true,
};
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);

expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a resource with no context and all query params specified", async () => {
resourceParms.cicsPlex = undefined;
resourceParms.regionName = undefined;
resourceParms.queryParams = {
overrideWarningCount: true,
summonly: true,
nodiscard: true,
};
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);

expect(response).toContain(content);
expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});
});
});
190 changes: 190 additions & 0 deletions packages/sdk/__tests__/__unit__/utils/Utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,195 @@ describe("Utils - getResourceUri", () => {
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1?CRITERIA=(NAME%3Dtest1)&PARAMETER=PARAM%3Dtest2");
});

it("should be able to get a resource uri with SUMMONLY specified", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
summonly: true,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1?SUMMONLY");
});

it("should be able to get a resource uri with SUMMONLY specified to false", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
summonly: false,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1");
});

it("should be able to get a resource uri with NODISCARD specified", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
nodiscard: true,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1?NODISCARD");
});

it("should be able to get a resource uri with NODISCARD specified", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
nodiscard: false,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1");
});

it("should be able to get a resource uri with OVERRIDEWARNINGCOUNT specified", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
overrideWarningCount: true,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1?OVERRIDEWARNINGCOUNT");
});

it("should be able to get a resource uri with OVERRIDEWARNINGCOUNT specified to false", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
overrideWarningCount: false,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1");
});

it("should be able to get a resource uri with all query params specified", async () => {
try {
const options: IGetResourceUriOptions = {
cicsPlex: "cicsplex1",
regionName: "region1",
queryParams: {
summonly: true,
nodiscard: true,
overrideWarningCount: true,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/cicsplex1/region1?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT");
});

it("should be able to get a resource uri with all query params specified and no context", async () => {
try {
const options: IGetResourceUriOptions = {
queryParams: {
summonly: true,
nodiscard: true,
overrideWarningCount: true,
}
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1/?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT");
});
});
});

describe('Utils - enforceParentheses', () => {

it("should add brackets when none exist", () => {
const output = Utils.enforceParentheses("input");
expect(output).toEqual("(input)");
});

it("should add first bracket when end exists", () => {
const output = Utils.enforceParentheses("input with spaces)");
expect(output).toEqual("(input with spaces)");
});

it("should add last bracket when first exists", () => {
const output = Utils.enforceParentheses("(input with spec1@| characters");
expect(output).toEqual("(input with spec1@| characters)");
});

it("should do nothing when both brackets exist", () => {
const output = Utils.enforceParentheses("(fully covered)");
expect(output).toEqual("(fully covered)");
});

it("should do nothing when multiple brackets exist", () => {
const output = Utils.enforceParentheses("((()))");
expect(output).toEqual("((()))");
});
});
7 changes: 6 additions & 1 deletion packages/sdk/src/constants/CicsCmci.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Constants to be used by the API
*/
export const CicsCmciConstants: { [key: string]: any } = {
export const CicsCmciConstants = {
/**
* Specifies the required part of the REST interface URI
*/
Expand Down Expand Up @@ -79,6 +79,11 @@ export const CicsCmciConstants: { [key: string]: any } = {
*/
NO_DISCARD: "NODISCARD",

/**
* OVERRIDEWARNINGCOUNT parameter
*/
OVERRIDE_WARNING_COUNT: "OVERRIDEWARNINGCOUNT",

/**
* CRITERIA parameter
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/src/doc/IGetResourceUriOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*
*/

import { IResourceQueryParams } from "./IResourceQueryParms";

export interface IGetResourceUriOptions {

/**
Expand Down Expand Up @@ -39,4 +41,9 @@ export interface IGetResourceUriOptions {
* "CSDGROUP(D*)"
*/
parameter?: string;

/**
* Query parameters to be used in the HTTP request
*/
queryParams?: IResourceQueryParams;
}
33 changes: 3 additions & 30 deletions packages/sdk/src/doc/IResourceParms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,11 @@
*
*/

export interface IResourceParms {
import { IGetResourceUriOptions } from "./IGetResourceUriOptions";

export interface IResourceParms extends IGetResourceUriOptions {
/**
* The name of the resource
*/
name: string;

/**
* Criteria by which to filter the records
*
* Examples:
* "TRANID=TRAN"
* "PROGRAM=PRG*"
* "NAME=C* AND PROGRAM=D*"
*/
criteria?: string;

/**
* Parameter by which to refine the records
*
* Example:
* "CSDGROUP(GRP1)"
* "CSDGROUP(D*)"
*/
parameter?: string;

/**
* The name of the CICS region of the program
*/
regionName?: string;

/**
* CICS Plex of the program
*/
cicsPlex?: string;
}
25 changes: 25 additions & 0 deletions packages/sdk/src/doc/IResourceQueryParms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.
*
*/

export interface IResourceQueryParams {
/**
* Include SUMMONLY query parameter
*/
summonly?: boolean;
/**
* Include NODISCARD query parameter
*/
nodiscard?: boolean;
/**
* Include OVERRIDEWARNINGCOUNT query parameter
*/
overrideWarningCount?: boolean;
}
Loading

0 comments on commit 1ea123b

Please sign in to comment.