use of api.support.builders.FixedDueDateSchedulesBuilder in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified.
@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified() {
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));
final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").fixed(fixedDueDateSchedulesId).renewFromCurrentDueDate();
final IndividualResource loanPolicy = loanPoliciesFixture.create(currentDueDateRollingPolicy);
UUID dueDateLimitedPolicyId = loanPolicy.getId();
use(currentDueDateRollingPolicy);
loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
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));
// TODO loanpolicyname is not stored, possible bug?
assertThat("last loan policy should be stored", renewedLoan.getString("loanPolicyId"), is(dueDateLimitedPolicyId.toString()));
assertThat("due date should be 2 months from previous due date", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
smallAngryPlanet = itemsClient.get(smallAngryPlanet);
assertThat(smallAngryPlanet, hasItemStatus(ItemBuilder.CHECKED_OUT));
}
use of api.support.builders.FixedDueDateSchedulesBuilder 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.FixedDueDateSchedulesBuilder 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)));
}
use of api.support.builders.FixedDueDateSchedulesBuilder 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.FixedDueDateSchedulesBuilder 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);
}
Aggregations