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));
}
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")));
}
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")));
}
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()));
}
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")));
}
Aggregations