use of api.support.fixtures.AgeToLostFixture.AgeToLostResult in project mod-circulation by folio-org.
the class AgedToLostScheduledNoticesProcessingTests method shouldStopSendingAgedToLostNoticesOnceItemIsDeclaredLost.
@Test
void shouldStopSendingAgedToLostNoticesOnceItemIsDeclaredLost() {
AgeToLostResult agedToLostLoan = createRecurringAgedToLostNotice();
declareLostFixtures.declareItemLost(agedToLostLoan.getLoan().getJson());
final ZonedDateTime firstRunTime = TIMING_PERIOD.plusDate(getAgedToLostDate(agedToLostLoan));
scheduledNoticeProcessingClient.runLoanNoticesProcessing(RECURRENCE_PERIOD.plusDate(firstRunTime).plusMinutes(1));
verifyNumberOfSentNotices(0);
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.fixtures.AgeToLostFixture.AgeToLostResult in project mod-circulation by folio-org.
the class AgedToLostScheduledNoticesProcessingTests method shouldStopSendingAgedToLostNoticesOnceItemIsRenewedThroughOverride.
@Test
void shouldStopSendingAgedToLostNoticesOnceItemIsRenewedThroughOverride() {
AgeToLostResult agedToLostLoan = createRecurringAgedToLostNotice();
final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
loansFixture.overrideRenewalByBarcode(agedToLostLoan.getItem(), agedToLostLoan.getUser(), "Test overriding", agedToLostLoan.getLoan().getJson().getString("dueDate"), okapiHeaders);
final ZonedDateTime firstRunTime = TIMING_PERIOD.plusDate(getAgedToLostDate(agedToLostLoan));
scheduledNoticeProcessingClient.runLoanNoticesProcessing(RECURRENCE_PERIOD.plusDate(firstRunTime).plusMinutes(1));
verifyNumberOfSentNotices(0);
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.fixtures.AgeToLostFixture.AgeToLostResult in project mod-circulation by folio-org.
the class AgedToLostScheduledNoticesProcessingTests method patronNoticeForAdjustmentOfFullyPaidLostItemFeeIsCreatedAndProcessed.
@Test
void patronNoticeForAdjustmentOfFullyPaidLostItemFeeIsCreatedAndProcessed() {
LostItemFeePolicyBuilder lostItemFeePolicyBuilder = lostItemFeePoliciesFixture.ageToLostAfterOneMinutePolicy().withSetCost(LOST_ITEM_FEE_AMOUNT).withLostItemProcessingFee(PROCESSING_FEE_AMOUNT);
AgeToLostResult agedToLostLoan = ageToLostFixture.createLoanAgeToLostAndChargeFees(lostItemFeePolicyBuilder, new NoticePolicyBuilder().active().withName("Aged to lost notice policy").withFeeFineNotices(List.of(new NoticeConfigurationBuilder().withAgedToLostReturnedEvent().withTemplateId(UPON_AT_TEMPLATE_ID).withUponAtTiming().create())));
final UUID loanId = agedToLostLoan.getLoanId();
final UUID userId = agedToLostLoan.getUser().getId();
final List<JsonObject> existingAccounts = accountsClient.getAll();
assertThat(existingAccounts, allOf(iterableWithSize(2), hasItems(isAccount(LOST_ITEM_FEE_AMOUNT, LOST_ITEM_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_FEE, agedToLostLoan.getUser().getId()), isAccount(PROCESSING_FEE_AMOUNT, PROCESSING_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_PROCESSING_FEE, agedToLostLoan.getUser().getId()))));
// one "charge" action per account
assertThat(feeFineActionsClient.getAll(), hasSize(2));
final List<Account> accounts = existingAccounts.stream().map(Account::from).collect(toList());
assertThat(accounts, hasSize(2));
final Account firstAccount = accounts.get(0);
final Account secondAccount = accounts.get(1);
feeFineAccountFixture.pay(firstAccount.getId(), firstAccount.getAmount().toDouble());
feeFineAccountFixture.transfer(secondAccount.getId(), secondAccount.getAmount().toDouble());
// 2 charges + 1 payment + 1 transfer
assertThat(feeFineActionsClient.getAll(), hasSize(4));
// closing a loan-related fee/fine should close the loan
eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loanId);
assertThat(loansFixture.getLoanById(agedToLostLoan.getLoanId()).getJson(), isClosed());
// check-in should refund both fees, no cancellations since both were paid/transferred fully
checkInFixture.checkInByBarcode(agedToLostLoan.getItem());
assertThat(itemsFixture.getById(agedToLostLoan.getItemId()).getJson(), isAvailable());
assertThat(loansFixture.getLoanById(agedToLostLoan.getLoanId()).getJson(), isClosed());
// 2 charges + 1 payment + 1 transfer + 2 credits + 2 refunds
assertThat(feeFineActionsClient.getAll(), hasSize(8));
final JsonObject lostItemFeeRefundAction = findFeeFineAction(ACTION_TYPE_REFUNDED_FULLY, LOST_ITEM_FEE_AMOUNT);
final JsonObject processingFeeRefundAction = findFeeFineAction(ACTION_TYPE_REFUNDED_FULLY, PROCESSING_FEE_AMOUNT);
final UUID refundLostItemFeeActionId = getId(lostItemFeeRefundAction);
final UUID refundProcessingFeeActionId = getId(processingFeeRefundAction);
final ZonedDateTime refundLostItemFeeActionDate = getActionDate(lostItemFeeRefundAction);
final ZonedDateTime refundProcessingFeeActionDate = getActionDate(processingFeeRefundAction);
verifyNumberOfSentNotices(0);
assertThat(scheduledNoticesClient.getAll(), allOf(iterableWithSize(2), hasItems(hasScheduledFeeFineNotice(refundLostItemFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundLostItemFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(refundProcessingFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundProcessingFeeActionDate, UPON_AT, null, true))));
ZonedDateTime maxActionDate = Stream.of(refundLostItemFeeActionDate, refundProcessingFeeActionDate).max(ZonedDateTime::compareTo).orElseThrow();
scheduledNoticeProcessingClient.runFeeFineNoticesProcessing(maxActionDate.plusSeconds(1));
checkSentFeeFineNotices(agedToLostLoan, Map.of(lostItemFeeRefundAction, UPON_AT_TEMPLATE_ID, processingFeeRefundAction, UPON_AT_TEMPLATE_ID));
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.fixtures.AgeToLostFixture.AgeToLostResult in project mod-circulation by folio-org.
the class AgedToLostScheduledNoticesProcessingTests method shouldStopSendingAgedToLostNoticesOnceItemIsClaimedReturned.
@Test
void shouldStopSendingAgedToLostNoticesOnceItemIsClaimedReturned() {
AgeToLostResult agedToLostLoan = createRecurringAgedToLostNotice();
claimItemReturnedFixture.claimItemReturned(new ClaimItemReturnedRequestBuilder().forLoan(agedToLostLoan.getLoanId().toString()).withItemClaimedReturnedDate(ClockUtil.getZonedDateTime()));
final ZonedDateTime firstRunTime = TIMING_PERIOD.plusDate(getAgedToLostDate(agedToLostLoan));
scheduledNoticeProcessingClient.runLoanNoticesProcessing(RECURRENCE_PERIOD.plusDate(firstRunTime).plusMinutes(1));
verifyNumberOfSentNotices(0);
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.fixtures.AgeToLostFixture.AgeToLostResult in project mod-circulation by folio-org.
the class AgedToLostScheduledNoticesProcessingTests method patronNoticesForForAgedToLostFineAdjustmentsAreCreatedAndProcessed.
@Test
void patronNoticesForForAgedToLostFineAdjustmentsAreCreatedAndProcessed() {
LostItemFeePolicyBuilder lostItemFeePolicyBuilder = lostItemFeePoliciesFixture.ageToLostAfterOneMinutePolicy().withSetCost(LOST_ITEM_FEE_AMOUNT).withLostItemProcessingFee(PROCESSING_FEE_AMOUNT);
AgeToLostResult agedToLostLoan = ageToLostFixture.createLoanAgeToLostAndChargeFees(lostItemFeePolicyBuilder, new NoticePolicyBuilder().active().withName("Aged to lost notice policy").withFeeFineNotices(List.of(new NoticeConfigurationBuilder().withAgedToLostReturnedEvent().withTemplateId(UPON_AT_TEMPLATE_ID).withUponAtTiming().create())));
final List<JsonObject> existingAccounts = accountsClient.getAll();
assertThat(existingAccounts, allOf(iterableWithSize(2), hasItems(isAccount(LOST_ITEM_FEE_AMOUNT, LOST_ITEM_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_FEE, agedToLostLoan.getUser().getId()), isAccount(PROCESSING_FEE_AMOUNT, PROCESSING_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_PROCESSING_FEE, agedToLostLoan.getUser().getId()))));
// one "charge" action per account
assertThat(feeFineActionsClient.getAll(), hasSize(2));
// create payments for both accounts to produce "refund" actions and notices
existingAccounts.forEach(account -> feeFineAccountFixture.pay(account.getString("id"), // partial payment to produce "cancel" actions and notices
account.getDouble("remaining") / 2));
// 2 charges + 2 payments
assertThat(feeFineActionsClient.getAll(), hasSize(4));
// check-in should refund and cancel both "Lost item fee" and "Lost item processing fee"
checkInFixture.checkInByBarcode(agedToLostLoan.getItem());
assertThat(itemsFixture.getById(agedToLostLoan.getItemId()).getJson(), isAvailable());
assertThat(loansFixture.getLoanById(agedToLostLoan.getLoanId()).getJson(), isClosed());
// 2 charges + 2 payments + 2 credits + 2 refunds + 2 cancellations
assertThat(feeFineActionsClient.getAll(), hasSize(10));
final UUID loanId = agedToLostLoan.getLoanId();
final UUID userId = agedToLostLoan.getUser().getId();
final JsonObject refundLostItemFeeAction = findFeeFineAction(ACTION_TYPE_REFUNDED_PARTIALLY, LOST_ITEM_FEE_PAYMENT_AMOUNT);
final JsonObject refundProcessingFeeAction = findFeeFineAction(ACTION_TYPE_REFUNDED_PARTIALLY, PROCESSING_FEE_PAYMENT_AMOUNT);
final JsonObject cancelLostItemFeeAction = findFeeFineAction(ACTION_TYPE_CANCELLED, LOST_ITEM_FEE_AMOUNT);
final JsonObject cancelProcessingFeeAction = findFeeFineAction(ACTION_TYPE_CANCELLED, PROCESSING_FEE_AMOUNT);
final UUID refundLostItemFeeActionId = getId(refundLostItemFeeAction);
final UUID refundProcessingFeeActionId = getId(refundProcessingFeeAction);
final UUID cancelLostItemFeeActionId = getId(cancelLostItemFeeAction);
final UUID cancelProcessingFeeActionId = getId(cancelProcessingFeeAction);
final ZonedDateTime refundLostItemFeeActionDate = getActionDate(refundLostItemFeeAction);
final ZonedDateTime refundProcessingFeeActionDate = getActionDate(refundProcessingFeeAction);
final ZonedDateTime cancelLostItemFeeActionDate = getActionDate(cancelLostItemFeeAction);
final ZonedDateTime cancelProcessingFeeActionDate = getActionDate(cancelProcessingFeeAction);
verifyNumberOfSentNotices(0);
assertThat(scheduledNoticesClient.getAll(), allOf(iterableWithSize(4), hasItems(hasScheduledFeeFineNotice(refundLostItemFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundLostItemFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(refundProcessingFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundProcessingFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(cancelLostItemFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, cancelLostItemFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(cancelProcessingFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, cancelProcessingFeeActionDate, UPON_AT, null, true))));
ZonedDateTime maxActionDate = Stream.of(cancelLostItemFeeActionDate, cancelProcessingFeeActionDate, refundLostItemFeeActionDate, refundProcessingFeeActionDate).max(ZonedDateTime::compareTo).orElseThrow();
scheduledNoticeProcessingClient.runFeeFineNoticesProcessing(maxActionDate.plusSeconds(1));
checkSentFeeFineNotices(agedToLostLoan, Map.of(refundLostItemFeeAction, UPON_AT_TEMPLATE_ID, refundProcessingFeeAction, UPON_AT_TEMPLATE_ID, cancelLostItemFeeAction, UPON_AT_TEMPLATE_ID, cancelProcessingFeeAction, UPON_AT_TEMPLATE_ID));
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 4);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Aggregations