Search in sources :

Example 16 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class RenewalAPITests method cannotRenewWhenItemIsAgedToLost.

@Test
void cannotRenewWhenItemIsAgedToLost() {
    val result = ageToLostFixture.createAgedToLostLoan();
    final Response response = attemptRenewal(result.getItem(), result.getUser());
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("item is Aged to lost"), hasUUIDParameter("itemId", result.getItem().getId()))));
    assertThat(getOverridableBlockNames(response), hasItem("renewalBlock"));
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(5));
    assertThatPublishedLoanLogRecordEventsAreValid(loansClient.getById(result.getLoan().getId()).getJson());
}
Also used : lombok.val(lombok.val) Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) Test(org.junit.jupiter.api.Test)

Example 17 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class RenewalAPITests method cannotRenewWhenItemIsNotLoanable.

@Test
void cannotRenewWhenItemIsNotLoanable() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    LoanPolicyBuilder policyForCheckout = new LoanPolicyBuilder().withName("Policy for checkout").rolling(Period.days(2)).notRenewable();
    use(policyForCheckout);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
    LoanPolicyBuilder nonLoanablePolicy = new LoanPolicyBuilder().withName("Non loanable policy").withLoanable(false);
    UUID notLoanablePolicyId = loanPoliciesFixture.create(nonLoanablePolicy).getId();
    use(nonLoanablePolicy);
    final Response response = attemptRenewal(smallAngryPlanet, jessica);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("item is not loanable"), hasLoanPolicyIdParameter(notLoanablePolicyId), hasLoanPolicyNameParameter("Non loanable policy"))));
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
    assertThatPublishedLoanLogRecordEventsAreValid(response.getJson());
    assertThat(getOverridableBlockNames(response), hasItem("renewalDueDateRequiredBlock"));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 18 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class LoanAPITests method dueDateChangedEventIsPublishedOnReplace.

@Test
void dueDateChangedEventIsPublishedOnReplace() {
    final ItemResource item = itemsFixture.basedUponNod();
    final IndividualResource checkOutResponse = loansFixture.createLoan(item, usersFixture.jessica());
    itemsClient.getById(item.getId()).getJson();
    loansFixture.replaceLoan(checkOutResponse.getId(), checkOutResponse.getJson().copy());
    itemsClient.getById(item.getId()).getJson();
    Response loanFromStorage = loansStorageClient.getById(checkOutResponse.getId());
    // There should be four events published - "create", "replace"
    // and two "log_record"
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
    final var event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
    assertThat(event, isValidLoanDueDateChangedEvent(loanFromStorage.getJson()));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Aggregations

FakePubSub (api.support.fakes.FakePubSub)18 Test (org.junit.jupiter.api.Test)17 IndividualResource (api.support.http.IndividualResource)13 JsonObject (io.vertx.core.json.JsonObject)12 Response (org.folio.circulation.support.http.client.Response)10 ZonedDateTime (java.time.ZonedDateTime)7 ItemResource (api.support.http.ItemResource)6 UUID (java.util.UUID)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 RequestBuilder (api.support.builders.RequestBuilder)4 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)3 APITests (api.support.APITests)2 CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)2 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)2 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)2 ValidationErrorMatchers.hasErrorWith (api.support.matchers.ValidationErrorMatchers.hasErrorWith)2 ValidationErrorMatchers.hasMessage (api.support.matchers.ValidationErrorMatchers.hasMessage)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 lombok.val (lombok.val)2