Skip to content

Commit

Permalink
CIRC-1463 Renewing Items Does Not Change Due Date (#1071)
Browse files Browse the repository at this point in the history
* LoanPolicy adjustment

(cherry picked from commit 0543591)
  • Loading branch information
bisecomsergiy authored and viktor-draban committed Apr 15, 2022
1 parent f8b9610 commit 5784387
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public Optional<ZonedDateTime> getScheduleLimit(ZonedDateTime loanDate, boolean

if(isRolling(loansPolicy)) {
if(isRenewal) {
return getRenewalDueDateLimitSchedules().findDueDateFor(loanDate);
return getRenewalDueDateLimitSchedules().findDueDateFor(systemDate);
}
else {
return fixedDueDateSchedules.findDueDateFor(loanDate);
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/api/loans/RenewalAPITests.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static org.folio.circulation.support.utils.ClockUtil.getZonedDateTime;
import static org.folio.circulation.support.utils.DateFormatUtil.formatDateTime;
import static org.folio.circulation.support.utils.DateTimeUtil.atEndOfDay;
import static org.folio.circulation.support.utils.DateTimeUtil.atStartOfDay;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
Expand Down Expand Up @@ -1169,6 +1170,45 @@ void testRespectSelectedTimezoneForDueDateCalculations() {
renewedLoan.getString("dueDate"), isEquivalentTo(expectedDate));
}

@Test
void canRenewWhenSystemDateFallsWithinSecondLimitingDueDateSchedule() {
ZonedDateTime firstScheduleStart = atStartOfDay(getZonedDateTime().minusDays(10).withZoneSameLocal(UTC));
ZonedDateTime firstScheduleEndAndDueDate = atStartOfDay(getZonedDateTime().minusDays(3).withZoneSameLocal(UTC));
ZonedDateTime secondScheduleStart = atStartOfDay(getZonedDateTime().minusDays(2).withZoneSameLocal(UTC));
ZonedDateTime secondScheduleEndAndDueDate = atStartOfDay(getZonedDateTime().plusDays(5).withZoneSameLocal(UTC));

FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder()
.withName("Fixed Due Date Schedule")
.addSchedule(new FixedDueDateSchedule(firstScheduleStart, firstScheduleEndAndDueDate, firstScheduleEndAndDueDate))
.addSchedule(new FixedDueDateSchedule(secondScheduleStart, secondScheduleEndAndDueDate, secondScheduleEndAndDueDate));

UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();

LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder()
.withName("System Date Rolling Policy")
.rolling(Period.days(56))
.limitedBySchedule(fixedDueDateSchedulesId)
.renewWith(Period.days(7))
.renewFromSystemDate();

loanPoliciesFixture.create(currentDueDateRollingPolicy).getId();
use(currentDueDateRollingPolicy);

IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource jessica = usersFixture.jessica();

IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica,
getZonedDateTime().minusDays(5).withZoneSameLocal(UTC));
UUID loanId = loan.getId();

JsonObject renewedLoan = renew(smallAngryPlanet, jessica).getJson();

assertThat(renewedLoan.getString("id"), is(loanId.toString()));
assertThat("due date should be as per second fixed schedule",
renewedLoan.getString("dueDate"),
isEquivalentTo(secondScheduleEndAndDueDate));
}

@Test
void canRenewWhenCurrentDueDateFallsWithinLimitingDueDateSchedule() {
FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder()
Expand Down

0 comments on commit 5784387

Please sign in to comment.