Search in sources :

Example 11 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method overdueFineCalculatedCorrectlyWhenHourlyFeeFinePolicyIsApplied.

@Test
void overdueFineCalculatedCorrectlyWhenHourlyFeeFinePolicyIsApplied() {
    useFallbackPolicies(loanPoliciesFixture.create(new LoanPolicyBuilder().withId(UUID.randomUUID()).withName("Three days policy").withDescription("Can circulate item").rolling(Period.days(3)).unlimitedRenewals().renewFromSystemDate()).getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder().withId(UUID.randomUUID()).withName("One per hour overdue fine policy").withOverdueFine(new JsonObject().put("quantity", 1.0).put("intervalId", "hour")).withCountClosed(false)).getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    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);
    JsonObject servicePointOwner = new JsonObject();
    servicePointOwner.put("value", homeLocation.getJson().getString("primaryServicePoint"));
    servicePointOwner.put("label", "label");
    UUID ownerId = UUID.randomUUID();
    feeFineOwnersClient.create(new FeeFineOwnerBuilder().withId(ownerId).withOwner("fee-fine-owner").withServicePointOwner(Collections.singletonList(servicePointOwner)));
    UUID feeFineId = UUID.randomUUID();
    feeFinesClient.create(new FeeFineBuilder().withId(feeFineId).withFeeFineType("Overdue fine").withOwnerId(ownerId).withAutomatic(true).withDefaultAmount(1.0));
    CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(checkInDate).at(checkInServicePointId));
    JsonObject checkedInLoan = checkInResponse.getLoan();
    waitAtMost(1, SECONDS).until(accountsClient::getAll, hasSize(1));
    List<JsonObject> createdAccounts = accountsClient.getAll();
    assertThat("Fee/fine record should be created", createdAccounts, hasSize(1));
    JsonObject account = createdAccounts.get(0);
    assertThat(account, isValidOverdueFine(checkedInLoan, nod, homeLocation.getJson().getString("name"), ownerId, feeFineId, 7.0));
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) FeeFineBuilder(api.support.builders.FeeFineBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) OverdueFinePolicyBuilder(api.support.builders.OverdueFinePolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 12 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method canCheckInAnItemTwice.

@Test
void canCheckInAnItemTwice() {
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 1, 13, 25, 46, 0, UTC);
    final IndividualResource james = usersFixture.james();
    final UUID checkInServicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.withPrimaryServicePoint(checkInServicePointId));
    final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withTemporaryLocation(homeLocation.getId()).withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
    checkOutFixture.checkOutByBarcode(nod, james, loanDate);
    checkInFixture.checkInByBarcode(nod, ZonedDateTime.of(2018, 3, 5, 14, 23, 41, 0, UTC), checkInServicePointId);
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(nod, ZonedDateTime.of(2018, 3, 5, 14, 23, 41, 0, UTC), checkInServicePointId);
    assertThat("Response should not include a loan", checkInResponse.getJson().containsKey("loan"), is(false));
    assertThat("Response should include an item", checkInResponse.getJson().containsKey("item"), is(true));
    final JsonObject itemFromResponse = checkInResponse.getItem();
    assertThat("ID should be included for item", itemFromResponse.getString("id"), is(nod.getId()));
    assertThat("title is included for item", itemFromResponse.getString("title"), is("Nod"));
    assertThat("barcode is included for item", itemFromResponse.getString("barcode"), is("565578437802"));
    assertThat("has item enumeration", itemFromResponse.getString("enumeration"), is("v.70:no.1-6"));
    assertThat("has item chronology", itemFromResponse.getString("chronology"), is("1987:Jan.-June"));
    assertThat("has item volume", itemFromResponse.getString("volume"), is("testVolume"));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 13 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method canCloseAnOpenLoanByCheckingInTheItem.

@Test
void canCloseAnOpenLoanByCheckingInTheItem() {
    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.withTemporaryLocation(homeLocation.getId()).withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2018, 3, 1, 13, 25, 46, 0, UTC));
    ZonedDateTime expectedSystemReturnDate = ClockUtil.getZonedDateTime();
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(ZonedDateTime.of(2018, 3, 5, 14, 23, 41, 0, UTC)).at(checkInServicePointId));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("Closed loan should be present", loanRepresentation, notNullValue());
    assertThat(loanRepresentation.getString("userId"), is(james.getId().toString()));
    assertThat("Should have return date", loanRepresentation.getString("returnDate"), is("2018-03-05T14:23:41.000Z"));
    assertThat("Should have system return date similar to now", loanRepresentation.getString("systemReturnDate"), is(withinSecondsAfter(10, expectedSystemReturnDate)));
    assertThat("status is not closed", loanRepresentation.getJsonObject("status").getString("name"), is("Closed"));
    assertThat("action is not checkedin", loanRepresentation.getString("action"), is("checkedin"));
    assertThat("ID should be included for item", loanRepresentation.getJsonObject("item").getString("id"), is(nod.getId()));
    assertThat("title is taken from item", loanRepresentation.getJsonObject("item").getString("title"), is("Nod"));
    assertThat("barcode is taken from item", loanRepresentation.getJsonObject("item").getString("barcode"), is("565578437802"));
    assertThat("Should not have snapshot of item status, as current status is included", loanRepresentation.containsKey("itemStatus"), is(false));
    assertThat("Response should include an item", checkInResponse.getJson().containsKey("item"), is(true));
    final JsonObject itemFromResponse = checkInResponse.getItem();
    assertThat("title is included for item", itemFromResponse.getString("title"), is("Nod"));
    assertThat("ID should be included for item", itemFromResponse.getString("id"), is(nod.getId()));
    assertThat("barcode is included for item", itemFromResponse.getString("barcode"), is("565578437802"));
    assertThat("has item enumeration", itemFromResponse.getString("enumeration"), is("v.70:no.1-6"));
    assertThat("has item chronology", itemFromResponse.getString("chronology"), is("1987:Jan.-June"));
    assertThat("has item volume", itemFromResponse.getString("volume"), is("testVolume"));
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("item status is not available", updatedNod.getJsonObject("status").getString("name"), is("Available"));
    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(checkInServicePointId));
    verifyCheckInOperationRecorded(nod.getId(), checkInServicePointId);
}
Also used : 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)

Example 14 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method patronNoticeOnCheckInIsNotSentWhenCheckInLoanNoticeIsDefinedAndLoanExists.

@Test
void patronNoticeOnCheckInIsNotSentWhenCheckInLoanNoticeIsDefinedAndLoanExists() {
    UUID checkInTemplateId = UUID.randomUUID();
    JsonObject checkOutNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(checkInTemplateId).withCheckInEvent().create();
    JsonObject renewNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withEventType("Renew").create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with checkout notice").withLoanNotices(Arrays.asList(checkOutNoticeConfiguration, renewNoticeConfiguration));
    use(noticePolicy);
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 1, 13, 25, 46, 0, UTC);
    final IndividualResource james = usersFixture.james();
    final UUID checkInServicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(builder -> builder.withPrimaryServicePoint(checkInServicePointId));
    final ItemResource nod = itemsFixture.basedUponNod(builder -> builder.withTemporaryLocation(homeLocation.getId()));
    checkOutFixture.checkOutByBarcode(nod, james, loanDate);
    ZonedDateTime checkInDate = ZonedDateTime.of(2018, 3, 5, 14, 23, 41, 0, UTC);
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(checkInDate).at(checkInServicePointId));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    assertThat("Closed loan should be present", loanRepresentation, notNullValue());
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 15 with CheckInByBarcodeResponse

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

the class CheckInByBarcodeTests method verifyItemEffectiveLocationIdAtCheckOut.

@Test
public void verifyItemEffectiveLocationIdAtCheckOut() {
    final IndividualResource james = usersFixture.james();
    final UUID checkInServicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(item -> item.withPrimaryServicePoint(checkInServicePointId));
    final String anotherLocationId = locationsFixture.thirdFloor().getId().toString();
    final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withTemporaryLocation(homeLocation.getId()));
    checkOutFixture.checkOutByBarcode(nod, james);
    // Change the item's effective location to verify itemEffectiveLocationIdAtCheckOut is unchanged
    JsonObject update = nod.getJson();
    update.put("temporaryLocationId", anotherLocationId);
    itemsClient.replace(nod.getId(), update);
    final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).at(checkInServicePointId));
    JsonObject loanRepresentation = checkInResponse.getLoan();
    JsonObject updatedNod = itemsClient.getById(nod.getId()).getJson();
    assertThat("New location should not equal old location", homeLocation.getId().toString(), not(anotherLocationId));
    assertThat("The item's temporary location ID should be updated", updatedNod.getString("temporaryLocationId"), is(anotherLocationId));
    assertThat("itemEffectiveLocationIdAtCheckOut should match the original location ID at checkout", loanRepresentation.getString("itemEffectiveLocationIdAtCheckOut"), is(homeLocation.getId().toString()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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