Search in sources :

Example 6 with OkapiHeaders

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

Example 7 with OkapiHeaders

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

Example 8 with OkapiHeaders

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

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

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

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