use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.
the class DueDateScheduledNoticesTests method noticesShouldBeRescheduledAfterRenewal.
@Test
void noticesShouldBeRescheduledAfterRenewal() {
UUID beforeTemplateId = UUID.randomUUID();
Period beforePeriod = Period.days(2);
Period beforeRecurringPeriod = Period.hours(6);
UUID uponAtTemplateId = UUID.randomUUID();
UUID afterTemplateId = UUID.randomUUID();
Period afterPeriod = Period.days(3);
Period afterRecurringPeriod = Period.hours(4);
JsonObject beforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(beforeTemplateId).withDueDateEvent().withBeforeTiming(beforePeriod).recurring(beforeRecurringPeriod).sendInRealTime(true).create();
JsonObject uponAtDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(uponAtTemplateId).withDueDateEvent().withUponAtTiming().sendInRealTime(false).create();
JsonObject afterDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(afterTemplateId).withDueDateEvent().withAfterTiming(afterPeriod).recurring(afterRecurringPeriod).sendInRealTime(true).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Arrays.asList(beforeDueDateNoticeConfiguration, uponAtDueDateNoticeConfiguration, afterDueDateNoticeConfiguration));
use(noticePolicy);
IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
final IndividualResource borrower = usersFixture.steve();
final IndividualResource loan = checkOutFixture.checkOutByBarcode(item, borrower);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
verifyNumberOfScheduledNotices(6);
IndividualResource renewedLoan = loansFixture.renewLoan(item, borrower);
ZonedDateTime dueDateAfterRenewal = getDateTimeProperty(renewedLoan.getJson(), "dueDate");
Matcher<Iterable<JsonObject>> scheduledNoticesAfterRenewalMatcher = hasItems(hasScheduledLoanNotice(loan.getId(), beforePeriod.minusDate(dueDateAfterRenewal), BEFORE_TIMING, beforeTemplateId, beforeRecurringPeriod, true), hasScheduledLoanNotice(loan.getId(), dueDateAfterRenewal, UPON_AT_TIMING, uponAtTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), afterPeriod.plusDate(dueDateAfterRenewal), AFTER_TIMING, afterTemplateId, afterRecurringPeriod, true));
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, scheduledNoticesAfterRenewalMatcher);
verifyNumberOfScheduledNotices(6);
}
use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.
the class LostItemPolicyTest method shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemRecalled.
@ParameterizedTest
@CsvSource(value = { "Minutes, 43", "Hours, 12", "Days, 29", "Weeks, 1", "Months, 5" })
void shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemRecalled(String interval, int duration) {
final Period period = from(duration, interval);
final LostItemPolicy lostItemPolicy = lostItemPolicyWithRecallAgePeriod(period);
final ZonedDateTime loanDueDate = period.minusDate(getZonedDateTime()).minusSeconds(1);
assertTrue(lostItemPolicy.canAgeLoanToLost(true, loanDueDate));
}
use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.
the class LostItemPolicyTest method shouldRefundLostFeesIfPeriodIsPassing.
@ParameterizedTest
@CsvSource(value = { "Minutes, 656", "Hours, 6", "Days, 98", "Weeks, 43", "Months, 5" })
void shouldRefundLostFeesIfPeriodIsPassing(String interval, int duration) {
final Period period = from(duration, interval);
final LostItemFeePolicyBuilder builder = new LostItemFeePolicyBuilder().withFeeRefundInterval(period);
final LostItemPolicy lostItemPolicy = LostItemPolicy.from(builder.create());
final ZonedDateTime now = ZonedDateTime.of(2022, 3, 27, 11, 25, 35, 0, ZoneId.of("UTC"));
setClock(fixed(now.toInstant(), ZoneOffset.UTC));
final ZonedDateTime lostDateTime = period.minusDate(now);
assertTrue(lostItemPolicy.shouldRefundFees(lostDateTime));
}
use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.
the class LostItemPolicyTest method shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemNotRecalled.
@ParameterizedTest
@CsvSource(value = { "Minutes, 43", "Hours, 12", "Days, 29", "Weeks, 1", "Months, 5" })
void shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemNotRecalled(String interval, int duration) {
final Period period = from(duration, interval);
final LostItemPolicy lostItemPolicy = lostItemPolicyWithAgePeriod(period);
final ZonedDateTime loanDueDate = period.minusDate(getZonedDateTime()).minusSeconds(1);
assertTrue(lostItemPolicy.canAgeLoanToLost(false, loanDueDate));
}
use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.
the class LostItemPolicyTest method canCalculateBillingDateWhenPatronIsBilledImmediatelyForNotRecalledItem.
@ParameterizedTest
@CsvSource(value = { "Minutes, 0", "Hours, 0", "Days, 0", "Weeks, 0", "Months, 0", "null, null" }, nullValues = { "null" })
public void canCalculateBillingDateWhenPatronIsBilledImmediatelyForNotRecalledItem(String interval, Integer duration) {
final Period billPatronInterval = duration == null && interval == null ? null : Period.from(duration, interval);
final ZonedDateTime agedToLostDate = getZonedDateTime();
final LostItemPolicy lostItemPolicy = LostItemPolicy.from(new LostItemFeePolicyBuilder().withPatronBilledAfterItemAgedToLost(billPatronInterval).withSetCost(10.0).doNotChargeProcessingFeeWhenAgedToLost().create());
final ZonedDateTime actualBillingDate = lostItemPolicy.calculateDateTimeWhenPatronBilledForAgedToLost(false, agedToLostDate);
assertThat(actualBillingDate, is(agedToLostDate));
}
Aggregations