Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/CIRC-2051' into CIRC-2051
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-barannyk committed Apr 12, 2024
2 parents 6f5c6b1 + a65768b commit c6ab23f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
8 changes: 6 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,9 @@
"manualblocks.collection.get",
"pubsub.publish.post",
"automated-patron-blocks.collection.get",
"circulation-storage.loans-history.collection.get"
"circulation-storage.loans-history.collection.get",
"overdue-fines-policies.item.get",
"overdue-fines-policies.collection.get"
],
"visible": false
},
Expand Down Expand Up @@ -2291,7 +2293,9 @@
"pubsub.publish.post",
"configuration.entries.collection.get",
"patron-notice.post",
"circulation-storage.loans-history.collection.get"
"circulation-storage.loans-history.collection.get",
"overdue-fines-policies.item.get",
"overdue-fines-policies.collection.get"
],
"visible": false
},
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/circulation/domain/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ public FeeAmount getRemainingFeeFineAmount() {
public void closeLoanAsLostAndPaid() {
log.debug("closeLoanAsLostAndPaid:: ");
closeLoan(CLOSED_LOAN);
changeReturnDate(ClockUtil.getZonedDateTime());
changeItemStatusForItemAndLoan(ItemStatus.LOST_AND_PAID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
import org.folio.circulation.domain.FeeFine;
import org.folio.circulation.domain.FeeFineOwner;
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.Location;
import org.folio.circulation.domain.policy.lostitem.LostItemPolicy;
import org.folio.circulation.domain.policy.lostitem.itemfee.AutomaticallyChargeableFee;
import org.folio.circulation.domain.representations.DeclareItemLostRequest;
import org.folio.circulation.infrastructure.storage.ActualCostRecordRepository;
import org.folio.circulation.infrastructure.storage.ServicePointRepository;
import org.folio.circulation.infrastructure.storage.feesandfines.FeeFineOwnerRepository;
import org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository;
import org.folio.circulation.infrastructure.storage.inventory.IdentifierTypeRepository;
import org.folio.circulation.infrastructure.storage.inventory.LocationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository;
import org.folio.circulation.infrastructure.storage.users.PatronGroupRepository;
import org.folio.circulation.infrastructure.storage.users.UserRepository;
import org.folio.circulation.services.actualcostrecord.ActualCostRecordService;
import org.folio.circulation.services.EventPublisher;
import org.folio.circulation.services.FeeFineFacade;
import org.folio.circulation.services.actualcostrecord.ActualCostRecordService;
import org.folio.circulation.services.support.CreateAccountCommand;
import org.folio.circulation.support.Clients;
import org.folio.circulation.support.fetching.PageableFetcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.policy.Period;
import org.folio.circulation.services.agedtolost.LoanToChargeFees;
import org.folio.circulation.support.utils.ClockUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -47,13 +48,17 @@ void shouldCloseLoanWhenAllFeesClosed() {
feeFineAccountFixture.payLostItemFee(loan.getId());
feeFineAccountFixture.payLostItemProcessingFee(loan.getId());

var returnDate = ClockUtil.getZonedDateTime();
mockClockManagerToReturnFixedDateTime(returnDate);
eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId());

assertThatLoanIsClosedAsLostAndPaid();
JsonObject loan = assertThatLoanIsClosedAsLostAndPaid();
assertThat(loan.getString("returnDate"), is(returnDate.toString()));
mockClockManagerToReturnDefaultDateTime();

List<JsonObject> loanClosedEvents = getPublishedEventsAsList(byEventType(LOAN_CLOSED));
assertThat(loanClosedEvents, hasSize(1));
assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan.getJson()));
assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan));
}

@Test
Expand Down Expand Up @@ -224,9 +229,15 @@ void shouldCloseLoanWhenActualCostRecordIsCancelled() {

item = result.getItem();
loan = result.getLoan();

var returnDate = ClockUtil.getZonedDateTime();
mockClockManagerToReturnFixedDateTime(returnDate);
cancelActualCostRecord();
eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId());

assertThatLoanIsClosedAsLostAndPaid();
JsonObject loan = assertThatLoanIsClosedAsLostAndPaid();
assertThat(loan.getString("returnDate"), is(returnDate.toString()));
mockClockManagerToReturnDefaultDateTime();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.folio.circulation.domain.ItemStatus;
import org.folio.circulation.domain.policy.Period;
import org.folio.circulation.support.http.client.Response;
import org.folio.circulation.support.utils.ClockUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -54,12 +55,17 @@ void shouldCloseLoanWhenAllFeesClosed() {
feeFineAccountFixture.payLostItemFee(loan.getId());
feeFineAccountFixture.payLostItemProcessingFee(loan.getId());

var returnDate = ClockUtil.getZonedDateTime();
mockClockManagerToReturnFixedDateTime(returnDate);
eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId());
assertThatLoanIsClosedAsLostAndPaid();

JsonObject loan = assertThatLoanIsClosedAsLostAndPaid();
assertThat(loan.getString("returnDate"), is(returnDate.toString()));
mockClockManagerToReturnDefaultDateTime();

List<JsonObject> loanClosedEvents = getPublishedEventsAsList(byEventType(LOAN_CLOSED));
assertThat(loanClosedEvents, hasSize(1));
assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan.getJson()));
assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static api.support.matchers.LoanMatchers.isClosed;
import static api.support.matchers.LoanMatchers.isOpen;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.time.ZonedDateTime;
import java.util.UUID;
Expand Down Expand Up @@ -78,9 +79,13 @@ protected void payLostItemActualCostFeeAndProcessingFeeAndCheckThatLoanIsClosed(
assertThatLoanIsClosedAsLostAndPaid();
}

protected void assertThatLoanIsClosedAsLostAndPaid() {
assertThat(loansFixture.getLoanById(loan.getId()).getJson(), isClosed());
protected JsonObject assertThatLoanIsClosedAsLostAndPaid() {
JsonObject loan = loansFixture.getLoanById(this.loan.getId()).getJson();
assertThat(loan, isClosed());
assertNotNull(loan.getString("returnDate"));
assertThat(itemsClient.getById(item.getId()).getJson(), isLostAndPaid());

return loan;
}

protected void assertThatLoanIsOpenAndLost() {
Expand Down

0 comments on commit c6ab23f

Please sign in to comment.