use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class CheckOutByBarcodeTests method canOverrideCheckOutWhenItemNotLoanableBlockIsPresent.
@Test
void canOverrideCheckOutWhenItemNotLoanableBlockIsPresent() {
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_ITEM_NOT_LOANABLE_BLOCK_PERMISSION);
setNotLoanablePolicy();
IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
Response responseBlocked = checkOutFixture.attemptCheckOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(item).to(usersFixture.steve()).at(UUID.randomUUID()).on(TEST_LOAN_DATE).withOverrideBlocks(new CheckOutBlockOverrides().withComment(TEST_COMMENT).create()), okapiHeaders);
assertThat(responseBlocked.getJson(), hasErrorWith(allOf(hasMessage("Item is not loanable"), hasParameter("loanPolicyName", "Not Loanable Policy"))));
JsonObject loan = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(item).to(usersFixture.steve()).at(UUID.randomUUID()).on(TEST_LOAN_DATE).withOverrideBlocks(new CheckOutBlockOverrides().withItemNotLoanableBlockOverride(new ItemNotLoanableBlockOverrideBuilder().withDueDate(TEST_DUE_DATE).create()).withComment(TEST_COMMENT).create()), okapiHeaders).getJson();
item = itemsClient.get(item);
assertThat(item, hasItemStatus(CHECKED_OUT));
assertThat(loan.getString("actionComment"), is(TEST_COMMENT));
assertThat(loan.getString("action"), is(CHECKED_OUT_THROUGH_OVERRIDE));
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
final var checkOutLogEvent = publishedEvents.findFirst(byLogEventType(LogEventType.CHECK_OUT_THROUGH_OVERRIDE.value()));
assertThat(checkOutLogEvent, isValidCheckOutLogEvent(loan, CHECK_OUT_THROUGH_OVERRIDE));
}
use of api.support.http.OkapiHeaders in project mod-circulation by folio-org.
the class CheckOutByBarcodeTests method cannotOverrideItemNotLoanableBlockWhenDueDateIsNotPresent.
@Test
void cannotOverrideItemNotLoanableBlockWhenDueDateIsNotPresent() {
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_ITEM_NOT_LOANABLE_BLOCK_PERMISSION);
setNotLoanablePolicy();
Response response = checkOutFixture.attemptCheckOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(itemsFixture.basedUponSmallAngryPlanet()).to(usersFixture.steve()).at(UUID.randomUUID()).on(TEST_LOAN_DATE).withOverrideBlocks(new CheckOutBlockOverrides().withItemNotLoanableBlockOverride(new JsonObject()).withComment(TEST_COMMENT).create()), okapiHeaders);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Override should be performed with due date specified"), hasParameter("dueDate", null))));
}
use of api.support.http.OkapiHeaders 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.http.OkapiHeaders 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.http.OkapiHeaders 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));
}
Aggregations