From 60242f0de98eb56f631563df570328079e57ee97 Mon Sep 17 00:00:00 2001 From: Viktor Draban Date: Mon, 28 Mar 2022 15:36:48 +0300 Subject: [PATCH 1/3] CIRC-1482 create test for overdue recall fine calculation when recall request creation --- .../java/api/loans/CheckInByBarcodeTests.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/test/java/api/loans/CheckInByBarcodeTests.java b/src/test/java/api/loans/CheckInByBarcodeTests.java index 1d7635abb2..3ca2d2b7cd 100644 --- a/src/test/java/api/loans/CheckInByBarcodeTests.java +++ b/src/test/java/api/loans/CheckInByBarcodeTests.java @@ -1369,6 +1369,89 @@ void overdueFineCalculatedCorrectlyWhenHourlyFeeFinePolicyIsApplied() { homeLocation.getJson().getString("name"), ownerId, feeFineId, 7.0)); } + @Test + void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreation() { + double maxOverdueFine = 5.0; + double maxOverdueRecallFineFine = 30.0; + double overdueRecallFineFine = 6.0; + configurationsFixture.enableTlrFeature(); + useFallbackPolicies(loanPoliciesFixture.create(new LoanPolicyBuilder() + .withId(UUID.randomUUID()) + .withName("1 minute policy") + .withDescription("Can circulate item") + .rolling(Period.minutes(1)) + .withGracePeriod(Period.zeroDurationPeriod()) + .unlimitedRenewals() + .renewFromSystemDate()).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) + .withGracePeriodRecall(false) + .withOverdueFine( + new JsonObject() + .put("quantity", 1.0) + .put("intervalId", "minute")) + .withMaxOverdueFine(maxOverdueFine) + .withOverdueRecallFine(new JsonObject() + .put("quantity", overdueRecallFineFine) + .put("intervalId", "minute")) + .withMaxOverdueRecallFine(maxOverdueRecallFineFine) + .withCountClosed(false)).getId(), + lostItemFeePoliciesFixture.facultyStandard().getId()); + + final IndividualResource james = usersFixture.james(); + final IndividualResource requester = usersFixture.steve(); + final UUID checkInServicePointId = servicePointsFixture.cd1().getId(); + final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation( + item -> item.withPrimaryServicePoint(checkInServicePointId)); + final IndividualResource nod = itemsFixture.basedUponNod(item -> + item.withPermanentLocation(homeLocation.getId())); + + ZonedDateTime checkOutDate = ZonedDateTime.of(2020, 1, 18, 18, 0, 0, 0, UTC); + ZonedDateTime requestDate = ZonedDateTime.of(2020, 1, 19, 18, 0, 0, 0, UTC); + ZonedDateTime checkInDate = ZonedDateTime.of(2020, 1, 22, 15, 30, 0, 0, UTC); + + checkOutFixture.checkOutByBarcode(nod, james, checkOutDate); + requestsFixture.placeItemLevelHoldShelfRequest(nod, requester, requestDate, "Recall"); + + JsonObject servicePointOwner = new JsonObject(); + servicePointOwner.put("value", homeLocation.getJson().getString("primaryServicePoint")); + servicePointOwner.put("label", "label"); + UUID ownerId = UUID.randomUUID(); + feeFineOwnersClient.create(new FeeFineOwnerBuilder() + .withId(ownerId) + .withOwner("fee-fine-owner") + .withServicePointOwner(Collections.singletonList(servicePointOwner))); + + UUID feeFineId = UUID.randomUUID(); + feeFinesClient.create(new FeeFineBuilder() + .withId(feeFineId) + .withFeeFineType("Overdue fine") + .withOwnerId(ownerId) + .withAutomatic(true) + .withDefaultAmount(1.0)); + + CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode( + new CheckInByBarcodeRequestBuilder() + .forItem(nod) + .on(checkInDate) + .at(checkInServicePointId)); + + waitAtMost(1, SECONDS) + .until(accountsClient::getAll, hasSize(1)); + + List createdAccounts = accountsClient.getAll(); + + assertThat("Fee/fine record should be created", createdAccounts, hasSize(1)); + JsonObject account = createdAccounts.get(0); + JsonObject checkedInLoan = checkInResponse.getLoan(); + assertThat(account, isValidOverdueFine(checkedInLoan, nod, + homeLocation.getJson().getString("name"), ownerId, feeFineId, maxOverdueRecallFineFine)); + } + @Test void canCheckInLostAndPaidItem() { final ItemResource item = itemsFixture.basedUponNod(); From c39f8efcbc13d0a69db5b96e463287580052ed50 Mon Sep 17 00:00:00 2001 From: Viktor Draban Date: Mon, 28 Mar 2022 22:52:17 +0300 Subject: [PATCH 2/3] CIRC-1482 refactor test --- .../java/api/loans/CheckInByBarcodeTests.java | 93 +++++++++---------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/src/test/java/api/loans/CheckInByBarcodeTests.java b/src/test/java/api/loans/CheckInByBarcodeTests.java index 3ca2d2b7cd..a1aca193fd 100644 --- a/src/test/java/api/loans/CheckInByBarcodeTests.java +++ b/src/test/java/api/loans/CheckInByBarcodeTests.java @@ -1370,43 +1370,40 @@ void overdueFineCalculatedCorrectlyWhenHourlyFeeFinePolicyIsApplied() { } @Test - void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreation() { + void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreated() { double maxOverdueFine = 5.0; - double maxOverdueRecallFineFine = 30.0; - double overdueRecallFineFine = 6.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)) - .withGracePeriod(Period.zeroDurationPeriod()) - .unlimitedRenewals() - .renewFromSystemDate()).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) - .withGracePeriodRecall(false) - .withOverdueFine( - new JsonObject() - .put("quantity", 1.0) + useFallbackPolicies( + loanPoliciesFixture.create(new LoanPolicyBuilder() + .withId(UUID.randomUUID()) + .withName("1 minute policy") + .withDescription("Can circulate item") + .rolling(Period.minutes(1)) + .withGracePeriod(Period.zeroDurationPeriod()) + .unlimitedRenewals() + .renewFromSystemDate()).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) + .withGracePeriodRecall(false) + .withOverdueFine( + new JsonObject() + .put("quantity", 1.0) + .put("intervalId", "minute")) + .withMaxOverdueFine(maxOverdueFine) + .withOverdueRecallFine(new JsonObject() + .put("quantity", overdueRecallFine) .put("intervalId", "minute")) - .withMaxOverdueFine(maxOverdueFine) - .withOverdueRecallFine(new JsonObject() - .put("quantity", overdueRecallFineFine) - .put("intervalId", "minute")) - .withMaxOverdueRecallFine(maxOverdueRecallFineFine) - .withCountClosed(false)).getId(), - lostItemFeePoliciesFixture.facultyStandard().getId()); - - final IndividualResource james = usersFixture.james(); - final IndividualResource requester = usersFixture.steve(); - final UUID checkInServicePointId = servicePointsFixture.cd1().getId(); - final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation( - item -> item.withPrimaryServicePoint(checkInServicePointId)); + .withMaxOverdueRecallFine(maxOverdueRecallFine) + .withCountClosed(false)).getId(), + lostItemFeePoliciesFixture.facultyStandard().getId() + ); + final IndividualResource homeLocation = locationsFixture.mainFloor(); final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withPermanentLocation(homeLocation.getId())); @@ -1414,31 +1411,27 @@ void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreation() { ZonedDateTime requestDate = ZonedDateTime.of(2020, 1, 19, 18, 0, 0, 0, UTC); ZonedDateTime checkInDate = ZonedDateTime.of(2020, 1, 22, 15, 30, 0, 0, UTC); - checkOutFixture.checkOutByBarcode(nod, james, checkOutDate); - requestsFixture.placeItemLevelHoldShelfRequest(nod, requester, requestDate, "Recall"); + checkOutFixture.checkOutByBarcode(nod, usersFixture.james(), checkOutDate); + requestsFixture.placeItemLevelHoldShelfRequest( + nod, usersFixture.steve(), requestDate, "Recall"); - JsonObject servicePointOwner = new JsonObject(); - servicePointOwner.put("value", homeLocation.getJson().getString("primaryServicePoint")); - servicePointOwner.put("label", "label"); UUID ownerId = UUID.randomUUID(); feeFineOwnersClient.create(new FeeFineOwnerBuilder() .withId(ownerId) .withOwner("fee-fine-owner") - .withServicePointOwner(Collections.singletonList(servicePointOwner))); + .withServicePointOwner(Collections.singletonList(new JsonObject() + .put("value", homeLocation.getJson().getString("primaryServicePoint")) + .put("label", "label")))); UUID feeFineId = UUID.randomUUID(); feeFinesClient.create(new FeeFineBuilder() .withId(feeFineId) .withFeeFineType("Overdue fine") .withOwnerId(ownerId) - .withAutomatic(true) - .withDefaultAmount(1.0)); + .withAutomatic(true)); - CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode( - new CheckInByBarcodeRequestBuilder() - .forItem(nod) - .on(checkInDate) - .at(checkInServicePointId)); + CheckInByBarcodeResponse checkInResponse = + checkInFixture.checkInByBarcode(nod, checkInDate, servicePointsFixture.cd1().getId()); waitAtMost(1, SECONDS) .until(accountsClient::getAll, hasSize(1)); @@ -1446,10 +1439,8 @@ void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreation() { List createdAccounts = accountsClient.getAll(); assertThat("Fee/fine record should be created", createdAccounts, hasSize(1)); - JsonObject account = createdAccounts.get(0); - JsonObject checkedInLoan = checkInResponse.getLoan(); - assertThat(account, isValidOverdueFine(checkedInLoan, nod, - homeLocation.getJson().getString("name"), ownerId, feeFineId, maxOverdueRecallFineFine)); + assertThat(createdAccounts.get(0), isValidOverdueFine(checkInResponse.getLoan(), nod, + homeLocation.getJson().getString("name"), ownerId, feeFineId, maxOverdueRecallFine)); } @Test From ae0f2ce590a6fbe88b3674a66b0bfac009498c84 Mon Sep 17 00:00:00 2001 From: Viktor Draban Date: Tue, 12 Apr 2022 10:51:15 +0300 Subject: [PATCH 3/3] CIRC-1482 fix comments --- .../java/api/loans/CheckInByBarcodeTests.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/java/api/loans/CheckInByBarcodeTests.java b/src/test/java/api/loans/CheckInByBarcodeTests.java index a1aca193fd..79b91f8560 100644 --- a/src/test/java/api/loans/CheckInByBarcodeTests.java +++ b/src/test/java/api/loans/CheckInByBarcodeTests.java @@ -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; @@ -1381,16 +1382,13 @@ void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreated() { .withName("1 minute policy") .withDescription("Can circulate item") .rolling(Period.minutes(1)) - .withGracePeriod(Period.zeroDurationPeriod()) - .unlimitedRenewals() - .renewFromSystemDate()).getId(), + .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) - .withGracePeriodRecall(false) .withOverdueFine( new JsonObject() .put("quantity", 1.0) @@ -1407,9 +1405,11 @@ void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreated() { final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withPermanentLocation(homeLocation.getId())); - ZonedDateTime checkOutDate = ZonedDateTime.of(2020, 1, 18, 18, 0, 0, 0, UTC); - ZonedDateTime requestDate = ZonedDateTime.of(2020, 1, 19, 18, 0, 0, 0, UTC); - ZonedDateTime checkInDate = ZonedDateTime.of(2020, 1, 22, 15, 30, 0, 0, UTC); + 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( @@ -1420,8 +1420,7 @@ void overdueRecallFineCalculatedCorrectlyWhenRecallRequestCreated() { .withId(ownerId) .withOwner("fee-fine-owner") .withServicePointOwner(Collections.singletonList(new JsonObject() - .put("value", homeLocation.getJson().getString("primaryServicePoint")) - .put("label", "label")))); + .put("value", homeLocation.getJson().getString("primaryServicePoint"))))); UUID feeFineId = UUID.randomUUID(); feeFinesClient.create(new FeeFineBuilder()