Search in sources :

Example 1 with LoanBuilder

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

the class LoanAPIProxyTests method canUpdateProxiedLoanWhenValidProxyRelationship.

@Test
void canUpdateProxiedLoanWhenValidProxyRelationship() {
    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.currentProxyFor(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("Valid proxy should allow updates to work but does not", putResponse.getStatusCode(), is(HTTP_NO_CONTENT));
}
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 2 with LoanBuilder

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

the class LoanAPIProxyTests method cannotUpdateProxiedLoanWhenNoRelationship.

@Test
void cannotUpdateProxiedLoanWhenNoRelationship() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource requestingUser = usersFixture.jessica();
    IndividualResource userAttemptingToProxy = 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(requestingUser.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
    JsonObject updatedLoan = new LoanBuilder().withId(id).open().withUserId(requestingUser.getId()).withProxyUserId(userAttemptingToProxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).create();
    Response putResponse = loansFixture.attemptToReplaceLoan(id, updatedLoan);
    assertThat("Invalid proxyUserId is not allowed when updating a loan", 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 3 with LoanBuilder

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

the class LoanAPIProxyTests method cannotCreateProxiedLoanWhenRelationshipIsForOtherSponsor.

@Test
void cannotCreateProxiedLoanWhenRelationshipIsForOtherSponsor() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource unexpectedSponsor = usersFixture.jessica();
    IndividualResource otherUser = usersFixture.charlotte();
    IndividualResource proxy = usersFixture.james();
    proxyRelationshipsFixture.currentProxyFor(unexpectedSponsor, 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(otherUser.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 4 with LoanBuilder

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

the class LoanAPIProxyTests method canCreateProxiedLoanWhenNonExpiringRelationship.

@Test
void canCreateProxiedLoanWhenNonExpiringRelationship() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource sponsor = usersFixture.jessica();
    IndividualResource proxy = usersFixture.james();
    proxyRelationshipsFixture.nonExpiringProxyFor(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);
    IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(sponsor.getId()).withProxyUserId(proxy.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
    JsonObject loan = response.getJson();
    assertThat("user id does not match", loan.getString("userId"), is(sponsor.getId().toString()));
    assertThat("proxy user id does not match", loan.getString("proxyUserId"), is(proxy.getId().toString()));
}
Also used : 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 5 with LoanBuilder

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

the class LoanAPIProxyTests method cannotUpdateProxiedLoanWhenRelationshipIsForOtherSponsor.

@Test
void cannotUpdateProxiedLoanWhenRelationshipIsForOtherSponsor() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource unexpectedSponsor = usersFixture.jessica();
    IndividualResource otherUser = usersFixture.charlotte();
    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(otherUser.getId()).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
    proxyRelationshipsFixture.currentProxyFor(unexpectedSponsor, proxy);
    JsonObject updatedLoan = new LoanBuilder().withId(id).open().withUserId(otherUser.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)

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