Search in sources :

Example 96 with ItemResource

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)));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Matcher(org.hamcrest.Matcher) HashMap(java.util.HashMap) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 97 with ItemResource

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 98 with ItemResource

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"))));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 99 with ItemResource

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) RequestBuilder(api.support.builders.RequestBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 100 with ItemResource

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ItemResource (api.support.http.ItemResource)232 Test (org.junit.jupiter.api.Test)218 IndividualResource (api.support.http.IndividualResource)189 JsonObject (io.vertx.core.json.JsonObject)138 UUID (java.util.UUID)127 RequestBuilder (api.support.builders.RequestBuilder)117 Response (org.folio.circulation.support.http.client.Response)89 ZonedDateTime (java.time.ZonedDateTime)81 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)61 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)40 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)39 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)38 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)36 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)32 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)27 ItemBuilder (api.support.builders.ItemBuilder)21 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)13 UserResource (api.support.http.UserResource)13 HashMap (java.util.HashMap)13 Matcher (org.hamcrest.Matcher)13