Skip to content

Commit

Permalink
unit test failOnNoData flag
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Twydell <[email protected]>
  • Loading branch information
AndrewTwydell committed Jan 10, 2025
1 parent 06e2c06 commit ec5b1e2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("CMCI - Get Cache", () => {
"/" + cacheParms.cacheToken + "?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, [], true);
});

it("should be able to get a result cache with SUMMONLY", async () => {
Expand All @@ -132,7 +132,7 @@ describe("CMCI - Get Cache", () => {
"&" + CicsCmciConstants.SUMM_ONLY;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, [], true);
});

it("should be able to get a result cache with start index", async () => {
Expand All @@ -149,7 +149,7 @@ describe("CMCI - Get Cache", () => {
"10?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, [], true);
});

it("should be able to get a result cache with start index and count", async () => {
Expand All @@ -167,7 +167,7 @@ describe("CMCI - Get Cache", () => {
"15/5?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, [], true);
});

it("should be able to get a result cache without NODISCARD", async () => {
Expand All @@ -183,7 +183,7 @@ describe("CMCI - Get Cache", () => {
"/" + cacheParms.cacheToken;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, [], true);
});
});
});
46 changes: 45 additions & 1 deletion packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ICMCIApiResponse,
IResourceParms
} from "../../../src";
import { ok2RecordsXmlResponse, okContent2Records } from "../../__mocks__/CmciGetResponse";
import { nodataContent, nodataXmlResponse, ok2RecordsXmlResponse, okContent2Records } from "../../__mocks__/CmciGetResponse";

describe("CMCI - Get resource", () => {

Expand Down Expand Up @@ -255,5 +255,49 @@ describe("CMCI - Get resource", () => {
expect(response).toEqual(okContent2Records);
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should error when failOnNoData is true and data is not returned", async () => {

getExpectStringMock.mockClear();
getExpectStringMock.mockResolvedValue(nodataXmlResponse);

endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/REGION1`;
try {
response = await getResource(dummySession, resourceParms, true);
} catch (err) {
error = err;
}

expect(error).toBeDefined();
expect(`${error}`).toContain("1027");
expect(response).toBeUndefined();
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should not fail when failOnNoData is true and data is returned", async () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/REGION1`;
response = await getResource(dummySession, resourceParms, true);

expect(response).toEqual(okContent2Records);
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should not fail when failOnNoData is false and data is not returned", async () => {

getExpectStringMock.mockClear();
getExpectStringMock.mockResolvedValue(nodataXmlResponse);

endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/REGION1`;
try {
response = await getResource(dummySession, resourceParms, false);
} catch (err) {
error = err;
}

expect(error).toBeUndefined();
expect(response).toBeDefined();
expect(response).toEqual(nodataContent);
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
});
});

0 comments on commit ec5b1e2

Please sign in to comment.