Search in sources :

Example 11 with OkapiHeaders

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);
}
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 12 with OkapiHeaders

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) 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 13 with OkapiHeaders

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));
}
Also used : lombok.val(lombok.val) OkapiHeaders(api.support.http.OkapiHeaders) RenewBlockOverrides(api.support.builders.RenewBlockOverrides) ZonedDateTime(java.time.ZonedDateTime) RenewByBarcodeRequestBuilder(api.support.builders.RenewByBarcodeRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) RenewalDueDateRequiredBlockOverrideBuilder(api.support.builders.RenewalDueDateRequiredBlockOverrideBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with OkapiHeaders

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));
}
Also used : lombok.val(lombok.val) OkapiHeaders(api.support.http.OkapiHeaders) RenewBlockOverrides(api.support.builders.RenewBlockOverrides) ZonedDateTime(java.time.ZonedDateTime) RenewByBarcodeRequestBuilder(api.support.builders.RenewByBarcodeRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) RenewalDueDateRequiredBlockOverrideBuilder(api.support.builders.RenewalDueDateRequiredBlockOverrideBuilder) Test(org.junit.jupiter.api.Test)

Example 15 with OkapiHeaders

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) OkapiHeaders(api.support.http.OkapiHeaders) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

OkapiHeaders (api.support.http.OkapiHeaders)44 Test (org.junit.jupiter.api.Test)43 IndividualResource (api.support.http.IndividualResource)31 JsonObject (io.vertx.core.json.JsonObject)30 ZonedDateTime (java.time.ZonedDateTime)20 Response (org.folio.circulation.support.http.client.Response)19 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 CheckOutBlockOverrides (api.support.builders.CheckOutBlockOverrides)13 UUID (java.util.UUID)12 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)11 ItemNotLoanableBlockOverrideBuilder (api.support.builders.ItemNotLoanableBlockOverrideBuilder)7 lombok.val (lombok.val)6 RenewBlockOverrides (api.support.builders.RenewBlockOverrides)4 RenewalDueDateRequiredBlockOverrideBuilder (api.support.builders.RenewalDueDateRequiredBlockOverrideBuilder)4 RenewByBarcodeRequestBuilder (api.support.builders.RenewByBarcodeRequestBuilder)3 ItemResource (api.support.http.ItemResource)3 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)2 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)2 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)2