From a2c310984e58b7afaab45f4c3a6783c70b01639e Mon Sep 17 00:00:00 2001 From: Andrew Twydell Date: Fri, 10 Jan 2025 14:15:28 +0000 Subject: [PATCH] unit test failOnNoData flag Signed-off-by: Andrew Twydell --- .../__unit__/cache/Cache.unit.test.ts | 10 ++--- .../__unit__/get/Get.resource.unit.test.ts | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts b/packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts index d9faaf38..ef803dc4 100644 --- a/packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts +++ b/packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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); }); }); }); diff --git a/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts b/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts index 53177b6c..6eddd558 100644 --- a/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts +++ b/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts @@ -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, []); }); }); });