Search in sources :

Example 11 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsDeclaredLost.

@Test
void canOverrideRenewalWhenItemIsDeclaredLost() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Limited Renewals policy").rolling(Period.weeks(1));
    use(defaultRollingPolicies().loanPolicy(loanPoliciesFixture.create(limitedRenewalsPolicy)).lostItemPolicy(lostItemFeePoliciesFixture.chargeFee()));
    final ZonedDateTime loanDate = ClockUtil.getZonedDateTime().minusWeeks(1);
    final JsonObject loanJson = checkOutFixture.checkOutByBarcode(smallAngryPlanet, usersFixture.jessica(), loanDate).getJson();
    declareLostFixtures.declareItemLost(loanJson);
    loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    final var renewRequestBuilder = new RenewByBarcodeRequestBuilder().forItem(smallAngryPlanet).forUser(jessica).withServicePointId(servicePointsFixture.cd1().getId().toString()).withOverrideBlocks(new RenewBlockOverrides().withRenewalBlock(new RenewalDueDateRequiredBlockOverrideBuilder().withDueDate(null).create()).withComment(OVERRIDE_COMMENT).create());
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(renewRequestBuilder, okapiHeaders).getJson();
    verifyRenewedLoan(smallAngryPlanet, jessica, renewedLoan);
    assertThat("renewal count should be incremented", renewedLoan.getInteger("renewalCount"), is(1));
    assertThat("item status should be changed", renewedLoan.getJsonObject("item").getJsonObject("status").getString("name"), is(CHECKED_OUT.getValue()));
    ZonedDateTime expectedDueDate = loanDate.plusWeeks(2);
    assertThat("due date should be 2 weeks later", renewedLoan.getString("dueDate"), isEquivalentTo(expectedDueDate));
}
Also used : RenewBlockOverrides(api.support.builders.RenewBlockOverrides) OkapiHeaders(api.support.http.OkapiHeaders) ZonedDateTime(java.time.ZonedDateTime) RenewByBarcodeRequestBuilder(api.support.builders.RenewByBarcodeRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) RenewalDueDateRequiredBlockOverrideBuilder(api.support.builders.RenewalDueDateRequiredBlockOverrideBuilder) Test(org.junit.jupiter.api.Test)

Example 12 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewByBarcodeTests method cannotOverrideRenewalWhenLoanDoesNotMatchAnyOfOverrideCases.

@Test
void cannotOverrideRenewalWhenLoanDoesNotMatchAnyOfOverrideCases() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
    LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").rolling(Period.months(2)).renewFromCurrentDueDate();
    use(currentDueDateRollingPolicy);
    final Response response = loansFixture.attemptOverride(smallAngryPlanet, jessica, OVERRIDE_COMMENT, null);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Override renewal does not match any of expected cases: " + "item is not loanable, " + "item is not renewable, " + "reached number of renewals limit," + "renewal date falls outside of the date ranges in the loan policy, " + "items cannot be renewed when there is an active recall request, " + "item is Declared lost, item is Aged to lost, " + "renewal would not change the due date"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 13 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsSpecified.

@Test
void canOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsSpecified() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    LoanPolicyBuilder notLoanablePolicy = new LoanPolicyBuilder().withName("Not Loanable Policy").withLoanable(false);
    createLoanPolicyAndSetAsFallback(notLoanablePolicy);
    JsonObject renewalResponse = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica).getJson();
    assertThat(renewalResponse, hasErrorWith(allOf(hasMessage(ITEM_IS_NOT_LOANABLE_MESSAGE))));
    ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(2);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
    assertThat("action should be renewed", renewedLoan.getString("action"), is(RENEWED_THROUGH_OVERRIDE));
    assertThat("'actionComment' field should contain comment specified for override", renewedLoan.getString(ACTION_COMMENT_KEY), is(OVERRIDE_COMMENT));
    assertThat("due date should be 2 weeks from now", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 14 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified.

@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    final UUID loanId = loan.getId();
    FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder().withName("Fixed Due Date Schedule").addSchedule(wholeMonth(2018, 2));
    final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
    LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").fixed(fixedDueDateSchedulesId).renewFromCurrentDueDate();
    final IndividualResource loanPolicy = loanPoliciesFixture.create(currentDueDateRollingPolicy);
    UUID dueDateLimitedPolicyId = loanPolicy.getId();
    use(currentDueDateRollingPolicy);
    loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
    final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
    assertThat(renewedLoan.getString("id"), is(loanId.toString()));
    verifyRenewedLoan(smallAngryPlanet, jessica, renewedLoan);
    assertThat("renewal count should be incremented", renewedLoan.getInteger("renewalCount"), is(1));
    // TODO loanpolicyname is not stored, possible bug?
    assertThat("last loan policy should be stored", renewedLoan.getString("loanPolicyId"), is(dueDateLimitedPolicyId.toString()));
    assertThat("due date should be 2 months from previous due date", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
    smallAngryPlanet = itemsClient.get(smallAngryPlanet);
    assertThat(smallAngryPlanet, hasItemStatus(ItemBuilder.CHECKED_OUT));
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 15 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewByBarcodeTests method checkInRemovesActionCommentAfterOverride.

@Test
void checkInRemovesActionCommentAfterOverride() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    LoanPolicyBuilder nonRenewablePolicy = new LoanPolicyBuilder().withName("Non Renewable Policy").rolling(Period.days(2)).notRenewable();
    createLoanPolicyAndSetAsFallback(nonRenewablePolicy);
    loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(2);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    JsonObject loanAfterOverride = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
    assertLoanHasActionComment(loanAfterOverride, OVERRIDE_COMMENT);
    JsonObject loanAfterCheckIn = checkInFixture.checkInByBarcode(smallAngryPlanet).getLoan();
    assertActionCommentIsAbsentInLoan(loanAfterCheckIn);
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)199 Test (org.junit.jupiter.api.Test)173 ZonedDateTime (java.time.ZonedDateTime)135 IndividualResource (api.support.http.IndividualResource)97 JsonObject (io.vertx.core.json.JsonObject)87 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)79 Loan (org.folio.circulation.domain.Loan)70 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)64 UUID (java.util.UUID)63 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)57 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)50 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)39 RequestQueue (org.folio.circulation.domain.RequestQueue)37 RequestBuilder (api.support.builders.RequestBuilder)34 Response (org.folio.circulation.support.http.client.Response)32 ItemResource (api.support.http.ItemResource)25 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)23 LoanBuilder (api.support.builders.LoanBuilder)18 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)16 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)16