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());
}
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"));
}
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()));
}
Aggregations