use of api.support.http.ItemResource in project mod-circulation by folio-org.
the class RequestsAPIUpdatingTests method cancellationReasonNameIsUsedAsReasonForCancellationTokenWhenPublicDescriptionIsNotPresent.
@Test
void cancellationReasonNameIsUsedAsReasonForCancellationTokenWhenPublicDescriptionIsNotPresent() {
UUID requestCancellationTemplateId = UUID.randomUUID();
JsonObject requestCancellationConfiguration = new NoticeConfigurationBuilder().withTemplateId(requestCancellationTemplateId).withEventType(REQUEST_CANCELLATION).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with request cancellation notice").withLoanNotices(Collections.singletonList(requestCancellationConfiguration));
useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
final ItemResource temeraire = itemsFixture.basedUponTemeraire();
final IndividualResource requester = usersFixture.steve();
ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
final IndividualResource exampleServicePoint = servicePointsFixture.cd1();
IndividualResource createdRequest = requestsClient.create(new RequestBuilder().page().withRequestDate(requestDate).forItem(temeraire).by(requester).fulfilToHoldShelf().withPickupServicePointId(exampleServicePoint.getId()).withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)));
final IndividualResource courseReserves = cancellationReasonsFixture.courseReserves();
JsonObject updatedRequest = RequestBuilder.from(createdRequest).cancelled().withCancellationReasonId(courseReserves.getId()).withCancellationAdditionalInformation("Cancellation info").create();
requestsClient.replace(createdRequest.getId(), updatedRequest);
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(requester));
noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(temeraire, true));
noticeContextMatchers.putAll(TemplateContextMatchers.getRequestContextMatchers(updatedRequest));
noticeContextMatchers.putAll(TemplateContextMatchers.getCancelledRequestContextMatchers(updatedRequest));
noticeContextMatchers.put("request.reasonForCancellation", is(courseReserves.getJson().getString(CANCELLATION_REASON_NAME)));
assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(requester.getId(), requestCancellationTemplateId, noticeContextMatchers)));
}
use of api.support.http.ItemResource in project mod-circulation by folio-org.
the class RequestsAPIUpdatingTests method eventsShouldBePublished.
@Test
void eventsShouldBePublished() {
final ItemResource temeraire = itemsFixture.basedUponTemeraire();
IndividualResource loan = checkOutFixture.checkOutByBarcode(temeraire);
final IndividualResource steve = usersFixture.steve();
ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
final IndividualResource exampleServicePoint = servicePointsFixture.cd1();
IndividualResource createdRequest = requestsClient.create(new RequestBuilder().recall().withRequestDate(requestDate).forItem(temeraire).by(steve).fulfilToHoldShelf().withPickupServicePointId(exampleServicePoint.getId()).withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)));
final IndividualResource charlotte = usersFixture.charlotte();
requestsClient.replace(createdRequest.getId(), RequestBuilder.from(createdRequest).hold().by(charlotte).withTags(new RequestBuilder.Tags(Arrays.asList("new", "important"))));
Response response = loansClient.getById(loan.getId());
JsonObject updatedLoan = response.getJson();
// There should be seven events published - for "check out", for "log event: check out",
// for "log event: request created", for "log event: request updated" for "recall" and for "replace"
// and one log events for loans
final var publishedEvents = Awaitility.await().atMost(1, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(9));
final var requestCreatedLogEvent = publishedEvents.findFirst(byLogEventType(REQUEST_CREATED.value()));
final var requestUpdatedLogEvent = publishedEvents.findFirst(byLogEventType(REQUEST_UPDATED.value()));
final var dueDateChangedEvent = publishedEvents.findFirst(byEventType(LOAN_DUE_DATE_CHANGED.name()));
Request requestCreatedFromEventPayload = getRequestFromPayload(requestCreatedLogEvent, "created");
assertThat(requestCreatedFromEventPayload, notNullValue());
Request originalCreatedFromEventPayload = getRequestFromPayload(requestUpdatedLogEvent, "original");
Request updatedCreatedFromEventPayload = getRequestFromPayload(requestUpdatedLogEvent, "updated");
assertThat(requestCreatedFromEventPayload.getRequestType(), equalTo(originalCreatedFromEventPayload.getRequestType()));
assertThat(originalCreatedFromEventPayload.getRequestType(), not(equalTo(updatedCreatedFromEventPayload.getRequestType())));
assertThat(dueDateChangedEvent, isValidLoanDueDateChangedEvent(updatedLoan));
}
use of api.support.http.ItemResource in project mod-circulation by folio-org.
the class RequestsAPIUpdatingTests method cannotUpdatePatronComments.
@Test
void cannotUpdatePatronComments() {
final ItemResource temeraire = itemsFixture.basedUponTemeraire();
final IndividualResource steve = usersFixture.steve();
final IndividualResource createdRequest = requestsClient.create(new RequestBuilder().page().withRequestDate(ClockUtil.getZonedDateTime()).forItem(temeraire).by(steve).fulfilToHoldShelf().withPatronComments("Original patron comments").withPickupServicePointId(servicePointsFixture.cd1().getId()));
final var replaceResponse = requestsClient.attemptReplace(createdRequest.getId(), RequestBuilder.from(createdRequest).withPatronComments("updated patron comments"));
assertThat(replaceResponse.getJson(), hasErrorWith(allOf(hasMessage("Patron comments are not allowed to change"), hasParameter("existingPatronComments", "Original patron comments"))));
}
use of api.support.http.ItemResource in project mod-circulation by folio-org.
the class PageRequestWorkflowTests method itemCannotBeCheckedOutToOtherPatronWhenItemIsPagedAndNotYetBeingFulfilled.
@Test
void itemCannotBeCheckedOutToOtherPatronWhenItemIsPagedAndNotYetBeingFulfilled() {
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource jessica = usersFixture.jessica();
IndividualResource rebecca = usersFixture.rebecca();
IndividualResource requestByJessica = requestsFixture.place(new RequestBuilder().page().fulfilToHoldShelf().withItemId(smallAngryPlanet.getId()).withInstanceId(smallAngryPlanet.getInstanceId()).withRequestDate(ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC)).withRequesterId(jessica.getId()).withPickupServicePointId(servicePointsFixture.cd1().getId()));
Response response = checkOutFixture.attemptCheckOutByBarcode(smallAngryPlanet, rebecca);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("The Long Way to a Small, Angry Planet (Barcode: 036000291452) " + "cannot be checked out to user Stuart, Rebecca " + "because it has been requested by another patron"), hasParameter("userBarcode", rebecca.getJson().getString("barcode")))));
Response getByIdResponse = requestsClient.getById(requestByJessica.getId());
assertThat(getByIdResponse, hasStatus(HTTP_OK));
assertThat(getByIdResponse.getJson().getString("status"), is(OPEN_NOT_YET_FILLED));
IndividualResource pagedSmallAngryPlanet = itemsClient.get(smallAngryPlanet);
assertThat(pagedSmallAngryPlanet, hasItemStatus(PAGED));
}
use of api.support.http.ItemResource in project mod-circulation by folio-org.
the class HoldShelfFulfillmentTests method canBeCheckedOutToPatronRequestingTitleWhenReadyForPickup.
@Test
void canBeCheckedOutToPatronRequestingTitleWhenReadyForPickup() {
configurationsFixture.enableTlrFeature();
final IndividualResource pickupServicePoint = servicePointsFixture.cd1();
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource james = usersFixture.james();
IndividualResource jessica = usersFixture.jessica();
checkOutFixture.checkOutByBarcode(smallAngryPlanet, james);
IndividualResource requestByJessica = requestsFixture.placeTitleLevelHoldShelfRequest(smallAngryPlanet.getInstanceId(), jessica, ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC), pickupServicePoint.getId());
checkInFixture.checkInByBarcode(smallAngryPlanet, ClockUtil.getZonedDateTime(), pickupServicePoint.getId());
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica);
Response request = requestsClient.getById(requestByJessica.getId());
assertThat(request.getJson(), isTitleLevel());
assertThat(request.getJson().getString("status"), is(CLOSED_FILLED));
assertThat(itemsClient.get(smallAngryPlanet), hasItemStatus(CHECKED_OUT));
}
Aggregations