Search in sources :

Example 1 with ChangeDueDateRequestBuilder

use of api.support.builders.ChangeDueDateRequestBuilder in project mod-circulation by folio-org.

the class ChangeDueDateAPITests method changeDueDateNoticeIsNotSentWhenPatronNoticeRequestFails.

@Test
void changeDueDateNoticeIsNotSentWhenPatronNoticeRequestFails() {
    UUID templateId = UUID.randomUUID();
    JsonObject changeNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(templateId).withManualDueDateChangeEvent().create();
    JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
    IndividualResource noticePolicy = noticePoliciesFixture.create(new NoticePolicyBuilder().withName("Policy with manual due date change notice").withLoanNotices(Arrays.asList(changeNoticeConfiguration, checkInNoticeConfiguration)));
    int renewalLimit = 3;
    IndividualResource policyWithLimitedRenewals = loanPoliciesFixture.create(new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(months(1)).limitedRenewals(renewalLimit));
    useFallbackPolicies(policyWithLimitedRenewals.getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePolicy.getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), EMPTY, "ItemPrefix", "ItemSuffix", "");
    ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
    IndividualResource steve = usersFixture.steve();
    IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve);
    ZonedDateTime newDueDate = dueDate.plusWeeks(2);
    FakeModNotify.setFailPatronNoticesWithBadRequest(true);
    changeDueDateFixture.changeDueDate(new ChangeDueDateRequestBuilder().forLoan(loan.getId()).withDueDate(newDueDate));
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : ItemBuilder(api.support.builders.ItemBuilder) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ChangeDueDateRequestBuilder

use of api.support.builders.ChangeDueDateRequestBuilder in project mod-circulation by folio-org.

the class ChangeDueDateAPITests method cannotChangeDueDateWhenLoanIsClosed.

@Test
void cannotChangeDueDateWhenLoanIsClosed() {
    final ZonedDateTime newDueDate = dueDate.plusDays(14);
    checkInFixture.checkInByBarcode(item);
    final Response response = changeDueDateFixture.attemptChangeDueDate(new ChangeDueDateRequestBuilder().forLoan(loan.getId()).withDueDate(newDueDate));
    assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY));
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Loan is closed"), hasUUIDParameter("loanId", loan.getId()))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ZonedDateTime(java.time.ZonedDateTime) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ChangeDueDateRequestBuilder

use of api.support.builders.ChangeDueDateRequestBuilder in project mod-circulation by folio-org.

the class ChangeDueDateAPITests method dueDateChangeShouldUnsetRenewalFlagValueWhenTlrFeatureDisabledOrNotConfigured.

@ParameterizedTest
@EnumSource(value = TlrFeatureStatus.class, names = { "DISABLED", "NOT_CONFIGURED" })
void dueDateChangeShouldUnsetRenewalFlagValueWhenTlrFeatureDisabledOrNotConfigured(TlrFeatureStatus tlrFeatureStatus) {
    IndividualResource loanPolicy = loanPoliciesFixture.create(new LoanPolicyBuilder().withName("loan policy").withRecallsMinimumGuaranteedLoanPeriod(org.folio.circulation.domain.policy.Period.weeks(2)).rolling(org.folio.circulation.domain.policy.Period.months(1)));
    useFallbackPolicies(loanPolicy.getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardDoNotCountClosed().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), EMPTY, "ItemPrefix", "ItemSuffix", "");
    ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
    IndividualResource steve = usersFixture.steve();
    IndividualResource initialLoan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve);
    ZonedDateTime initialDueDate = ZonedDateTime.parse(initialLoan.getJson().getString("dueDate"));
    UUID instanceId = smallAngryPlanet.getInstanceId();
    assertThat(initialLoan.getJson().containsKey("dueDateChangedByRecall"), equalTo(false));
    IndividualResource itemLevelRecall = requestsFixture.place(new RequestBuilder().recall().itemRequestLevel().withInstanceId(instanceId).forItem(smallAngryPlanet).by(usersFixture.charlotte()).fulfilToHoldShelf(servicePointsFixture.cd1()));
    Response recalledLoan = loansClient.getById(initialLoan.getId());
    assertThat(recalledLoan.getJson().getBoolean("dueDateChangedByRecall"), equalTo(true));
    configurationsFixture.enableTlrFeature();
    requestsClient.create(new RequestBuilder().recall().titleRequestLevel().withInstanceId(instanceId).withNoItemId().withNoHoldingsRecordId().withPickupServicePointId(servicePointsFixture.cd1().getId()).withRequesterId(usersFixture.jessica().getId()));
    requestsFixture.cancelRequest(itemLevelRecall);
    reconfigureTlrFeature(tlrFeatureStatus);
    final ZonedDateTime newDueDate = initialDueDate.plusMonths(1);
    changeDueDateFixture.changeDueDate(new ChangeDueDateRequestBuilder().forLoan(recalledLoan.getJson().getString("id")).withDueDate(newDueDate));
    JsonObject dueDateChangedLoan = loansClient.getById(initialLoan.getId()).getJson();
    assertThat(recalledLoan.getJson().containsKey("dueDateChangedByRecall"), equalTo(true));
    assertThat(dueDateChangedLoan.getBoolean("dueDateChangedByRecall"), equalTo(false));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ItemBuilder(api.support.builders.ItemBuilder) ClaimItemReturnedRequestBuilder(api.support.builders.ClaimItemReturnedRequestBuilder) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ChangeDueDateRequestBuilder

use of api.support.builders.ChangeDueDateRequestBuilder in project mod-circulation by folio-org.

the class ChangeDueDateAPITests method dueDateChangeShouldClearRenewalFlagWhenSetAndNoOpenRecallsInQueue.

@Test
void dueDateChangeShouldClearRenewalFlagWhenSetAndNoOpenRecallsInQueue() {
    IndividualResource loanPolicy = loanPoliciesFixture.create(new LoanPolicyBuilder().withName("loan policy").withRecallsMinimumGuaranteedLoanPeriod(weeks(2)).rolling(months(1)));
    useFallbackPolicies(loanPolicy.getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardDoNotCountClosed().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), EMPTY, "ItemPrefix", "ItemSuffix", "");
    ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
    IndividualResource steve = usersFixture.steve();
    ZonedDateTime loanDate = ZonedDateTime.of(2021, 11, 20, 13, 25, 46, 0, UTC);
    IndividualResource initialLoan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve, loanDate);
    ZonedDateTime initialDueDate = ZonedDateTime.parse(initialLoan.getJson().getString("dueDate"));
    assertThat(initialLoan.getJson().containsKey("dueDateChangedByRecall"), equalTo(false));
    IndividualResource recall = requestsFixture.place(new RequestBuilder().recall().forItem(smallAngryPlanet).by(usersFixture.charlotte()).fulfilToHoldShelf(servicePointsFixture.cd1()));
    Response recalledLoan = loansClient.getById(initialLoan.getId());
    requestsFixture.cancelRequest(recall);
    final ZonedDateTime newDueDate = initialDueDate.plusMonths(1);
    changeDueDateFixture.changeDueDate(new ChangeDueDateRequestBuilder().forLoan(recalledLoan.getJson().getString("id")).withDueDate(newDueDate));
    JsonObject dueDateChangedLoan = loansClient.getById(initialLoan.getId()).getJson();
    assertThat(dueDateChangedLoan.getBoolean("dueDateChangedByRecall"), equalTo(false));
    assertThat("due date should be provided new due date", dueDateChangedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ItemBuilder(api.support.builders.ItemBuilder) ClaimItemReturnedRequestBuilder(api.support.builders.ClaimItemReturnedRequestBuilder) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ChangeDueDateRequestBuilder

use of api.support.builders.ChangeDueDateRequestBuilder in project mod-circulation by folio-org.

the class ChangeDueDateAPITests method canChangeTheDueDate.

@Test
void canChangeTheDueDate() {
    final ZonedDateTime newDueDate = dueDate.plusDays(14);
    changeDueDateFixture.changeDueDate(new ChangeDueDateRequestBuilder().forLoan(loan.getId()).withDueDate(newDueDate));
    Response response = loansClient.getById(loan.getId());
    JsonObject updatedLoan = response.getJson();
    var description = new JsonObject(FakePubSub.getPublishedEvents().stream().filter(json -> json.getString("eventType").equals("LOG_RECORD") && json.getString("eventPayload").contains("LOAN")).collect(toList()).get(0).getString("eventPayload")).getJsonObject("payload").getString("description");
    assertThat(description, notNullValue());
    assertThat(description, containsString(formatDateTime(dueDate)));
    assertThat(description, containsString(formatDateTime(newDueDate)));
    assertThat("due date is not updated", updatedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ChangeDueDateRequestBuilder (api.support.builders.ChangeDueDateRequestBuilder)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 ZonedDateTime (java.time.ZonedDateTime)11 Test (org.junit.jupiter.api.Test)11 Response (org.folio.circulation.support.http.client.Response)10 JsonObject (io.vertx.core.json.JsonObject)8 ClaimItemReturnedRequestBuilder (api.support.builders.ClaimItemReturnedRequestBuilder)5 ItemBuilder (api.support.builders.ItemBuilder)5 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)5 IndividualResource (api.support.http.IndividualResource)5 ItemResource (api.support.http.ItemResource)5 RequestBuilder (api.support.builders.RequestBuilder)4 UUID (java.util.UUID)3 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)2 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 FakePubSub (api.support.fakes.FakePubSub)1 HashMap (java.util.HashMap)1 Matcher (org.hamcrest.Matcher)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1