Search in sources :

Example 1 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class OverrideRenewalTest method shouldUseOverrideDateWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent.

@Test
void shouldUseOverrideDateWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent() {
    final ZonedDateTime overrideDueDate = ClockUtil.getZonedDateTime().plusWeeks(2);
    final LoanPolicy loanPolicy = LoanPolicy.from(rollingPolicy().limitedRenewals(1).create());
    final Loan loan = Loan.from(new JsonObject().put("renewalCount", 2)).changeDueDate(ClockUtil.getZonedDateTime().plusWeeks(1).plusSeconds(1)).withItem(createCheckedOutItem()).withLoanPolicy(loanPolicy);
    final Result<Loan> renewedLoan = renew(loan, overrideDueDate);
    assertDueDate(overrideDueDate, renewedLoan);
    assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 2 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class OverrideRenewalTest method overrideDateIsRequiredWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent.

@Test
void overrideDateIsRequiredWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent() {
    final LoanPolicy loanPolicy = LoanPolicy.from(rollingPolicy().limitedRenewals(1).create());
    final Loan loan = Loan.from(new JsonObject().put("renewalCount", 2)).changeDueDate(ClockUtil.getZonedDateTime().plusDays(8)).withLoanPolicy(loanPolicy);
    final Result<Loan> renewedLoan = renew(loan, null);
    assertThat(renewedLoan, hasValidationError(hasMessage(NEW_DUE_DATE_IS_REQUIRED_ERROR)));
}
Also used : Loan(org.folio.circulation.domain.Loan) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 3 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class OverrideRenewalTest method shouldUseOverrideDateWhenLoanIsNotLoanable.

@Test
void shouldUseOverrideDateWhenLoanIsNotLoanable() {
    final ZonedDateTime overrideDate = ClockUtil.getZonedDateTime().plusMonths(1);
    final JsonObject loanPolicyJson = new LoanPolicyBuilder().withLoanable(false).create();
    final Result<Loan> renewedLoan = renew(LoanPolicy.from(loanPolicyJson), overrideDate);
    assertDueDate(overrideDate, renewedLoan);
    assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class OverrideRenewalTest method nonLoanableAgedToLostItemShouldBeProperlyRenewed.

@Test
void nonLoanableAgedToLostItemShouldBeProperlyRenewed() {
    final ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
    final ZonedDateTime ageToLostDate = ClockUtil.getZonedDateTime();
    final LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().withLoanable(false).create());
    final Loan loan = Loan.from(new JsonObject()).withItem(createCheckedOutItem()).withLoanPolicy(loanPolicy);
    loan.ageOverdueItemToLost(ageToLostDate).setAgedToLostDelayedBilling(false, ageToLostDate.plusDays(1));
    final Result<Loan> renewedLoan = renew(loan, newDueDate);
    assertDueDate(newDueDate, renewedLoan);
    assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
    assertThat(renewedLoan.value().asJson(), allOf(hasNoJsonPath("agedToLostDelayedBilling.lostItemHasBeenBilled"), hasNoJsonPath("agedToLostDelayedBilling.dateLostItemShouldBeBilled")));
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class OverrideRenewalTest method overrideDateIsRequiredWhenLoanIsNotLoanable.

@Test
void overrideDateIsRequiredWhenLoanIsNotLoanable() {
    final JsonObject loanPolicyJson = new LoanPolicyBuilder().withLoanable(false).create();
    final Result<Loan> renewedLoan = renew(LoanPolicy.from(loanPolicyJson), null);
    assertThat(renewedLoan, hasValidationError(hasMessage(OVERRIDE_DUE_DATE_MUST_BE_SPECIFIED_ERROR)));
}
Also used : Loan(org.folio.circulation.domain.Loan) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Loan (org.folio.circulation.domain.Loan)133 ZonedDateTime (java.time.ZonedDateTime)89 Test (org.junit.jupiter.api.Test)77 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)70 RequestQueue (org.folio.circulation.domain.RequestQueue)48 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)39 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)39 JsonObject (io.vertx.core.json.JsonObject)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)30 Result (org.folio.circulation.support.results.Result)26 CompletableFuture (java.util.concurrent.CompletableFuture)23 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)21 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)20 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)19 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)19 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)17 RoutingContext (io.vertx.ext.web.RoutingContext)15 Clients (org.folio.circulation.support.Clients)15 HttpClient (io.vertx.core.http.HttpClient)14