From bca2c8db3788ce25dd74a4899ca1af999b72c470 Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Thu, 14 Dec 2023 18:32:18 +0530 Subject: [PATCH] UICIRCLOG-149 Adding test cases --- .../builder/service/LogRecordBuilder.java | 2 +- .../rest/impl/CirculationLogsImplApiTest.java | 16 ++++++++++++++- .../org/folio/utils/TenantApiTestUtil.java | 3 ++- .../src/test/resources/mock_content.json | 11 ++++++++++ .../resources/mocks/circulation-item.json | 4 ++++ ...ee_fine_billed_automated_virtual_item.json | 20 +++++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 mod-audit-server/src/test/resources/mocks/circulation-item.json create mode 100644 mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json diff --git a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java index ffd06a68..6cd0b192 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java @@ -206,7 +206,7 @@ private void fetchUserPersonal(JsonObject payload, User user) { public CompletableFuture fetchItemDetails(JsonObject payload) { return handleGetRequest(String.format(URL_WITH_ID_PATTERN, ITEMS_URL, getProperty(payload, ITEM_ID))) - .thenCompose(itemJson -> itemJson != null ? CompletableFuture.completedFuture(itemJson) : + .thenCompose(itemJson -> nonNull(itemJson) ? CompletableFuture.completedFuture(itemJson) : handleGetRequest(String.format(URL_WITH_ID_PATTERN, CIRCULATION_ITEM_URL, getProperty(payload, ITEM_ID)))) .thenCompose(itemJson -> addItemData(payload, itemJson)) .thenCompose(json -> diff --git a/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java b/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java index 7865d7d5..ce39fe8a 100644 --- a/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java +++ b/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java @@ -48,7 +48,7 @@ void getCirculationAuditLogRecordsNoFilter() { logger.info("Get circulation audit log records: no filter"); given().headers(HEADERS).get(CIRCULATION_LOGS_ENDPOINT) .then().log().all().statusCode(200) - .assertThat().body("totalRecords", equalTo(25)); + .assertThat().body("totalRecords", equalTo(26)); } @Test @@ -115,6 +115,20 @@ void anonymizeLoanShouldRemoveUserDataFromRelatedRecords() { .and().body("logRecords[5].linkToIds.userId", is(emptyOrNullString())); } + @Test + void getFeeFineRelatedRecordOfVirtualItem() { + // For virtual item, holdingsId and instanceId needs to be present, then only FE validation will work. + // This record is already posted in beforeAll method so directly assert it using get endpoint with virtual item ID. + given().headers(HEADERS).get(CIRCULATION_LOGS_ENDPOINT + "?query=(items=100d10bf-2f06-4aa0-be15-0b95b2d9f9e4)") + .then().log().all().statusCode(200) + .assertThat() + .body("totalRecords", equalTo(1)) + .body("logRecords[0].items[0].itemBarcode", is("virtualItem")) + .and().body("logRecords[0].items[0].itemId", is("100d10bf-2f06-4aa0-be15-0b95b2d9f9e4")) + .and().body("logRecords[0].items[0].instanceId", is("5bf370e0-8cca-4d9c-82e4-5170ab2a0a39")) + .and().body("logRecords[0].items[0].holdingId", is("e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19")); + } + @Test void getCirculationAuditLogRecordsMalformedQuery() { logger.info("get circulation audit log records: malformed query"); diff --git a/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java b/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java index 9428cc43..828a8e51 100644 --- a/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java +++ b/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java @@ -41,6 +41,7 @@ public class TenantApiTestUtil { public static final String MANUAL_BLOCK_UPDATED_PAYLOAD_JSON = "payloads/manual_block_updated.json"; public static final String MANUAL_BLOCK_DELETED_PAYLOAD_JSON = "payloads/manual_block_deleted.json"; public static final String FEE_FINE_PAYLOAD_JSON = "payloads/fee_fine_billed.json"; + public static final String FEE_FINE_VIRTUAL_ITEM_PAYLOAD_JSON = "payloads/fee_fine_billed_automated_virtual_item.json"; public static final String LOAN_PAYLOAD_JSON = "payloads/loan.json"; public static final String LOAN_ANONYMIZE_PAYLOAD_JSON = "payloads/anonymize_loan.json"; public static final String LOAN_AGE_TO_LOST_PAYLOAD_JSON = "payloads/loan_age_to_lost.json"; @@ -69,7 +70,7 @@ public class TenantApiTestUtil { public static final String ANONYMIZE_LOAN_CLOSED = "payloads/anonymize_loan_closed.json"; public static final List SAMPLES = Arrays.asList(CHECK_IN_PAYLOAD_JSON, CHECK_OUT_PAYLOAD_JSON, MANUAL_BLOCK_CREATED_PAYLOAD_JSON, MANUAL_BLOCK_UPDATED_PAYLOAD_JSON, MANUAL_BLOCK_DELETED_PAYLOAD_JSON, - FEE_FINE_PAYLOAD_JSON, LOAN_PAYLOAD_JSON, LOAN_AGE_TO_LOST_PAYLOAD_JSON, LOAN_WRONG_ACTION_JSON, LOAN_EMPTY_ACTION_JSON, NOTICE_PAYLOAD_JSON, + FEE_FINE_PAYLOAD_JSON, FEE_FINE_VIRTUAL_ITEM_PAYLOAD_JSON, LOAN_PAYLOAD_JSON, LOAN_AGE_TO_LOST_PAYLOAD_JSON, LOAN_WRONG_ACTION_JSON, LOAN_EMPTY_ACTION_JSON, NOTICE_PAYLOAD_JSON, REQUEST_CREATED_THROUGH_OVERRIDE_PAYLOAD_JSON, REQUEST_CREATED_PAYLOAD_JSON, REQUEST_EDITED_PAYLOAD_JSON, REQUEST_MOVED_PAYLOAD_JSON, REQUEST_REORDERED_PAYLOAD_JSON, REQUEST_CANCELLED_PAYLOAD_JSON, REQUEST_EXPIRED_PAYLOAD_JSON, ANONYMIZE_CHECK_OUT, ANONYMIZE_CHECK_IN, ANONYMIZE_LOAN_CLOSED); diff --git a/mod-audit-server/src/test/resources/mock_content.json b/mod-audit-server/src/test/resources/mock_content.json index 77a55be4..dc3eb051 100644 --- a/mod-audit-server/src/test/resources/mock_content.json +++ b/mod-audit-server/src/test/resources/mock_content.json @@ -88,6 +88,17 @@ "receivedPath": "mocks/item.json", "status": 200 }, + { + "url": "/inventory/items/100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "method": "GET", + "status": 404 + }, + { + "url": "/circulation-item/100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "method": "GET", + "receivedPath": "mocks/circulation-item.json", + "status": 200 + }, { "url": "/inventory/items/e038e283-4104-455d-80b7-e6d05ca4e5a7", "method": "GET", diff --git a/mod-audit-server/src/test/resources/mocks/circulation-item.json b/mod-audit-server/src/test/resources/mocks/circulation-item.json new file mode 100644 index 00000000..dccc3249 --- /dev/null +++ b/mod-audit-server/src/test/resources/mocks/circulation-item.json @@ -0,0 +1,4 @@ +{ + "barcode": "virtualItem", + "holdingsRecordId" : "e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19" +} diff --git a/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json new file mode 100644 index 00000000..e26b8979 --- /dev/null +++ b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json @@ -0,0 +1,20 @@ +{ + "logEventType":"FEE_FINE", + "payload": { + "userId":"6f36265e-722a-490a-b436-806e63af2ea7", + "userBarcode":"693787594998493", + "itemBarcode":"virtualItem", + "itemId":"100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "action":"Billed", + "comments": "Comments from Staff", + "date":"2020-10-15T12:17:38.627Z", + "servicePointId":"7c5abc9f-f3d7-4856-b8d7-6712462ca007", + "source":"ADMINISTRATOR, DIKU", + "feeFineId":"7ad9dfa0-6ee9-43ba-8db5-7a034ce05838", + "feeFineOwner":"sample owner", + "loanId":"0", + "automated":true, + "type":"manual charge", + "amount":10.0 + } +}