Search in sources :

Example 11 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class RequestsAPILoanRenewalTests method allowRenewalWithHoldsWhenProfileIsFixedUseLoanSchedule.

@Test
void allowRenewalWithHoldsWhenProfileIsFixedUseLoanSchedule() {
    final ZonedDateTime from = getZonedDateTime().minusMonths(3);
    final ZonedDateTime to = getZonedDateTime().plusMonths(3);
    final ZonedDateTime dueDate = to.plusDays(15);
    final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource rebecca = usersFixture.rebecca();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, rebecca);
    IndividualResource schedule = loanPoliciesFixture.createSchedule(new FixedDueDateSchedulesBuilder().withId(UUID.randomUUID()).withName("Can circulate schedule").withDescription("descr").addSchedule(new FixedDueDateSchedule(from, to, dueDate)));
    JsonObject holds = new JsonObject().put("renewItemsWithRequest", true);
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().fixed(schedule.getId()).withName("Fixed with holds").withDescription("Fixed policy with holds").withHolds(holds);
    useWithActiveNotice(loanPolicy);
    requestsFixture.place(new RequestBuilder().hold().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
    IndividualResource response = loansFixture.renewLoanById(smallAngryPlanet, rebecca);
    assertThat(response.getJson().getString("action"), is("renewed"));
    assertThat(response.getJson().getString("dueDate"), is(withinSecondsAfter(15, dueDate)));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) RequestBuilder(api.support.builders.RequestBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 12 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class RequestsAPILoanRenewalTests method validationErrorWhenRenewalPeriodSpecifiedForFixedPolicy.

@Test
void validationErrorWhenRenewalPeriodSpecifiedForFixedPolicy() {
    final ZonedDateTime from = getZonedDateTime().minusMonths(3);
    final ZonedDateTime to = getZonedDateTime().plusMonths(3);
    final ZonedDateTime dueDate = to.plusDays(15);
    final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource rebecca = usersFixture.rebecca();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, rebecca);
    IndividualResource schedule = loanPoliciesFixture.createSchedule(new FixedDueDateSchedulesBuilder().withId(UUID.randomUUID()).withName("Can circulate schedule").withDescription("descr").addSchedule(new FixedDueDateSchedule(from, to, dueDate)));
    JsonObject holds = new JsonObject().put("renewItemsWithRequest", true);
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().fixed(schedule.getId()).withName("Fixed with holds").withDescription("Fixed policy with holds").renewWith(Period.weeks(2)).withHolds(holds);
    useWithActiveNotice(loanPolicy);
    requestsFixture.place(new RequestBuilder().hold().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
    Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, rebecca);
    assertThat(response.getJson(), hasErrorWith(hasMessage("Item's loan policy has fixed profile but renewal period is specified")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) RequestBuilder(api.support.builders.RequestBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 13 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class RequestsAPILoanRenewalTests method allowRenewalWithHoldsWhenProfileIsFixedUseRenewalSchedule.

@Test
void allowRenewalWithHoldsWhenProfileIsFixedUseRenewalSchedule() {
    final ZonedDateTime from = getZonedDateTime().minusMonths(3);
    final ZonedDateTime to = getZonedDateTime().plusMonths(3);
    final ZonedDateTime dueDate = to.plusDays(15);
    final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource rebecca = usersFixture.rebecca();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, rebecca);
    IndividualResource schedule = loanPoliciesFixture.createSchedule(new FixedDueDateSchedulesBuilder().withId(UUID.randomUUID()).withName("Can circulate schedule").withDescription("descr").addSchedule(new FixedDueDateSchedule(from, to, dueDate)));
    JsonObject holds = new JsonObject().put("renewItemsWithRequest", true);
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().fixed(loanPoliciesFixture.createExampleFixedDueDateSchedule().getId()).renewWith(schedule.getId()).withName("Fixed with holds").withDescription("Fixed policy with holds").withHolds(holds);
    useWithActiveNotice(loanPolicy);
    requestsFixture.place(new RequestBuilder().hold().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
    IndividualResource response = loansFixture.renewLoanById(smallAngryPlanet, rebecca);
    assertThat(response.getJson().getString("action"), is("renewed"));
    assertThat(response.getJson().getString("dueDate"), is(withinSecondsAfter(15, dueDate)));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) RequestBuilder(api.support.builders.RequestBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 14 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class RenewalAPITests method canRenewWhenSystemDateFallsWithinSecondLimitingDueDateSchedule.

@Test
void canRenewWhenSystemDateFallsWithinSecondLimitingDueDateSchedule() {
    ZonedDateTime firstScheduleStart = atStartOfDay(getZonedDateTime().minusDays(10).withZoneSameLocal(UTC));
    ZonedDateTime firstScheduleEndAndDueDate = atStartOfDay(getZonedDateTime().minusDays(3).withZoneSameLocal(UTC));
    ZonedDateTime secondScheduleStart = atStartOfDay(getZonedDateTime().minusDays(2).withZoneSameLocal(UTC));
    ZonedDateTime secondScheduleEndAndDueDate = atStartOfDay(getZonedDateTime().plusDays(5).withZoneSameLocal(UTC));
    FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder().withName("Fixed Due Date Schedule").addSchedule(new FixedDueDateSchedule(firstScheduleStart, firstScheduleEndAndDueDate, firstScheduleEndAndDueDate)).addSchedule(new FixedDueDateSchedule(secondScheduleStart, secondScheduleEndAndDueDate, secondScheduleEndAndDueDate));
    UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
    LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("System Date Rolling Policy").rolling(Period.days(56)).limitedBySchedule(fixedDueDateSchedulesId).renewWith(Period.days(7)).renewFromSystemDate();
    loanPoliciesFixture.create(currentDueDateRollingPolicy).getId();
    use(currentDueDateRollingPolicy);
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    IndividualResource jessica = usersFixture.jessica();
    IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, getZonedDateTime().minusDays(5).withZoneSameLocal(UTC));
    UUID loanId = loan.getId();
    JsonObject renewedLoan = renew(smallAngryPlanet, jessica).getJson();
    assertThat(renewedLoan.getString("id"), is(loanId.toString()));
    assertThat("due date should be as per second fixed schedule", renewedLoan.getString("dueDate"), isEquivalentTo(secondScheduleEndAndDueDate));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Aggregations

FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)14 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)14 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)14 ZonedDateTime (java.time.ZonedDateTime)14 Test (org.junit.jupiter.api.Test)14 Loan (org.folio.circulation.domain.Loan)9 IndividualResource (api.support.http.IndividualResource)5 JsonObject (io.vertx.core.json.JsonObject)5 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)5 RequestBuilder (api.support.builders.RequestBuilder)4 ItemResource (api.support.http.ItemResource)4 RequestQueue (org.folio.circulation.domain.RequestQueue)4 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)4 Response (org.folio.circulation.support.http.client.Response)2 LoanBuilder (api.support.builders.LoanBuilder)1 ZoneOffset (java.time.ZoneOffset)1 UUID (java.util.UUID)1