use of api.support.builders.MoveRequestBuilder in project mod-circulation by folio-org.
the class RequestsAPICreationTests method recallNoticeToLoanOwnerIsSentForMovedRecallIfDueDateIsNotChanged.
@Test
void recallNoticeToLoanOwnerIsSentForMovedRecallIfDueDateIsNotChanged() {
UUID recallToLoanOwnerTemplateId = UUID.randomUUID();
JsonObject recallToLoanOwnerNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(recallToLoanOwnerTemplateId).withEventType(ITEM_RECALLED).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with recall notice").withLoanNotices(Collections.singletonList(recallToLoanOwnerNoticeConfiguration));
LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().withName("Policy with recall notice").withDescription("Recall configuration has no effect on due date").rolling(Period.weeks(3)).withClosedLibraryDueDateManagement(DueDateManagement.KEEP_THE_CURRENT_DUE_DATE.getValue()).withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(3)).withRecallsRecallReturnInterval(Period.weeks(1));
useFallbackPolicies(loanPoliciesFixture.create(loanPolicy).getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
UUID pickupServicePointId = servicePointsFixture.cd1().getId();
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
IndividualResource itemToMoveTo = items.get(0);
IndividualResource itemToMoveFrom = items.get(1);
IndividualResource requester = usersFixture.rebecca();
IndividualResource loanOwner = usersFixture.jessica();
ZonedDateTime loanDate = ZonedDateTime.of(2020, 7, 22, 10, 22, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(itemToMoveTo, loanOwner, loanDate);
checkOutFixture.checkOutByBarcode(itemToMoveFrom, loanOwner, loanDate);
ZonedDateTime requestDate = loanDate.plusDays(1);
mockClockManagerToReturnFixedDateTime(requestDate);
IndividualResource recallRequest = requestsFixture.place(new RequestBuilder().withId(UUID.randomUUID()).open().recall().forItem(itemToMoveFrom).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(LocalDate.of(2020, 7, 30)).withHoldShelfExpiration(LocalDate.of(2020, 8, 31)).withPickupServicePointId(pickupServicePointId).withTags(new RequestBuilder.Tags(asList("new", "important"))));
requestsFixture.move(new MoveRequestBuilder(recallRequest.getId(), itemToMoveTo.getId(), RECALL.getValue()));
// Recall notice to loan owner should be sent twice without changing due date
verifyNumberOfSentNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.builders.MoveRequestBuilder in project mod-circulation by folio-org.
the class MoveRequestPolicyTests method moveRecallRequestWithExistingRecallsAndWithNoPolicyValuesChangesDueDateToSystemDate.
@Test
void moveRecallRequestWithExistingRecallsAndWithNoPolicyValuesChangesDueDateToSystemDate() {
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
final IndividualResource itemToMoveTo = items.get(0);
final IndividualResource itemToMoveFrom = items.get(1);
final IndividualResource steve = usersFixture.steve();
final IndividualResource charlotte = usersFixture.charlotte();
final IndividualResource jessica = usersFixture.jessica();
// steve checks out itemToMoveTo
final IndividualResource loan = checkOutFixture.checkOutByBarcode(itemToMoveTo, steve, getZonedDateTime());
final String originalDueDate = loan.getJson().getString("dueDate");
// charlotte places recall request on itemToMoveTo
requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveTo, charlotte, getZonedDateTime().minusHours(1), RequestType.RECALL.getValue());
JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
assertThat("due date is the original date", storedLoan.getString("dueDate"), not(originalDueDate));
final String expectedDueDate = formatDateTime(getZonedDateTime());
assertThat("due date is not the current date", storedLoan.getString("dueDate"), is(expectedDueDate));
// charlotte checks out itemToMoveFrom
checkOutFixture.checkOutByBarcode(itemToMoveFrom, charlotte);
// jessica places recall request on itemToMoveFrom
IndividualResource requestByJessica = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveFrom, jessica, getZonedDateTime(), RequestType.RECALL.getValue());
// There should be 2 notices for each recall
waitAtMost(1, SECONDS).until(() -> patronNoticesForRecipientWasSent(steve));
waitAtMost(1, SECONDS).until(() -> patronNoticesForRecipientWasSent(charlotte));
verifyNumberOfSentNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
// move jessica's recall request from itemToMoveFrom to itemToMoveTo
IndividualResource moveRequest = requestsFixture.move(new MoveRequestBuilder(requestByJessica.getId(), itemToMoveTo.getId(), RequestType.RECALL.getValue()));
assertThat("Move request should have correct item id", moveRequest.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
assertThat("Move request should have correct type", moveRequest.getJson().getString("requestType"), is(RequestType.RECALL.getValue()));
storedLoan = loansStorageClient.getById(loan.getId()).getJson();
assertThat("due date has changed", storedLoan.getString("dueDate"), is(expectedDueDate));
assertThat("move recall request unexpectedly sent another patron notice", FakeModNotify.getSentPatronNotices(), hasSize(2));
verifyNumberOfSentNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.builders.MoveRequestBuilder in project mod-circulation by folio-org.
the class MoveRequestPolicyTests method moveRecallRequestWithoutExistingRecallsAndWithNoPolicyValuesChangesDueDateToSystemDate.
@Test
void moveRecallRequestWithoutExistingRecallsAndWithNoPolicyValuesChangesDueDateToSystemDate() {
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
final IndividualResource itemToMoveTo = items.get(0);
final IndividualResource itemToMoveFrom = items.get(1);
final IndividualResource steve = usersFixture.steve();
final IndividualResource charlotte = usersFixture.charlotte();
final IndividualResource jessica = usersFixture.jessica();
// steve checks out itemToMoveTo
final IndividualResource loan = checkOutFixture.checkOutByBarcode(itemToMoveTo, steve, getZonedDateTime());
final String originalDueDate = loan.getJson().getString("dueDate");
// charlotte checks out itemToMoveFrom
checkOutFixture.checkOutByBarcode(itemToMoveFrom, charlotte);
// jessica places recall request on itemToMoveFrom
IndividualResource requestByJessica = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveFrom, jessica, getZonedDateTime(), RequestType.RECALL.getValue());
// notice for the recall is expected
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
// move jessica's recall request from itemToMoveFrom to itemToMoveTo
IndividualResource moveRequest = requestsFixture.move(new MoveRequestBuilder(requestByJessica.getId(), itemToMoveTo.getId(), RequestType.RECALL.getValue()));
assertThat("Move request should have correct item id", moveRequest.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
assertThat("Move request should have correct type", moveRequest.getJson().getString("requestType"), is(RequestType.RECALL.getValue()));
final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
assertThat("due date is the original date", storedLoan.getString("dueDate"), not(originalDueDate));
final String expectedDueDate = formatDateTime(getZonedDateTime());
assertThat("due date is not the current date", storedLoan.getString("dueDate"), is(expectedDueDate));
verifyNumberOfSentNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.builders.MoveRequestBuilder in project mod-circulation by folio-org.
the class MoveRequestPolicyTests method moveRecallRequestWithoutExistingRecallsAndWithMGDAndRDValuesChangesDueDateToRD.
@Test
void moveRecallRequestWithoutExistingRecallsAndWithMGDAndRDValuesChangesDueDateToRD() {
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
final IndividualResource itemToMoveTo = items.get(0);
final IndividualResource itemToMoveFrom = items.get(1);
final IndividualResource steve = usersFixture.steve();
final IndividualResource charlotte = usersFixture.charlotte();
final IndividualResource jessica = usersFixture.jessica();
final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.months(2));
final IndividualResource loanPolicy = loanPoliciesFixture.create(canCirculateRollingPolicy);
useFallbackPolicies(loanPolicy.getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
final IndividualResource loan = checkOutFixture.checkOutByBarcode(itemToMoveTo, steve, getZonedDateTime());
final String originalDueDate = loan.getJson().getString("dueDate");
// charlotte checks out itemToMoveFrom
checkOutFixture.checkOutByBarcode(itemToMoveFrom, charlotte);
// jessica places recall request on itemToMoveFrom
IndividualResource requestByJessica = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveFrom, jessica, getZonedDateTime(), RequestType.RECALL.getValue());
// One notice for the recall is expected
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
// move jessica's recall request from itemToMoveFrom to itemToMoveTo
IndividualResource moveRequest = requestsFixture.move(new MoveRequestBuilder(requestByJessica.getId(), itemToMoveTo.getId(), RequestType.RECALL.getValue()));
assertThat("Move request should have correct item id", moveRequest.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
assertThat("Move request should have correct type", moveRequest.getJson().getString("requestType"), is(RequestType.RECALL.getValue()));
final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
assertThat("due date is the original date", storedLoan.getString("dueDate"), not(originalDueDate));
final String expectedDueDate = formatDateTime(getZonedDateTime().plusMonths(2));
assertThat("due date is not the recall due date (2 months)", storedLoan.getString("dueDate"), is(expectedDueDate));
assertThat("move recall request notice has not been sent", FakeModNotify.getSentPatronNotices(), hasSize(2));
verifyNumberOfSentNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.builders.MoveRequestBuilder in project mod-circulation by folio-org.
the class MoveRequestTests method canMoveAHoldShelfRequestToAnEmptyQueue.
@Test
void canMoveAHoldShelfRequestToAnEmptyQueue() {
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
IndividualResource itemToMoveFrom = items.get(0);
IndividualResource itemToMoveTo = items.get(1);
IndividualResource james = usersFixture.james();
IndividualResource jessica = usersFixture.jessica();
IndividualResource charlotte = usersFixture.charlotte();
// james checks out itemToMoveFrom
checkOutFixture.checkOutByBarcode(itemToMoveFrom, james);
// charlotte checks out itemToMoveTo
checkOutFixture.checkOutByBarcode(itemToMoveTo, charlotte);
// make requests for itemToMoveTo
IndividualResource requestByJessica = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveFrom, jessica, getZonedDateTime());
// move jessica's hold shelf request from itemToMoveFrom to itemToMoveTo
IndividualResource moveRequest = requestsFixture.move(new MoveRequestBuilder(requestByJessica.getId(), itemToMoveTo.getId()));
assertThat("Move request should have correct item id", moveRequest.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
requestByJessica = requestsClient.get(requestByJessica);
assertThat(requestByJessica.getJson().getInteger("position"), is(1));
assertThat(requestByJessica.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
retainsStoredSummaries(requestByJessica);
// check item queues are correct size
MultipleRecords<JsonObject> itemToMoveFromQueue = requestsFixture.getQueueFor(itemToMoveFrom);
assertThat(itemToMoveFromQueue.getTotalRecords(), is(0));
MultipleRecords<JsonObject> itemToMoveToQueue = requestsFixture.getQueueFor(itemToMoveTo);
assertThat(itemToMoveToQueue.getTotalRecords(), is(1));
}
Aggregations