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));
}
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"))));
}
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));
}
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));
}
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);
}
Aggregations