Search in sources :

Example 6 with LoanBuilder

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

the class LoanAPIProxyTests method cannotCreateProxiedLoanWhenRelationshipHasExpired.

@Test
void cannotCreateProxiedLoanWhenRelationshipHasExpired() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource sponsor = usersFixture.jessica();
    IndividualResource proxy = usersFixture.james();
    proxyRelationshipsFixture.expiredProxyFor(sponsor, proxy);
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    LoanBuilder loan = new LoanBuilder().withId(id).open().withUserId(sponsor.getId()).withProxyUserId(proxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate);
    Response postResponse = loansFixture.attemptToCreateLoan(loan, 422);
    assertThat(postResponse.getJson(), hasErrorWith(hasMessage("proxyUserId is not valid")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 7 with LoanBuilder

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

the class LoanAPIProxyTests method cannotUpdateProxiedLoanWhenRelationshipHasExpired.

@Test
void cannotUpdateProxiedLoanWhenRelationshipHasExpired() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource sponsor = usersFixture.jessica();
    IndividualResource proxy = usersFixture.james();
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(sponsor.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
    proxyRelationshipsFixture.expiredProxyFor(sponsor, proxy);
    JsonObject updatedLoan = new LoanBuilder().withId(id).open().withUserId(sponsor.getId()).withProxyUserId(proxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).create();
    Response putResponse = loansFixture.attemptToReplaceLoan(id, updatedLoan);
    assertThat("Invalid proxy should fail loan update", putResponse.getStatusCode(), is(422));
    assertThat(putResponse.getJson(), hasErrorWith(hasMessage("proxyUserId is not valid")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 8 with LoanBuilder

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

the class LoanAPIProxyTests method cannotCreateProxiedLoanWhenRelationshipIsInactive.

@Test
void cannotCreateProxiedLoanWhenRelationshipIsInactive() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource sponsor = usersFixture.jessica();
    IndividualResource proxy = usersFixture.james();
    proxyRelationshipsFixture.inactiveProxyFor(sponsor, proxy);
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    LoanBuilder loan = new LoanBuilder().withId(id).open().withUserId(sponsor.getId()).withProxyUserId(proxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate);
    Response postResponse = loansFixture.attemptToCreateLoan(loan, 422);
    assertThat(postResponse.getJson(), hasErrorWith(hasMessage("proxyUserId is not valid")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 9 with LoanBuilder

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

the class LoanAPIProxyTests method cannotCreateProxiedLoanWhenNoRelationship.

@Test
void cannotCreateProxiedLoanWhenNoRelationship() {
    UUID id = UUID.randomUUID();
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource requestingUser = usersFixture.jessica();
    IndividualResource userAttemptingToProxy = usersFixture.james();
    LoanBuilder loan = new LoanBuilder().withId(id).open().withUserId(requestingUser.getId()).withProxyUserId(userAttemptingToProxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate);
    Response postResponse = loansFixture.attemptToCreateLoan(loan, 422);
    assertThat(postResponse.getJson(), hasErrorWith(hasMessage("proxyUserId is not valid")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 10 with LoanBuilder

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

the class LoanAPITests method cannotCreateALoanWithUnknownCheckOutServicePointId.

@Test
void cannotCreateALoanWithUnknownCheckOutServicePointId() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID userId = usersFixture.charlotte().getId();
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    final UUID unknownServicePointId = UUID.randomUUID();
    final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withId(id).withCheckoutServicePointId(unknownServicePointId).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate), UNPROCESSABLE_ENTITY);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Check Out Service Point does not exist"), hasUUIDParameter("checkoutServicePointId", unknownServicePointId))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

LoanBuilder (api.support.builders.LoanBuilder)70 Test (org.junit.jupiter.api.Test)68 ZonedDateTime (java.time.ZonedDateTime)49 UUID (java.util.UUID)43 IndividualResource (api.support.http.IndividualResource)30 JsonObject (io.vertx.core.json.JsonObject)30 Response (org.folio.circulation.support.http.client.Response)24 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)18 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Loan (org.folio.circulation.domain.Loan)13 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)12 RequestQueue (org.folio.circulation.domain.RequestQueue)11 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)8 MultipleJsonRecords (api.support.MultipleJsonRecords)7 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)7 lombok.val (lombok.val)7 UTC (java.time.ZoneOffset.UTC)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 AccountBuilder (api.support.builders.AccountBuilder)4