use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method renewalNoticeIsSentWhenPolicyDefinesRenewalNoticeConfiguration.
@Test
void renewalNoticeIsSentWhenPolicyDefinesRenewalNoticeConfiguration() {
UUID renewalTemplateId = UUID.randomUUID();
JsonObject renewalNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(renewalTemplateId).withRenewalEvent().create();
JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
NoticePolicyBuilder policyWithRenewalNotice = new NoticePolicyBuilder().withName("Policy with renewal notice").withLoanNotices(Arrays.asList(renewalNoticeConfiguration, checkInNoticeConfiguration));
LoanPolicyBuilder limitedRenewalsLoanPolicy = new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(Period.months(1)).limitedRenewals(3);
use(limitedRenewalsLoanPolicy, policyWithRenewalNotice);
ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), StringUtils.EMPTY, "ItemPrefix", "ItemSuffix", "");
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
final IndividualResource steve = usersFixture.steve();
final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
IndividualResource loanAfterRenewal = loansFixture.renewLoan(smallAngryPlanet, steve);
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
int expectedRenewalLimit = 3;
int expectedRenewalsRemaining = 2;
Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(steve));
noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(smallAngryPlanet, true));
noticeContextMatchers.putAll(TemplateContextMatchers.getLoanContextMatchers(loanAfterRenewal));
noticeContextMatchers.putAll(TemplateContextMatchers.getLoanPolicyContextMatchers(expectedRenewalLimit, expectedRenewalsRemaining));
assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(steve.getId(), renewalTemplateId, noticeContextMatchers)));
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RequestsAPIUpdatingTests method cancellationReasonPublicDescriptionIsUsedAsReasonForCancellationToken.
@Test
void cancellationReasonPublicDescriptionIsUsedAsReasonForCancellationToken() {
UUID requestCancellationTemplateId = UUID.randomUUID();
JsonObject requestCancellationConfiguration = new NoticeConfigurationBuilder().withTemplateId(requestCancellationTemplateId).withEventType(REQUEST_CANCELLATION).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with request cancellation notice").withLoanNotices(Collections.singletonList(requestCancellationConfiguration));
useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
final ItemResource temeraire = itemsFixture.basedUponTemeraire();
final IndividualResource requester = usersFixture.steve();
ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
final IndividualResource exampleServicePoint = servicePointsFixture.cd1();
IndividualResource createdRequest = requestsClient.create(new RequestBuilder().page().withRequestDate(requestDate).forItem(temeraire).by(requester).fulfilToHoldShelf().withPickupServicePointId(exampleServicePoint.getId()).withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)));
final IndividualResource itemNotAvailable = cancellationReasonsFixture.itemNotAvailable();
JsonObject updatedRequest = RequestBuilder.from(createdRequest).cancelled().withCancellationReasonId(itemNotAvailable.getId()).withCancellationAdditionalInformation("Cancellation info").create();
requestsClient.replace(createdRequest.getId(), updatedRequest);
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(requester));
noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(temeraire, true));
noticeContextMatchers.putAll(TemplateContextMatchers.getRequestContextMatchers(updatedRequest));
noticeContextMatchers.putAll(TemplateContextMatchers.getCancelledRequestContextMatchers(updatedRequest));
noticeContextMatchers.put("request.reasonForCancellation", is(itemNotAvailable.getJson().getString(CANCELLATION_REASON_PUBLIC_DESCRIPTION)));
assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(requester.getId(), requestCancellationTemplateId, noticeContextMatchers)));
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class CancelRequestTests method patronNoticeIsNotSentWhenPatronNoticeRequestFails.
@Test
void patronNoticeIsNotSentWhenPatronNoticeRequestFails() {
UUID requestCancelledTemplateId = UUID.randomUUID();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("test policy").withLoanNotices(Collections.singletonList(new NoticeConfigurationBuilder().withTemplateId(requestCancelledTemplateId).withEventType("Request cancellation").create()));
useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
UUID id = UUID.randomUUID();
UUID pickupServicePointId = servicePointsFixture.cd1().getId();
ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource requester = usersFixture.steve();
ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
IndividualResource request = requestsFixture.place(new RequestBuilder().withId(id).open().page().forItem(item).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)).withPickupServicePointId(pickupServicePointId).withTags(new RequestBuilder.Tags(asList("new", "important"))));
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
requestsFixture.cancelRequest(request);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Aggregations