use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.
the class RequestsAPILoanRenewalTests method validationErrorWhenRenewalPeriodForHoldsSpecifiedForFixedPolicy.
@Test
void validationErrorWhenRenewalPeriodForHoldsSpecifiedForFixedPolicy() {
final ZonedDateTime from = getZonedDateTime().minusMonths(3);
final ZonedDateTime to = getZonedDateTime().plusMonths(3);
final ZonedDateTime dueDate = to.plusDays(15);
final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource rebecca = usersFixture.rebecca();
checkOutFixture.checkOutByBarcode(smallAngryPlanet, rebecca);
IndividualResource schedule = loanPoliciesFixture.createSchedule(new FixedDueDateSchedulesBuilder().withId(UUID.randomUUID()).withName("Can circulate schedule").withDescription("descr").addSchedule(new FixedDueDateSchedule(from, to, dueDate)));
JsonObject holds = new JsonObject().put("renewItemsWithRequest", true).put("alternateRenewalLoanPeriod", Period.weeks(10).asJson());
LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().fixed(schedule.getId()).withName("Fixed with holds").withDescription("Fixed policy with holds").withHolds(holds);
loanPoliciesFixture.create(loanPolicy);
useWithActiveNotice(loanPolicy);
requestsFixture.place(new RequestBuilder().hold().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, rebecca);
assertThat(response.getJson(), hasErrorWith(hasMessage("Item's loan policy has fixed profile but alternative renewal period for holds is specified")));
}
use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight.
@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(new FixedDueDateSchedule(ZonedDateTime.of(2020, 11, 1, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC))).create());
ZonedDateTime loanDate = ZonedDateTime.of(2020, 11, 2, 12, 30, 30, 0, UTC);
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
final var expectedInitialDueDate = ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC);
assertThat(calculationResult.succeeded(), is(true));
assertThat(calculationResult.value(), is(expectedInitialDueDate));
}
use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldUseMiddleScheduleAvailableWhenLoanDateFits.
@Test
void shouldUseMiddleScheduleAvailableWhenLoanDateFits() {
final FixedDueDateSchedule expectedSchedule = FixedDueDateSchedule.wholeMonth(2018, 2);
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(expectedSchedule).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 2, 27, 16, 23, 43, 0, UTC);
Result<Loan> result = renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
assertThat(result.value().getDueDate(), is(expectedSchedule.due));
}
use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnightAndTimeZoneIsNotUTC.
@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnightAndTimeZoneIsNotUTC() {
ZoneOffset zone = ZoneOffset.ofHours(4);
final ZonedDateTime fromDate = ZonedDateTime.of(2020, 11, 1, 0, 0, 0, 0, zone);
final ZonedDateTime toDate = ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, zone);
final ZonedDateTime loanDate = ZonedDateTime.of(2020, 11, 2, 12, 30, 30, 0, zone);
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(new FixedDueDateSchedule(fromDate, toDate, toDate)).create());
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
assertThat(calculationResult.value(), is(toDate));
}
use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseFirstScheduleAvailableWhenLoanDateFits.
@Test
void shouldUseFirstScheduleAvailableWhenLoanDateFits() {
final FixedDueDateSchedule expectedSchedule = FixedDueDateSchedule.wholeMonth(2018, 1);
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(expectedSchedule).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 1, 8, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
assertThat(calculationResult.value(), is(expectedSchedule.due));
}
Aggregations