Search in sources :

Example 1 with AgeToLostResult

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);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) Test(org.junit.jupiter.api.Test)

Example 2 with AgeToLostResult

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);
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) Test(org.junit.jupiter.api.Test)

Example 3 with AgeToLostResult

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);
}
Also used : AccountMatchers.isAccount(api.support.matchers.AccountMatchers.isAccount) Account(org.folio.circulation.domain.Account) LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with AgeToLostResult

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);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) ClaimItemReturnedRequestBuilder(api.support.builders.ClaimItemReturnedRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with AgeToLostResult

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);
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

AgeToLostResult (api.support.fixtures.AgeToLostFixture.AgeToLostResult)9 ZonedDateTime (java.time.ZonedDateTime)9 Test (org.junit.jupiter.api.Test)9 LostItemFeePolicyBuilder (api.support.builders.LostItemFeePolicyBuilder)6 JsonObject (io.vertx.core.json.JsonObject)6 UUID (java.util.UUID)6 DeclareItemLostRequestBuilder (api.support.builders.DeclareItemLostRequestBuilder)3 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)3 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)3 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ClaimItemReturnedRequestBuilder (api.support.builders.ClaimItemReturnedRequestBuilder)2 OkapiHeaders (api.support.http.OkapiHeaders)2 AccountMatchers.isAccount (api.support.matchers.AccountMatchers.isAccount)2 APITests (api.support.APITests)1 FakeModNotify (api.support.fakes.FakeModNotify)1 TemplateContextMatchers.getFeeActionContextMatcher (api.support.fixtures.TemplateContextMatchers.getFeeActionContextMatcher)1 TemplateContextMatchers.getFeeChargeContextMatcher (api.support.fixtures.TemplateContextMatchers.getFeeChargeContextMatcher)1 TemplateContextMatchers.getItemContextMatchers (api.support.fixtures.TemplateContextMatchers.getItemContextMatchers)1 TemplateContextMatchers.getLoanContextMatchers (api.support.fixtures.TemplateContextMatchers.getLoanContextMatchers)1