use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method cannotRenewWhenNonRenewableFixedPolicy.
@Test
void cannotRenewWhenNonRenewableFixedPolicy() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
// TODO: Replace with better example when can fix system date
FixedDueDateSchedulesBuilder todayOnlySchedules = new FixedDueDateSchedulesBuilder().withName("Today Only Due Date Limit").addSchedule(FixedDueDateSchedule.todayOnly());
final UUID todayOnlySchedulesId = loanPoliciesFixture.createSchedule(todayOnlySchedules).getId();
LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Non Renewable Policy").fixed(todayOnlySchedulesId).notRenewable();
UUID notRenewablePolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
use(limitedRenewalsPolicy);
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, getZonedDateTime());
final Response response = attemptRenewal(smallAngryPlanet, jessica);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan is not renewable"), hasLoanPolicyIdParameter(notRenewablePolicyId), hasLoanPolicyNameParameter("Non Renewable Policy"))));
assertThat(getOverridableBlockNames(response), hasItem("renewalDueDateRequiredBlock"));
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method cannotRenewWhenRenewalLimitReached.
@Test
void cannotRenewWhenRenewalLimitReached() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Limited Renewals Policy").rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
UUID limitedRenewalsPolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
use(limitedRenewalsPolicy);
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
renew(smallAngryPlanet, jessica);
renew(smallAngryPlanet, jessica);
renew(smallAngryPlanet, jessica);
final Response response = attemptRenewal(smallAngryPlanet, jessica);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan at maximum renewal number"), hasLoanPolicyIdParameter(limitedRenewalsPolicyId), hasLoanPolicyNameParameter("Limited Renewals Policy"))));
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method canRenewFromCurrentDueDateWhenDueDateFallsWithinRangeOfAlternateDueDateLimit.
@Test
void canRenewFromCurrentDueDateWhenDueDateFallsWithinRangeOfAlternateDueDateLimit() {
FixedDueDateSchedulesBuilder dueDateLimitSchedule = new FixedDueDateSchedulesBuilder().withName("Alternate Due Date Limit").addSchedule(wholeMonth(2019, 3)).addSchedule(wholeMonth(2019, 5));
ZonedDateTime expectedDueDate = ZonedDateTime.of(2019, 5, 31, 23, 59, 59, 0, UTC);
final UUID dueDateLimitScheduleId = loanPoliciesFixture.createSchedule(dueDateLimitSchedule).getId();
LoanPolicyBuilder dueDateLimitedPolicy = new LoanPolicyBuilder().withName("Due Date Limited Rolling Policy").rolling(Period.months(1)).renewFromCurrentDueDate().renewWith(Period.months(1), dueDateLimitScheduleId);
final IndividualResource loanPolicy = loanPoliciesFixture.create(dueDateLimitedPolicy);
UUID dueDateLimitedPolicyId = loanPolicy.getId();
checkRenewalAttempt(expectedDueDate, dueDateLimitedPolicyId);
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method renewalNoticeIsNotSentWhenPatronNoticeRequestFails.
@Test
void renewalNoticeIsNotSentWhenPatronNoticeRequestFails() {
UUID renewalTemplateId = UUID.randomUUID();
JsonObject renewalNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(renewalTemplateId).withRenewalEvent().create();
JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
NoticePolicyBuilder policyWithRenewalNotice = new NoticePolicyBuilder().withName("Policy with renewal notice").withLoanNotices(Arrays.asList(renewalNoticeConfiguration, checkInNoticeConfiguration));
LoanPolicyBuilder limitedRenewalsLoanPolicy = new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(Period.months(1)).limitedRenewals(3);
use(limitedRenewalsLoanPolicy, policyWithRenewalNotice);
ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), StringUtils.EMPTY, "ItemPrefix", "ItemSuffix", "");
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
final IndividualResource steve = usersFixture.steve();
final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
loansFixture.renewLoan(smallAngryPlanet, steve);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest.
@Test
void multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Limited Renewals Policy").rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
UUID limitedRenewalsPolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
use(limitedRenewalsPolicy);
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
renew(smallAngryPlanet, jessica);
renew(smallAngryPlanet, jessica);
renew(smallAngryPlanet, jessica);
requestsFixture.place(new RequestBuilder().recall().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
final Response response = attemptRenewal(smallAngryPlanet, jessica);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan at maximum renewal number"), hasLoanPolicyIdParameter(limitedRenewalsPolicyId), hasLoanPolicyNameParameter("Limited Renewals Policy"))));
assertThat(response.getJson(), hasErrorWith(hasMessage("items cannot be renewed when there is an active recall request")));
}
Aggregations