use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.
the class LoanAPITests method canFilterByLoanStatus.
@Test
void canFilterByLoanStatus() {
val user = usersFixture.charlotte();
UUID userId = user.getId();
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Open").withItem(itemsFixture.basedUponSmallAngryPlanet()).withRandomPastLoanDate());
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Open").withItem(itemsFixture.basedUponNod()).withRandomPastLoanDate());
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withItem(itemsFixture.basedUponNod()).withStatus("Closed").withRandomPastLoanDate());
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponTemeraire()).withRandomPastLoanDate());
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponUprooted()).withRandomPastLoanDate());
loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponInterestingTimes()).withRandomPastLoanDate());
String queryTemplate = "userId=\"%s\" and status.name=\"%s\"";
MultipleJsonRecords openLoans = loansFixture.getLoans(queryFromTemplate(queryTemplate, userId, "Open"));
MultipleJsonRecords closedLoans = loansFixture.getLoans(queryFromTemplate(queryTemplate, userId, "Closed"));
assertThat(openLoans.size(), is(2));
assertThat(openLoans.totalRecords(), is(2));
assertThat(closedLoans.size(), is(4));
assertThat(closedLoans.totalRecords(), is(4));
openLoans.forEach(loan -> loanHasExpectedProperties(loan, user));
closedLoans.forEach(loan -> {
loanHasExpectedProperties(loan, user);
hasProperty("returnDate", loan, "loan");
});
assertThat(countOfDistinctTitles(openLoans.stream()), is(greaterThan(1)));
assertThat(countOfDistinctTitles(closedLoans.stream()), is(greaterThan(1)));
}
use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.
the class LoanAPITests method canPageLoans.
@Test
void canPageLoans() {
val user = usersFixture.steve();
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponSmallAngryPlanet(), user);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), user);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponTemeraire(), user);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponUprooted(), user);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponInterestingTimes(), user);
MultipleJsonRecords firstPage = loansFixture.getLoans(limit(3));
MultipleJsonRecords secondPage = loansFixture.getLoans(limit(3), offset(3));
assertThat(firstPage.size(), is(3));
assertThat(firstPage.totalRecords(), is(5));
assertThat(secondPage.size(), is(2));
assertThat(secondPage.totalRecords(), is(5));
firstPage.forEach(loan -> loanHasExpectedProperties(loan, user));
firstPage.forEach(loan -> loanHasExpectedProperties(loan, user));
assertThat(countOfDistinctTitles(firstPage.stream()), is(greaterThan(1)));
assertThat(countOfDistinctTitles(secondPage.stream()), is(greaterThan(1)));
}
use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.
the class LoanAPITests method queryLoans.
private void queryLoans(int limit) {
MultipleJsonRecords loans = loansFixture.getLoans(limit(limit));
assertThat("Did not have expected number of loans in page", loans.size(), is(limit));
loans.forEach(loan -> assertThat("loan does not have item", loan.containsKey("item"), is(true)));
}
use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.
the class LoanAPITests method canGetMultipleLoansForDifferentBorrowers.
@Test
void canGetMultipleLoansForDifferentBorrowers() {
UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
UUID nodId = itemsFixture.basedUponNod().getId();
UUID checkinServicePointId = servicePointsFixture.cd1().getId();
UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
val steveUser = usersFixture.steve();
val firstLoanBuilder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withUserId(usersFixture.steve().getId());
// Prepare loan
loansFixture.createLoan(firstLoanBuilder);
final IndividualResource firstLoan = loansClient.createAtSpecificLocation(firstLoanBuilder);
val jessicaUser = usersFixture.jessica();
val secondLoanBuilder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withUserId(usersFixture.jessica().getId());
// Prepare loan
loansFixture.createLoan(secondLoanBuilder);
final IndividualResource secondLoan = loansClient.createAtSpecificLocation(secondLoanBuilder);
final MultipleJsonRecords multipleLoans = loansFixture.getAllLoans();
final Set<String> uniqueUserIds = multipleLoans.stream().map(loan -> loan.getString("userId")).collect(Collectors.toSet());
assertThat("Should have different 'userId' for different loans", uniqueUserIds, containsInAnyOrder(jessicaUser.getId().toString(), steveUser.getId().toString()));
assertThat("Should have two loans", multipleLoans.size(), is(2));
loanHasExpectedProperties(firstLoan.getJson(), steveUser);
loanHasExpectedProperties(secondLoan.getJson(), jessicaUser);
}
use of api.support.MultipleJsonRecords 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