Search in sources :

Example 6 with CheckInByBarcodeResponse

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

the class InTransitToHomeLocationTests method isAvailableWhenCheckedInToReceiveAtNonPrimaryServicePointForHomeLocation.

@Test
void isAvailableWhenCheckedInToReceiveAtNonPrimaryServicePointForHomeLocation() {
    final IndividualResource primaryServicePoint = servicePointsFixture.cd1();
    final IndividualResource otherServingServicePoint = servicePointsFixture.cd2();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.servedBy(primaryServicePoint.getId()).servedBy(otherServingServicePoint.getId()).withPrimaryServicePoint(primaryServicePoint.getId()));
    final IndividualResource james = usersFixture.james();
    final IndividualResource nod = itemsFixture.basedUponNod(builder -> builder.withTemporaryLocation(homeLocation.getId()));
    final IndividualResource otherServicePoint = servicePointsFixture.cd3();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(nod, james);
    checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(otherServicePoint.getId()));
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(otherServingServicePoint.getId()));
    JsonObject itemRepresentation = checkInResponse.getItem();
    assertThat("item should be present in response", itemRepresentation, notNullValue());
    assertThat("ID should be included for item", itemRepresentation.getString("id"), is(nod.getId()));
    assertThat("title is included for item", itemRepresentation.getString("title"), is("Nod"));
    assertThat("barcode is included for item", itemRepresentation.getString("barcode"), is("565578437802"));
    assertThat("item status is not available", itemRepresentation.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item should not have a destination", itemRepresentation.containsKey("inTransitDestinationServicePointId"), is(false));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("closed loan should not be present in response", loanRepresentation, nullValue());
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("stored item status is not available", updatedNod.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item in storage should not have a destination", updatedNod.containsKey("inTransitDestinationServicePointId"), is(false));
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("stored loan status is not closed", storedLoan.getJsonObject("status").getString("name"), is("Closed"));
    assertThat("item status snapshot in storage should not change", storedLoan.getString("itemStatus"), is("In transit"));
    assertThat("Checkin Service Point Id should not change", storedLoan.getString("checkinServicePointId"), is(otherServicePoint.getId()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 7 with CheckInByBarcodeResponse

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

the class InTransitToHomeLocationTests method isAvailableWhenCheckedInToReceiveAtPrimaryServicePointForHomeLocation.

@Test
void isAvailableWhenCheckedInToReceiveAtPrimaryServicePointForHomeLocation() {
    final IndividualResource primaryServicePoint = servicePointsFixture.cd1();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.servedBy(primaryServicePoint.getId()).withPrimaryServicePoint(primaryServicePoint.getId()));
    final IndividualResource james = usersFixture.james();
    final IndividualResource nod = itemsFixture.basedUponNod(builder -> builder.withTemporaryLocation(homeLocation.getId()));
    final IndividualResource otherServicePoint = servicePointsFixture.cd2();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(nod, james);
    checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(otherServicePoint.getId()));
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(primaryServicePoint.getId()));
    JsonObject itemRepresentation = checkInResponse.getItem();
    assertThat("item should be present in response", itemRepresentation, notNullValue());
    assertThat("ID should be included for item", itemRepresentation.getString("id"), is(nod.getId()));
    assertThat("title is included for item", itemRepresentation.getString("title"), is("Nod"));
    assertThat("barcode is included for item", itemRepresentation.getString("barcode"), is("565578437802"));
    assertThat("item status is not available", itemRepresentation.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item should not have a destination", itemRepresentation.containsKey("inTransitDestinationServicePointId"), is(false));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("closed loan should not be present in response", loanRepresentation, nullValue());
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("stored item status is not available", updatedNod.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item in storage should not have a destination", updatedNod.containsKey("inTransitDestinationServicePointId"), is(false));
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("stored loan status is not closed", storedLoan.getJsonObject("status").getString("name"), is("Closed"));
    assertThat("item status snapshot in storage should not change", storedLoan.getString("itemStatus"), is("In transit"));
    assertThat("Checkin Service Point Id should not change", storedLoan.getString("checkinServicePointId"), is(otherServicePoint.getId()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 8 with CheckInByBarcodeResponse

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

the class InTransitToHomeLocationTests method isPlacedInTransitWhenCheckedInToReturnItemAtServicePointNotServingHomeLocation.

@Test
void isPlacedInTransitWhenCheckedInToReturnItemAtServicePointNotServingHomeLocation() {
    final IndividualResource primaryServicePoint = servicePointsFixture.cd1();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.servedBy(primaryServicePoint.getId()).withPrimaryServicePoint(primaryServicePoint.getId()));
    final IndividualResource james = usersFixture.james();
    final ItemResource nod = itemsFixture.basedUponNod(builder -> builder.withTemporaryLocation(homeLocation.getId()));
    final IndividualResource otherServicePoint = servicePointsFixture.cd2();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(nod, james);
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(otherServicePoint.getId()));
    JsonObject itemRepresentation = checkInResponse.getItem();
    assertThat("item should be present in response", itemRepresentation, notNullValue());
    assertThat("ID should be included for item", itemRepresentation.getString("id"), is(nod.getId()));
    assertThat("title is included for item", itemRepresentation.getString("title"), is("Nod"));
    assertThat("barcode is included for item", itemRepresentation.getString("barcode"), is("565578437802"));
    assertThat("item status is not in transit", itemRepresentation.getJsonObject("status").getString("name"), is("In transit"));
    assertThat("in transit item should have a destination", itemRepresentation.getString("inTransitDestinationServicePointId"), is(primaryServicePoint.getId()));
    assertThat("in transit item should have a extended destination properties", itemRepresentation.containsKey("inTransitDestinationServicePoint"), is(true));
    final JsonObject destinationServicePoint = itemRepresentation.getJsonObject("inTransitDestinationServicePoint");
    assertThat("extended destination properties should include id", destinationServicePoint.getString("id"), is(primaryServicePoint.getId()));
    assertThat("extended destination properties should include name", destinationServicePoint.getString("name"), is("Circ Desk 1"));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("closed loan should be present in response", loanRepresentation, notNullValue());
    assertThat("in transit item (in loan) should have a destination", loanRepresentation.getJsonObject("item").getString("inTransitDestinationServicePointId"), is(primaryServicePoint.getId()));
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("stored item status is not in transit", updatedNod.getJsonObject("status").getString("name"), is("In transit"));
    assertThat("in transit item in storage should have a destination", updatedNod.getString("inTransitDestinationServicePointId"), is(primaryServicePoint.getId()));
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("stored loan status is not closed", storedLoan.getJsonObject("status").getString("name"), is("Closed"));
    assertThat("item status snapshot in storage is not in transit", storedLoan.getString("itemStatus"), is("In transit"));
    assertThat("Checkin Service Point Id should be stored", storedLoan.getString("checkinServicePointId"), is(otherServicePoint.getId()));
    Map<String, Matcher<String>> staffSlipContextMatchers = new HashMap<>();
    staffSlipContextMatchers.putAll(getItemContextMatchers(nod, true));
    staffSlipContextMatchers.putAll(getTransitContextMatchers(otherServicePoint, primaryServicePoint));
    JsonObject staffSlipContext = checkInResponse.getStaffSlipContext();
    assertThat(staffSlipContext, JsonObjectMatcher.allOfPaths(staffSlipContextMatchers));
}
Also used : JsonObjectMatcher(api.support.matchers.JsonObjectMatcher) Matcher(org.hamcrest.Matcher) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 9 with CheckInByBarcodeResponse

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

the class InTransitToHomeLocationTests method isAvailableWhenCheckedInToReturnItemAtPrimaryServicePointForHomeLocation.

@Test
void isAvailableWhenCheckedInToReturnItemAtPrimaryServicePointForHomeLocation() {
    final IndividualResource primaryServicePoint = servicePointsFixture.cd1();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.servedBy(primaryServicePoint.getId()).withPrimaryServicePoint(primaryServicePoint.getId()));
    final IndividualResource james = usersFixture.james();
    final IndividualResource nod = itemsFixture.basedUponNod(builder -> builder.withTemporaryLocation(homeLocation.getId()));
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(nod, james);
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(primaryServicePoint.getId()));
    JsonObject itemRepresentation = checkInResponse.getItem();
    assertThat("item should be present in response", itemRepresentation, notNullValue());
    assertThat("ID should be included for item", itemRepresentation.getString("id"), is(nod.getId()));
    assertThat("title is included for item", itemRepresentation.getString("title"), is("Nod"));
    assertThat("barcode is included for item", itemRepresentation.getString("barcode"), is("565578437802"));
    assertThat("item status is not available", itemRepresentation.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item should not have a destination", itemRepresentation.containsKey("inTransitDestinationServicePointId"), is(false));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("closed loan should be present in response", loanRepresentation, notNullValue());
    assertThat("in transit item (in loan) should have a destination", loanRepresentation.getJsonObject("item").containsKey("inTransitDestinationServicePointId"), is(false));
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("stored item status is not available", updatedNod.getJsonObject("status").getString("name"), is("Available"));
    assertThat("available item in storage should not have a destination", updatedNod.containsKey("inTransitDestinationServicePointId"), is(false));
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("stored loan status is not closed", storedLoan.getJsonObject("status").getString("name"), is("Closed"));
    assertThat("item status snapshot in storage is not available", storedLoan.getString("itemStatus"), is("Available"));
    assertThat("Checkin Service Point Id should be stored", storedLoan.getString("checkinServicePointId"), is(primaryServicePoint.getId()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 10 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method itemCheckedInEventIsPublished.

@Test
void itemCheckedInEventIsPublished() {
    final IndividualResource james = usersFixture.james();
    final UUID checkInServicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(item -> item.withPrimaryServicePoint(checkInServicePointId));
    final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withPermanentLocation(homeLocation.getId()));
    ZonedDateTime checkOutDate = ZonedDateTime.of(2020, 1, 18, 18, 0, 0, 0, UTC);
    ZonedDateTime checkInDate = ZonedDateTime.of(2020, 1, 22, 15, 30, 0, 0, UTC);
    checkOutFixture.checkOutByBarcode(nod, james, checkOutDate);
    CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(checkInDate).at(checkInServicePointId));
    JsonObject checkedInLoan = checkInResponse.getLoan();
    // There should be four events published - first ones for "check out" and check out log event, second ones for "check in" and check in log event
    final var publishedEvents = waitAtMost(2, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
    final var checkedInEvent = publishedEvents.findFirst(byEventType(ITEM_CHECKED_IN.name()));
    assertThat(checkedInEvent, isValidItemCheckedInEvent(checkedInLoan));
    final var checkInLogEvent = publishedEvents.findFirst(byLogEventType(CHECK_IN.value()));
    assertThat(checkInLogEvent, isValidCheckInLogEvent(checkedInLoan));
    assertThatPublishedLoanLogRecordEventsAreValid(checkedInLoan);
}
Also used : FakePubSub(api.support.fakes.FakePubSub) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Aggregations

CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)27 IndividualResource (api.support.http.IndividualResource)27 Test (org.junit.jupiter.api.Test)27 JsonObject (io.vertx.core.json.JsonObject)22 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)19 UUID (java.util.UUID)16 ZonedDateTime (java.time.ZonedDateTime)9 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)7 ItemResource (api.support.http.ItemResource)6 RequestBuilder (api.support.builders.RequestBuilder)5 FeeFineBuilder (api.support.builders.FeeFineBuilder)4 FeeFineOwnerBuilder (api.support.builders.FeeFineOwnerBuilder)4 JsonObjectMatcher (api.support.matchers.JsonObjectMatcher)3 HashMap (java.util.HashMap)3 Response (org.folio.circulation.support.http.client.Response)3 Matcher (org.hamcrest.Matcher)3 Address (api.support.builders.Address)2 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)2 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)2 TemplateContextMatchers.servicePointNameMatcher (api.support.fixtures.TemplateContextMatchers.servicePointNameMatcher)2