use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method barcodeIsNotIncludedWhenItemDoesNotHaveOne.
@Test
void barcodeIsNotIncludedWhenItemDoesNotHaveOne() {
UUID id = UUID.randomUUID();
UUID itemId = itemsFixture.basedUponSmallAngryPlanet(ItemBuilder::withNoBarcode).getId();
UUID userId = usersFixture.charlotte().getId();
loansFixture.createLoan(new LoanBuilder().withId(id).withUserId(userId).withItemId(itemId).withLoanDate(ZonedDateTime.of(2016, 10, 15, 8, 26, 53, 0, UTC)).withStatus("Open"));
Response getResponse = loansClient.getById(id);
assertThat(format("Failed to get loan: %s", getResponse.getBody()), getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject loan = getResponse.getJson();
assertThat("barcode is not taken from item", loan.getJsonObject("item").containsKey("barcode"), is(false));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method cannotCreateOpenLoanForUnknownRequestingUser.
@Test
void cannotCreateOpenLoanForUnknownRequestingUser() {
UUID loanId = UUID.randomUUID();
final UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
final UUID unknownUserId = 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);
final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withId(loanId).withUserId(unknownUserId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).open(), UNPROCESSABLE_ENTITY);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("user is not found"), hasUUIDParameter("userId", unknownUserId))));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method cannotCreateLoanThatIsNotOpenOrClosed.
@Test
void cannotCreateLoanThatIsNotOpenOrClosed() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource jessica = usersFixture.jessica();
final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withStatus("Unknown Status").withItemId(smallAngryPlanet.getId()).withUserId(jessica.getId()), UNPROCESSABLE_ENTITY);
assertThat(response.getJson(), hasErrorWith(hasMessage("Loan status must be \"Open\" or \"Closed\"")));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method cannotCreateALoanForUnknownItem.
@Test
void cannotCreateALoanForUnknownItem() {
UUID id = UUID.randomUUID();
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 unknownItemId = UUID.randomUUID();
final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().open().withId(id).withUserId(userId).withItemId(unknownItemId).withLoanDate(loanDate).withDueDate(dueDate), UNPROCESSABLE_ENTITY);
assertThat(response.getJson(), hasErrorWith(allOf(hasMessage(format("No item with ID %s could be found", unknownItemId)), hasUUIDParameter("itemId", unknownItemId))));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method multipleClosedLoansHaveNoBorrowerInformation.
@Test
void multipleClosedLoansHaveNoBorrowerInformation() {
UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
UUID nodId = itemsFixture.basedUponNod().getId();
UUID checkinServicePointId = servicePointsFixture.cd1().getId();
UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
final IndividualResource user = usersFixture.jessica();
LoanBuilder loan1Builder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withUserId(user.getId());
// Prepare loan
loansFixture.createLoan(loan1Builder);
final IndividualResource loan1 = loansClient.createAtSpecificLocation(loan1Builder);
LoanBuilder loan2Builder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withUserId(user.getId());
// Prepare loan
loansFixture.createLoan(loan2Builder);
final IndividualResource loan2 = loansClient.createAtSpecificLocation(loan2Builder);
JsonObject updatedLoanRequest = loan1.copyJson();
updatedLoanRequest.getJsonObject("status").put("name", "Closed");
updatedLoanRequest.remove("userId");
loansClient.replace(loan1.getId(), updatedLoanRequest);
updatedLoanRequest = loan2.copyJson();
updatedLoanRequest.getJsonObject("status").put("name", "Closed");
updatedLoanRequest.remove("userId");
loansClient.replace(loan2.getId(), updatedLoanRequest);
MultipleJsonRecords loans = loansFixture.getAllLoans();
loans.forEach(this::hasNoBorrowerProperties);
}
Aggregations