use of api.support.builders.FeeFineOwnerBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method overdueFineShouldBeChargedWhenItemIsOverdue.
@Test
void overdueFineShouldBeChargedWhenItemIsOverdue() throws InterruptedException {
IndividualResource loanPolicy = loanPoliciesFixture.create(new LoanPolicyBuilder().rolling(Period.from(10, "Days")));
useFallbackPolicies(loanPolicy.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()));
final IndividualResource loan = 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));
loansFixture.renewLoan(nod, james);
TimeUnit.SECONDS.sleep(1);
List<JsonObject> createdAccounts = accountsClient.getAll();
assertThat("Fee/fine record should be created", createdAccounts, hasSize(1));
JsonObject account = createdAccounts.get(0);
assertThat(account, OverdueFineMatcher.isValidOverdueFine(loan.getJson(), nod, homeLocation.getJson().getString("name"), ownerId, feeFineId, 5.0));
Awaitility.await().atMost(1, TimeUnit.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.is(loan.getJson().getString("userId")));
assertThat("account ID is included", createdFeeFineAction.getString("accountId"), Is.is(account.getString("id")));
assertThat("balance is included", createdFeeFineAction.getDouble("balance"), Is.is(account.getDouble("amount")));
assertThat("amountAction is included", createdFeeFineAction.getDouble("amountAction"), Is.is(account.getDouble("amount")));
assertThat("typeAction is included", createdFeeFineAction.getString("typeAction"), Is.is("Overdue fine"));
}
Aggregations