Search in sources :

Example 6 with FeeFineOwnerBuilder

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

the class CheckInByBarcodeTests method overdueFineIsNotCreatedWhenThereIsNoOwnerForServicePoint.

@Test
void overdueFineIsNotCreatedWhenThereIsNoOwnerForServicePoint() {
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardDoNotCountClosed().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()));
    checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, UTC));
    final UUID servicePointForOwner = servicePointsFixture.cd2().getId();
    JsonObject servicePointOwner = new JsonObject();
    servicePointOwner.put("value", servicePointForOwner.toString());
    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));
    checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(ZonedDateTime.of(2020, 1, 25, 12, 0, 0, 0, UTC)).at(checkInServicePointId));
    waitAtMost(1, SECONDS);
    List<JsonObject> createdAccounts = accountsClient.getAll();
    assertThat("No fee/fine records should have been created", createdAccounts, hasSize(0));
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) JsonObject(io.vertx.core.json.JsonObject) FeeFineBuilder(api.support.builders.FeeFineBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 7 with FeeFineOwnerBuilder

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

the class CheckInByBarcodeTests method overdueFineShouldBeChargedWhenItemIsOverdue.

@Test
void overdueFineShouldBeChargedWhenItemIsOverdue() {
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardDoNotCountClosed().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()));
    checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, UTC));
    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));
    CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(ZonedDateTime.of(2020, 1, 25, 12, 0, 0, 0, UTC)).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, 5.0));
    waitAtMost(1, SECONDS).until(feeFineActionsClient::getAll, hasSize(1));
    List<JsonObject> createdFeeFineActions = feeFineActionsClient.getAll();
    assertThat("Fee/fine action record should be created", createdFeeFineActions, hasSize(1));
    JsonObject createdFeeFineAction = createdFeeFineActions.get(0);
    assertThat("user ID is included", createdFeeFineAction.getString("userId"), is(checkedInLoan.getString("userId")));
    assertThat("account ID is included", createdFeeFineAction.getString("accountId"), is(account.getString("id")));
    assertThat("balance is included", createdFeeFineAction.getDouble("balance"), is(account.getDouble("amount")));
    assertThat("amountAction is included", createdFeeFineAction.getDouble("amountAction"), is(account.getDouble("amount")));
    assertThat("typeAction is included", createdFeeFineAction.getString("typeAction"), is("Overdue fine"));
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) JsonObject(io.vertx.core.json.JsonObject) FeeFineBuilder(api.support.builders.FeeFineBuilder) 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 8 with FeeFineOwnerBuilder

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

the class CheckInByBarcodeTests method noOverdueFineShouldBeChargedForOverdueFinePolicyWithNoOverdueFine.

@Test
void noOverdueFineShouldBeChargedForOverdueFinePolicyWithNoOverdueFine() {
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.noOverdueFine().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()));
    checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, UTC));
    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));
    checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(ZonedDateTime.of(2020, 1, 25, 12, 0, 0, 0, UTC)).at(checkInServicePointId));
    waitAtLeast(1, SECONDS).until(accountsClient::getAll, empty());
    waitAtLeast(1, SECONDS).until(feeFineActionsClient::getAll, empty());
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) JsonObject(io.vertx.core.json.JsonObject) FeeFineBuilder(api.support.builders.FeeFineBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 9 with FeeFineOwnerBuilder

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

the class CheckInByBarcodeTests method overdueFineIsChargedForCorrectOwnerWhenMultipleOwnersExist.

@Test
void overdueFineIsChargedForCorrectOwnerWhenMultipleOwnersExist() {
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardDoNotCountClosed().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()));
    checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, UTC));
    for (int i = 0; i < 10; i++) {
        feeFineOwnersClient.create(new FeeFineOwnerBuilder().withId(UUID.randomUUID()).withOwner("fee-fine-owner-" + i));
    }
    waitAtMost(3, SECONDS).until(feeFineOwnersClient::getAll, hasSize(10));
    JsonObject servicePointOwner = new JsonObject();
    servicePointOwner.put("value", homeLocation.getJson().getString("primaryServicePoint"));
    servicePointOwner.put("label", "label");
    UUID servicePointOwnerId = UUID.randomUUID();
    feeFineOwnersClient.create(new FeeFineOwnerBuilder().withId(servicePointOwnerId).withOwner("fee-fine-owner").withServicePointOwner(Collections.singletonList(servicePointOwner)));
    UUID feeFineId = UUID.randomUUID();
    feeFinesClient.create(new FeeFineBuilder().withId(feeFineId).withFeeFineType("Overdue fine").withAutomatic(true));
    CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(ZonedDateTime.of(2020, 1, 25, 12, 0, 0, 0, UTC)).at(checkInServicePointId));
    JsonObject checkedInLoan = checkInResponse.getLoan();
    waitAtMost(3, 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"), servicePointOwnerId, feeFineId, 5.0));
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) JsonObject(io.vertx.core.json.JsonObject) FeeFineBuilder(api.support.builders.FeeFineBuilder) 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 10 with FeeFineOwnerBuilder

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

the class RenewalAPITests method overdueFineShouldNotBeChargedWhenShouldBeForgiven.

@Test
void overdueFineShouldNotBeChargedWhenShouldBeForgiven() throws InterruptedException {
    IndividualResource loanPolicy = loanPoliciesFixture.create(new LoanPolicyBuilder().rolling(Period.from(10, "Days")));
    useFallbackPolicies(loanPolicy.getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.activeNotice().getId(), overdueFinePoliciesFixture.facultyStandardShouldForgiveFine().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()));
    checkOutFixture.checkOutByBarcode(nod, james, ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, UTC));
    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));
    loansFixture.renewLoan(nod, james);
    TimeUnit.SECONDS.sleep(1);
    List<JsonObject> createdAccounts = accountsClient.getAll();
    assertThat("Fee/fine record shouldn't have been created", createdAccounts, hasSize(0));
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) FeeFineBuilder(api.support.builders.FeeFineBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

FeeFineOwnerBuilder (api.support.builders.FeeFineOwnerBuilder)11 FeeFineBuilder (api.support.builders.FeeFineBuilder)10 IndividualResource (api.support.http.IndividualResource)10 JsonObject (io.vertx.core.json.JsonObject)10 UUID (java.util.UUID)10 Test (org.junit.jupiter.api.Test)9 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)8 CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)4 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)3 ZonedDateTime (java.time.ZonedDateTime)3 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)2 Address (api.support.builders.Address)1 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)1 OverdueFinePolicyBuilder (api.support.builders.OverdueFinePolicyBuilder)1 RequestBuilder (api.support.builders.RequestBuilder)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID.randomUUID (java.util.UUID.randomUUID)1 lombok.val (lombok.val)1