Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIRC-1482 create test for overdue recall fine calculation when recall… #1074

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
73 changes: 73 additions & 0 deletions src/test/java/api/loans/CheckInByBarcodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static org.junit.jupiter.api.Assertions.fail;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Arrays;
Expand Down Expand Up @@ -1369,6 +1370,78 @@ void overdueFineCalculatedCorrectlyWhenHourlyFeeFinePolicyIsApplied() {
homeLocation.getJson().getString("name"), ownerId, feeFineId, 7.0));
}

@Test
void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreated() {
double maxOverdueFine = 5.0;
double maxOverdueRecallFine = 30.0;
double overdueRecallFine = 6.0;
configurationsFixture.enableTlrFeature();
useFallbackPolicies(
loanPoliciesFixture.create(new LoanPolicyBuilder()
.withId(UUID.randomUUID())
.withName("1 minute policy")
.withDescription("Can circulate item")
.rolling(Period.minutes(1))
.unlimitedRenewals()).getId(),
requestPoliciesFixture.allowAllRequestPolicy().getId(),
noticePoliciesFixture.activeNotice().getId(),
overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder()
.withId(UUID.randomUUID())
.withName("One per minute overdue fine and overdue recall fine policy")
.withCountClosed(true)
.withOverdueFine(
new JsonObject()
.put("quantity", 1.0)
.put("intervalId", "minute"))
.withMaxOverdueFine(maxOverdueFine)
.withOverdueRecallFine(new JsonObject()
.put("quantity", overdueRecallFine)
.put("intervalId", "minute"))
.withMaxOverdueRecallFine(maxOverdueRecallFine)
.withCountClosed(false)).getId(),
lostItemFeePoliciesFixture.facultyStandard().getId()
);
final IndividualResource homeLocation = locationsFixture.mainFloor();
final IndividualResource nod = itemsFixture.basedUponNod(item ->
item.withPermanentLocation(homeLocation.getId()));

LocalDate date = LocalDate.of(2020, 1, 18);
LocalTime time = LocalTime.of(18, 0, 0, 0);
ZonedDateTime checkOutDate = ZonedDateTime.of(date, time, UTC);
ZonedDateTime requestDate = ZonedDateTime.of(date.plusDays(1), time, UTC);
ZonedDateTime checkInDate = ZonedDateTime.of(date.plusDays(4), time, UTC);

checkOutFixture.checkOutByBarcode(nod, usersFixture.james(), checkOutDate);
requestsFixture.placeItemLevelHoldShelfRequest(
nod, usersFixture.steve(), requestDate, "Recall");

UUID ownerId = UUID.randomUUID();
feeFineOwnersClient.create(new FeeFineOwnerBuilder()
.withId(ownerId)
.withOwner("fee-fine-owner")
.withServicePointOwner(Collections.singletonList(new JsonObject()
.put("value", homeLocation.getJson().getString("primaryServicePoint")))));

UUID feeFineId = UUID.randomUUID();
feeFinesClient.create(new FeeFineBuilder()
.withId(feeFineId)
.withFeeFineType("Overdue fine")
.withOwnerId(ownerId)
.withAutomatic(true));

CheckInByBarcodeResponse checkInResponse =
checkInFixture.checkInByBarcode(nod, checkInDate, servicePointsFixture.cd1().getId());

waitAtMost(1, SECONDS)
.until(accountsClient::getAll, hasSize(1));

List<JsonObject> createdAccounts = accountsClient.getAll();

assertThat("Fee/fine record should be created", createdAccounts, hasSize(1));
assertThat(createdAccounts.get(0), isValidOverdueFine(checkInResponse.getLoan(), nod,
homeLocation.getJson().getString("name"), ownerId, feeFineId, maxOverdueRecallFine));
}

@Test
void canCheckInLostAndPaidItem() {
final ItemResource item = itemsFixture.basedUponNod();
Expand Down