use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy.
@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy() {
final ZonedDateTime renewalDate = ClockUtil.getZonedDateTime();
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
final UUID loanId = loan.getId();
FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder().withName("Fixed Due Date Schedule").addSchedule(wholeMonth(2018, 2)).addSchedule(forDay(renewalDate));
final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").rolling(Period.months(2)).limitedBySchedule(fixedDueDateSchedulesId).renewFromCurrentDueDate();
use(currentDueDateRollingPolicy);
Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("renewal date falls outside of date ranges in the loan policy"))));
final ZonedDateTime newDueDate = loanDueDate.plusWeeks(3).plusMonths(2);
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
assertThat(renewedLoan.getString("id"), is(loanId.toString()));
verifyRenewedLoan(smallAngryPlanet, jessica, renewedLoan);
assertThat("renewal count should be incremented", renewedLoan.getInteger("renewalCount"), is(1));
assertThat("due date should be 1st of Feb 2019", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method cannotOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsNotSpecified.
@Test
void cannotOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsNotSpecified() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
LoanPolicyBuilder notLoanablePolicy = new LoanPolicyBuilder().withName("Not Loanable Policy").withLoanable(false);
createLoanPolicyAndSetAsFallback(notLoanablePolicy);
JsonObject renewalResponse = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica).getJson();
assertThat(renewalResponse, hasErrorWith(allOf(hasMessage(ITEM_IS_NOT_LOANABLE_MESSAGE))));
Response response = loansFixture.attemptOverride(smallAngryPlanet, jessica, OVERRIDE_COMMENT, null);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("New due date must be specified when due date calculation fails"))));
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsNotRenewableAndNewDueDateIsNotSpecified.
@Test
void canOverrideRenewalWhenItemIsNotRenewableAndNewDueDateIsNotSpecified() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
LoanPolicyBuilder nonRenewablePolicy = new LoanPolicyBuilder().withName("Non Renewable Policy").rolling(Period.days(2)).notRenewable();
use(nonRenewablePolicy);
loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
Response response = loansFixture.attemptOverride(smallAngryPlanet, jessica, OVERRIDE_COMMENT, null);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("New due date must be specified when due date calculation fails"))));
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method canRenewLoanWithAnotherLoanPolicyName.
@Test
void canRenewLoanWithAnotherLoanPolicyName() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
final String policyName = "Limited Renewals Policy";
LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName(policyName).rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
final IndividualResource loanPolicyResponse = loanPoliciesFixture.create(limitedRenewalsPolicy);
IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2019, 4, 21, 11, 21, 43, 0, UTC));
loanHasLoanPolicyProperties(loan.getJson(), loanPoliciesFixture.canCirculateRolling());
use(limitedRenewalsPolicy);
loan = renew(smallAngryPlanet, jessica);
loanHasLoanPolicyProperties(loan.getJson(), loanPolicyResponse);
}
use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method canRenewUsingAlternateDueDateLimitedRollingLoanPolicy.
@Test
void canRenewUsingAlternateDueDateLimitedRollingLoanPolicy() {
FixedDueDateSchedulesBuilder dueDateLimitSchedule = new FixedDueDateSchedulesBuilder().withName("March Only Due Date Limit").addSchedule(wholeMonth(2018, 3));
final UUID dueDateLimitScheduleId = loanPoliciesFixture.createSchedule(dueDateLimitSchedule).getId();
LoanPolicyBuilder dueDateLimitedPolicy = new LoanPolicyBuilder().withName("Due Date Limited Rolling Policy").rolling(Period.weeks(3)).renewFromCurrentDueDate().renewWith(Period.days(8), dueDateLimitScheduleId);
final IndividualResource loanPolicy = loanPoliciesFixture.create(dueDateLimitedPolicy);
use(dueDateLimitedPolicy);
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource steve = usersFixture.steve();
final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 4, 11, 43, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
final IndividualResource response = renew(smallAngryPlanet, steve);
final JsonObject loan = response.getJson();
loanHasLoanPolicyProperties(loan, loanPolicy);
assertThat("due date should be limited by schedule", loan.getString("dueDate"), isEquivalentTo(ZonedDateTime.of(2018, 3, 31, 23, 59, 59, 0, UTC)));
}
Aggregations