use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class CheckOutByBarcodeTests method itemCheckedOutEventIsPublishedWithGracePeriodDefinedInLoanPolicy.
private void itemCheckedOutEventIsPublishedWithGracePeriodDefinedInLoanPolicy(IndividualResource loanPolicy) {
use(defaultRollingPolicies().loanPolicy(loanPolicy));
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource steve = usersFixture.steve();
final IndividualResource response = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(getZonedDateTime()).at(UUID.randomUUID()));
final JsonObject loan = response.getJson();
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
final var checkedOutEvent = publishedEvents.findFirst(byEventType(ITEM_CHECKED_OUT));
assertThat(checkedOutEvent, isValidItemCheckedOutEvent(loan, loanPolicy));
final var checkOutLogEvent = publishedEvents.findFirst(byLogEventType(CHECK_OUT));
assertThat(checkOutLogEvent, isValidCheckOutLogEvent(loan, LogEventType.CHECK_OUT));
assertThatPublishedLoanLogRecordEventsAreValid(loan);
}
use of api.support.fakes.FakePubSub 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.fakes.FakePubSub in project mod-circulation by folio-org.
the class ClaimItemReturnedAPITests method itemClaimedReturnedEventIsPublished.
@Test
void itemClaimedReturnedEventIsPublished() {
final ZonedDateTime dateTime = ClockUtil.getZonedDateTime();
final Response response = claimItemReturnedFixture.claimItemReturned(new ClaimItemReturnedRequestBuilder().forLoan(loanId).withItemClaimedReturnedDate(dateTime));
assertLoanAndItem(response, null, dateTime);
// Five events are expected: one for check-out one for log event, one for the claim
// and one for log records
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
final var event = publishedEvents.findFirst(byEventType(ITEM_CLAIMED_RETURNED));
assertThat(event, isValidItemClaimedReturnedEvent(loan.getJson()));
assertThatPublishedLoanLogRecordEventsAreValid(loansClient.getById(loan.getId()).getJson());
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class RequestsAPICreationTests method canCreateTlrRecallForInstanceWithSingleItemAndTwoLoans.
@Test
void canCreateTlrRecallForInstanceWithSingleItemAndTwoLoans() {
reconfigureTlrFeature(TlrFeatureStatus.ENABLED);
final ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource requestPickupServicePoint = servicePointsFixture.cd1();
IndividualResource initialLoan = checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
checkInFixture.checkInByBarcode(item);
IndividualResource dueDateChangeLoan = checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
requestsClient.create(new RequestBuilder().recall().withNoHoldingsRecordId().withNoItemId().titleRequestLevel().withInstanceId(item.getInstanceId()).withPickupServicePointId(requestPickupServicePoint.getId()).withRequesterId(usersFixture.james().getId()));
PublishedEvents publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(9));
JsonObject loanWithoutChange = loansClient.get(initialLoan.getId()).getJson();
assertNull(loanWithoutChange.getString("dueDateChangedByRecall"));
JsonObject updatedLoan = loansClient.get(dueDateChangeLoan.getId()).getJson();
assertThat(updatedLoan.getString("dueDateChangedByRecall"), true);
JsonObject event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
assertThat(event, isValidLoanDueDateChangedEvent(updatedLoan));
assertThat(new JsonObject(event.getString("eventPayload")).getBoolean("dueDateChangedByRecall"), equalTo(true));
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class RenewalAPITests method dueDateChangedEventIsPublished.
@Test
void dueDateChangedEventIsPublished() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource jessica = usersFixture.jessica();
checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
final JsonObject renewedLoan = renew(smallAngryPlanet, jessica).getJson();
// There should be five events published - first for "check out",
// second one for log event, third for "change due date",
// fourth one for "log record", and fifth one for "renewed".
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(5));
final var event = publishedEvents.findFirst(byEventType(LOAN_DUE_DATE_CHANGED));
assertThat(event, isValidLoanDueDateChangedEvent(renewedLoan));
assertThatPublishedLoanLogRecordEventsAreValid(renewedLoan);
final var renewedEvent = publishedEvents.findFirst(byLogAction(ITEM_RENEWED));
assertThat(renewedEvent, isValidRenewedEvent(renewedLoan));
}
Aggregations