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);
}
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()))));
}
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));
}
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));
}
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));
}
Aggregations