diff --git a/src/main/java/org/folio/circulation/domain/UpdateItem.java b/src/main/java/org/folio/circulation/domain/UpdateItem.java index fe9df301db..9d8cc28ff7 100644 --- a/src/main/java/org/folio/circulation/domain/UpdateItem.java +++ b/src/main/java/org/folio/circulation/domain/UpdateItem.java @@ -164,7 +164,7 @@ private ItemStatus itemStatusOnRequestCreateOrUpdate( return (item.getStatus().equals(PAGED) && requestQueue.getRequests().isEmpty()) ? AVAILABLE - : type.equals(RequestType.PAGE) + : (item.getStatus().equals(AVAILABLE) && type.equals(RequestType.PAGE)) ? PAGED : item.getStatus(); } diff --git a/src/test/java/api/requests/scenarios/MoveRequestTests.java b/src/test/java/api/requests/scenarios/MoveRequestTests.java index 58c40e4df3..6cf90c46d8 100644 --- a/src/test/java/api/requests/scenarios/MoveRequestTests.java +++ b/src/test/java/api/requests/scenarios/MoveRequestTests.java @@ -704,4 +704,75 @@ private void retainsStoredSummaries(IndividualResource request) { assertThat("Updated request in queue should retain stored requester summary", request.getJson().containsKey("requester"), is(true)); } + + @Test + public void checkoutItemStatusDoesNotChangeOnPagedRequest() + throws MalformedURLException, + InterruptedException, + TimeoutException, + ExecutionException { + + final IndividualResource secondFloorEconomics = locationsFixture.secondFloorEconomics(); + final IndividualResource mezzanineDisplayCase = locationsFixture.mezzanineDisplayCase(); + + final IndividualResource itemCopyA = itemsFixture.basedUponTemeraire( + holdingBuilder -> holdingBuilder + .withPermanentLocation(secondFloorEconomics) + .withNoTemporaryLocation(), + itemBuilder -> itemBuilder + .withNoPermanentLocation() + .withNoTemporaryLocation() + .withBarcode("10203040506")); + + final IndividualResource itemCopyB = itemsFixture.basedUponTemeraire( + holdingBuilder -> holdingBuilder + .withPermanentLocation(mezzanineDisplayCase) + .withNoTemporaryLocation(), + itemBuilder -> itemBuilder + .withNoPermanentLocation() + .withNoTemporaryLocation() + .withBarcode("90806050402")); + + assertThat(itemCopyA.getJson().getJsonObject("status").getString("name"), is(ItemStatus.AVAILABLE.getValue())); + assertThat(itemCopyB.getJson().getJsonObject("status").getString("name"), is(ItemStatus.AVAILABLE.getValue())); + + IndividualResource james = usersFixture.james(); //cate + IndividualResource steve = usersFixture.steve(); //walker + IndividualResource jessica = usersFixture.jessica(); //McKenzie + + loansFixture.checkOutByBarcode(itemCopyA, james, DateTime.now(DateTimeZone.UTC)); + + assertThat(itemsClient.get(itemCopyA).getJson().getJsonObject("status").getString("name"), is(ItemStatus.CHECKED_OUT.getValue())); + + // Steve requests Item Copy B + IndividualResource stevesRequest = requestsFixture.placeHoldShelfRequest( + itemCopyB, steve, DateTime.now(DateTimeZone.UTC).minusHours(2), RequestType.PAGE.getValue()); + + assertThat(itemsClient.get(itemCopyB).getJson().getJsonObject("status").getString("name"), is(ItemStatus.PAGED.getValue())); + + // Jessica requests Item Copy A + IndividualResource jessicasRequest = requestsFixture.placeHoldShelfRequest( + itemCopyA, jessica, DateTime.now(DateTimeZone.UTC).minusHours(2), RequestType.RECALL.getValue()); + + requestsFixture.move(new MoveRequestBuilder( + stevesRequest.getId(), + itemCopyA.getId(), + RequestType.RECALL.getValue() + )); + + // Confirm Steves's request is first and item is AVAILABLE + stevesRequest = requestsClient.get(stevesRequest); + assertThat(stevesRequest.getJson().getInteger("position"), is(1)); + assertThat(itemsClient.get(itemCopyB).getJson().getJsonObject("status").getString("name"), is(ItemStatus.AVAILABLE.getValue())); + + requestsFixture.move(new MoveRequestBuilder( + jessicasRequest.getId(), + itemCopyB.getId() + )); + + // Ensure that itemCopyA is still CHECKED_OUT + assertThat(itemsClient.get(itemCopyA).getJson().getJsonObject("status").getString("name"), is(ItemStatus.CHECKED_OUT.getValue())); + + } + }