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 0106224 commit a2c3109
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 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);
});
});
});
43 changes: 43 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 @@ -255,6 +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 a2c3109

Please sign in to comment.