use of api.support.http.UserResource in project mod-circulation by folio-org.
the class CheckOutByBarcodeTests method cannotCheckoutItemWhenTitleLevelPageRequestExistsForSameItem.
@ParameterizedTest
@CsvSource({ "Item, Item", "Item, Title", "Title, Item", "Title, Title" })
void cannotCheckoutItemWhenTitleLevelPageRequestExistsForSameItem(String firstRequestLevel, String secondRequestLevel) {
configurationsFixture.enableTlrFeature();
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
ItemResource randomItem = items.stream().findAny().orElseThrow();
IndividualResource firstRequest = placeRequest(firstRequestLevel, randomItem, usersFixture.steve());
String requestedItemId = firstRequest.getJson().getString("itemId");
// If first request level is Title, the item for it is selected randomly among Available items
// of the instance. So for second request we have to find the other (Available) item.
ItemResource itemForSecondRequest = items.stream().filter(not(item -> item.getId().toString().equals(requestedItemId))).findAny().orElseThrow(() -> new AssertionError("Failed to find non-requested item"));
placeRequest(secondRequestLevel, itemForSecondRequest, usersFixture.jessica());
UserResource borrower = usersFixture.james();
Response response = checkOutFixture.attemptCheckOutByBarcode(itemForSecondRequest, borrower);
assertThat(response.getStatusCode(), is(422));
assertThat(response.getJson(), hasErrorWith(allOf(hasUserBarcodeParameter(borrower), hasMessage(String.format("The Long Way to a Small, Angry Planet (Barcode: %s) cannot be checked out to user " + "Rodwell, James because it has been requested by another patron", itemForSecondRequest.getBarcode())))));
}
use of api.support.http.UserResource in project mod-circulation by folio-org.
the class CheckInByBarcodeTests method requestAwaitingPickupNoticeIsNotSentWhenPatronNoticeRequestsFails.
@Test
void requestAwaitingPickupNoticeIsNotSentWhenPatronNoticeRequestsFails() {
JsonObject availableNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withAvailableEvent().create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with available notice").withLoanNotices(Collections.singletonList(availableNoticeConfig));
use(noticePolicy);
ItemResource requestedItem = itemsFixture.basedUponNod();
UUID pickupServicePointId = servicePointsFixture.cd1().getId();
ZonedDateTime requestDate = ZonedDateTime.of(2019, 10, 9, 10, 0, 0, 0, UTC);
UserResource steve = usersFixture.steve();
requestsFixture.place(new RequestBuilder().page().forItem(requestedItem).by(steve).withPickupServicePointId(pickupServicePointId).withRequestDate(requestDate));
ZonedDateTime checkInDate = ZonedDateTime.of(2019, 10, 10, 12, 30, 0, 0, UTC);
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
checkInFixture.checkInByBarcode(requestedItem, checkInDate, pickupServicePointId);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
use of api.support.http.UserResource in project mod-circulation by folio-org.
the class CheckInByBarcodeTests method patronNoticeIsSentForRequestAwaitingPickupWhenPreviousRequestWasClosed.
private void patronNoticeIsSentForRequestAwaitingPickupWhenPreviousRequestWasClosed(RequestStatus firstRequestUpdateStatus) {
UUID requestAwaitingPickupTemplateId = UUID.randomUUID();
UUID pickupServicePointId = servicePointsFixture.cd1().getId();
use(new NoticePolicyBuilder().withName("Policy with Request Awaiting Pickup notice").withLoanNotices(Collections.singletonList(new NoticeConfigurationBuilder().withTemplateId(requestAwaitingPickupTemplateId).withAvailableEvent().create())));
ZonedDateTime requestDate = ZonedDateTime.of(2020, 11, 30, 13, 30, 0, 0, UTC);
ZonedDateTime requestExpirationDateTime = requestDate.plusMonths(1);
LocalDate requestExpirationDate = toLocalDate(requestExpirationDateTime);
ZonedDateTime firstCheckInDate = requestDate.plusDays(1);
ZonedDateTime secondCheckInDate = firstCheckInDate.plusDays(1);
ItemResource item = itemsFixture.basedUponNod();
// create two requests for the same item
UserResource firstRequester = usersFixture.steve();
IndividualResource firstRequest = requestsFixture.place(new RequestBuilder().page().forItem(item).by(firstRequester).withPickupServicePointId(pickupServicePointId).withRequestDate(requestDate).withRequestExpiration(requestExpirationDate).withHoldShelfExpiration(requestExpirationDate));
UserResource secondRequester = usersFixture.james();
IndividualResource secondRequest = requestsFixture.place(new RequestBuilder().hold().forItem(item).by(secondRequester).withPickupServicePointId(pickupServicePointId).withRequestDate(requestDate).withRequestExpiration(requestExpirationDate).withHoldShelfExpiration(requestExpirationDate));
// verify that both requests are "Open - Not yet filled"
assertThatRequestStatusIs(firstRequest.getId(), RequestStatus.OPEN_NOT_YET_FILLED);
assertThatRequestStatusIs(secondRequest.getId(), RequestStatus.OPEN_NOT_YET_FILLED);
// check the item in
checkInFixture.checkInByBarcode(item, firstCheckInDate, pickupServicePointId);
// check that both item and first request are awaiting pickup
assertThatItemStatusIs(item.getId(), ItemStatus.AWAITING_PICKUP);
assertThatRequestStatusIs(firstRequest.getId(), RequestStatus.OPEN_AWAITING_PICKUP);
// verify that Request Awaiting Pickup notice was sent for first request
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
checkPatronNoticeEvent(firstRequest, firstRequester, item, requestAwaitingPickupTemplateId);
clearSentPatronNoticesAndPubsubEvents();
// Check-in again and verify that same notice is not sent repeatedly
checkInFixture.checkInByBarcode(item, firstCheckInDate, pickupServicePointId);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
switch(firstRequestUpdateStatus) {
case CLOSED_CANCELLED:
requestsFixture.cancelRequest(firstRequest);
break;
// for purposes of this test request position has to be changed manually
case CLOSED_UNFILLED:
requestsFixture.expireRequest(firstRequest);
updateRequestPosition(secondRequest, 1);
break;
case CLOSED_PICKUP_EXPIRED:
requestsFixture.expireRequestPickup(firstRequest);
updateRequestPosition(secondRequest, 1);
break;
default:
fail("Unsupported request status");
}
// verify that first request was closed, and that item is still awaiting pickup
assertThatItemStatusIs(item.getId(), ItemStatus.AWAITING_PICKUP);
assertThatRequestStatusIs(firstRequest.getId(), firstRequestUpdateStatus);
// check the item in again
checkInFixture.checkInByBarcode(item, secondCheckInDate, pickupServicePointId);
// verify that item is still awaiting pickup, and that second request is now awaiting pickup
assertThatItemStatusIs(item.getId(), ItemStatus.AWAITING_PICKUP);
assertThatRequestStatusIs(secondRequest.getId(), RequestStatus.OPEN_AWAITING_PICKUP);
// verify that Request Awaiting Pickup notice was sent to second requester
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
checkPatronNoticeEvent(secondRequest, secondRequester, item, requestAwaitingPickupTemplateId);
clearSentPatronNoticesAndPubsubEvents();
// Check-in again and verify that same notice is not sent repeatedly
checkInFixture.checkInByBarcode(item, secondCheckInDate, pickupServicePointId);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.http.UserResource in project mod-circulation by folio-org.
the class CheckInByBarcodeTests method availableNoticeIsSentUponCheckInWhenRequesterBarcodeWasChanged.
@Test
void availableNoticeIsSentUponCheckInWhenRequesterBarcodeWasChanged() {
UUID templateId = UUID.randomUUID();
JsonObject availableNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(templateId).withAvailableEvent().create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Test policy").withLoanNotices(Collections.singletonList(availableNoticeConfig));
use(noticePolicy);
ItemResource requestedItem = itemsFixture.basedUponNod();
UUID pickupServicePointId = servicePointsFixture.cd1().getId();
UserResource requester = usersFixture.steve();
ZonedDateTime requestDate = ZonedDateTime.of(2019, 10, 9, 10, 0, 0, 0, UTC);
requestsFixture.place(new RequestBuilder().page().forItem(requestedItem).by(requester).withPickupServicePointId(pickupServicePointId).withRequestDate(requestDate));
ZonedDateTime checkInDate = ZonedDateTime.of(2019, 10, 10, 12, 30, 0, 0, UTC);
JsonObject updatedRequesterJson = requester.getJson().put("barcode", "updated_barcode");
usersClient.replace(requester.getId(), updatedRequesterJson);
checkInFixture.checkInByBarcode(requestedItem, checkInDate, pickupServicePointId);
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
assertThat(FakeModNotify.getFirstSentPatronNotice(), hasEmailNoticeProperties(requester.getId(), templateId, getUserContextMatchers(updatedRequesterJson)));
}
use of api.support.http.UserResource in project mod-circulation by folio-org.
the class RequestsAPICreationTests method shouldFailToOverridePatronBlockWhenUserHasNoPermissionsAndNonOverridableErrorOccurs.
@Test
void shouldFailToOverridePatronBlockWhenUserHasNoPermissionsAndNonOverridableErrorOccurs() {
UserResource inactiveSteve = usersFixture.steve(UserBuilder::inactive);
UUID userId = inactiveSteve.getId();
userManualBlocksFixture.createRequestsManualPatronBlockForUser(userId);
Response response = attemptCreateRequestThroughPatronBlockOverride(userId, buildOkapiHeadersWithPermissions(CREATE_REQUEST_PERMISSION));
assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY));
assertThat(response.getJson(), hasErrors(2));
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Inactive users cannot make requests"), hasUUIDParameter("requesterId", userId))));
assertThat(getErrorsFromResponse(response), hasItem(isInsufficientPermissionsToOverridePatronBlockError()));
}
Aggregations