use of api.support.http.OkapiHeaders 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);
}
use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy.
@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy() {
final ZonedDateTime renewalDate = ClockUtil.getZonedDateTime();
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)).addSchedule(forDay(renewalDate));
final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").rolling(Period.months(2)).limitedBySchedule(fixedDueDateSchedulesId).renewFromCurrentDueDate();
use(currentDueDateRollingPolicy);
Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("renewal date falls outside of date ranges in the loan policy"))));
final ZonedDateTime newDueDate = loanDueDate.plusWeeks(3).plusMonths(2);
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
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));
assertThat("due date should be 1st of Feb 2019", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsAgedToLostAndPatronIsBlockedManually.
@Test
void canOverrideRenewalWhenItemIsAgedToLostAndPatronIsBlockedManually() {
final ZonedDateTime approximateRenewalDate = ClockUtil.getZonedDateTime().plusWeeks(3);
val result = ageToLostFixture.createAgedToLostLoan();
userManualBlocksFixture.createRenewalsManualPatronBlockForUser(result.getUser().getId());
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_PATRON_BLOCK_PERMISSION, OVERRIDE_RENEWAL_PERMISSION);
final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(new RenewByBarcodeRequestBuilder().forItem(result.getItem()).forUser(result.getUser()).withOverrideBlocks(new RenewBlockOverrides().withPatronBlock(new JsonObject()).withRenewalBlock(new RenewalDueDateRequiredBlockOverrideBuilder().create()).withComment(OVERRIDE_COMMENT).create()), okapiHeaders).getJson();
verifyRenewedLoan(result.getItem(), result.getUser(), renewedLoan);
assertThat(renewedLoan, hasJsonPath("item.status.name", "Checked out"));
assertThat(itemsClient.get(result.getItem()).getJson(), isCheckedOut());
assertThat(renewedLoan.getString("dueDate"), withinSecondsAfter(2L, approximateRenewalDate));
}
use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsAgedToLostAndPatronIsBlockedAutomatically.
@Test
void canOverrideRenewalWhenItemIsAgedToLostAndPatronIsBlockedAutomatically() {
final ZonedDateTime approximateRenewalDate = ClockUtil.getZonedDateTime().plusWeeks(3);
val result = ageToLostFixture.createAgedToLostLoan();
automatedPatronBlocksFixture.blockAction(result.getUser().getId().toString(), false, true, false);
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_PATRON_BLOCK_PERMISSION, OVERRIDE_RENEWAL_PERMISSION);
final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(new RenewByBarcodeRequestBuilder().forItem(result.getItem()).forUser(result.getUser()).withOverrideBlocks(new RenewBlockOverrides().withRenewalBlock(new RenewalDueDateRequiredBlockOverrideBuilder().create()).withPatronBlock(new JsonObject()).withComment(OVERRIDE_COMMENT).create()), okapiHeaders).getJson();
verifyRenewedLoan(result.getItem(), result.getUser(), renewedLoan);
assertThat(renewedLoan, hasJsonPath("item.status.name", "Checked out"));
assertThat(itemsClient.get(result.getItem()).getJson(), isCheckedOut());
assertThat(renewedLoan.getString("dueDate"), withinSecondsAfter(2L, approximateRenewalDate));
}
use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class RenewalAPITests method canOverrideRenewalWhenPatronIsBlockedManuallyAndAutomatically.
@Test
void canOverrideRenewalWhenPatronIsBlockedManuallyAndAutomatically() {
IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
checkOutFixture.checkOutByBarcode(item, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
userManualBlocksFixture.createRenewalsManualPatronBlockForUser(jessica.getId());
automatedPatronBlocksFixture.blockAction(jessica.getId().toString(), false, true, false);
final Response response = attemptRenewal(item, jessica);
assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY));
assertThat(response.getJson(), hasErrorWith(hasMessage(PATRON_WAS_BLOCKED_MESSAGE)));
assertThat(response.getJson(), hasErrorWith(hasMessage(MAX_NUMBER_OF_ITEMS_CHARGED_OUT_MESSAGE)));
assertThat(response.getJson(), hasErrorWith(hasMessage(MAX_OUTSTANDING_FEE_FINE_BALANCE_MESSAGE)));
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_PATRON_BLOCK_PERMISSION);
JsonObject loan = loansFixture.renewLoan(buildRenewByBarcodeRequestWithPatronBlockOverride(item, jessica), okapiHeaders).getJson();
item = itemsClient.get(item);
assertThat(item, hasItemStatus(CHECKED_OUT));
assertThat(loan.getString("actionComment"), is(TEST_COMMENT));
assertThat(loan.getString("action"), is(RENEWED_THROUGH_OVERRIDE));
}
Aggregations