use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method canCreateClosedLoanInSpecificLocationWithoutUserId.
@Test
void canCreateClosedLoanInSpecificLocationWithoutUserId() {
UUID loanId = UUID.randomUUID();
UUID checkinServicePointId = servicePointsFixture.cd1().getId();
UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
LoanBuilder loanBuilder = new LoanBuilder().withId(loanId).withItemId(itemId).withCheckinServicePointId(checkinServicePointId).closed().withNoUserId();
UUID userId = usersFixture.charlotte().getId();
loansFixture.createLoan(loanBuilder.withUserId(userId));
loansFixture.createLoanAtSpecificLocation(loanId, loanBuilder);
final IndividualResource item = itemsClient.get(itemId);
assertThat("Item status should be available", item.getJson().getJsonObject("status").getString("name"), is("Available"));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method canCreateALoanWithoutStatus.
@Test
void canCreateALoanWithoutStatus() {
UUID id = UUID.randomUUID();
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(builder -> builder.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
UUID itemId = smallAngryPlanet.getId();
UUID userId = usersFixture.charlotte().getId();
IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).withUserId(userId).withItemId(itemId).withNoStatus());
JsonObject loan = response.getJson();
assertThat("status is not open", loan.getJsonObject("status").getString("name"), is("Open"));
assertThat("action is not checkedout", loan.getString("action"), is("checkedout"));
loanHasLoanPolicyProperties(response.getJson(), loanPoliciesFixture.canCirculateRolling());
assertThat("title is taken from item", loan.getJsonObject("item").containsKey("title"), is(true));
assertThat("barcode is taken from item", loan.getJsonObject("item").containsKey("barcode"), is(true));
assertThat("has item status", loan.getJsonObject("item").containsKey("status"), is(true));
assertThat("status is taken from item", loan.getJsonObject("item").getJsonObject("status").getString("name"), is("Checked out"));
assertThat("has item enumeration", loan.getJsonObject("item").getString("enumeration"), is("v.70:no.1-6"));
assertThat("has item chronology", loan.getJsonObject("item").getString("chronology"), is("1987:Jan.-June"));
assertThat("has item volume", loan.getJsonObject("item").getString("volume"), is("testVolume"));
JsonObject item = itemsClient.getById(itemId).getJson();
assertThat("item status is not checked out", item.getJsonObject("status").getString("name"), is("Checked out"));
assertThat("has item enumeration", item.getString("enumeration"), is("v.70:no.1-6"));
assertThat("has item chronology", item.getString("chronology"), is("1987:Jan.-June"));
assertThat("has item volume", item.getString("volume"), is("testVolume"));
assertThat("item status snapshot in storage is not checked out", loansStorageClient.getById(id).getJson().getString("itemStatus"), is("Checked out"));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method canCreateALoanAtASpecificLocation.
@Test
void canCreateALoanAtASpecificLocation() {
UUID id = UUID.randomUUID();
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(builder -> builder.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
UUID itemId = smallAngryPlanet.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);
val loanBuilder = new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate);
// Prepare loan
loansFixture.createLoan(loanBuilder.withUserId(userId));
IndividualResource response = loansClient.createAtSpecificLocation(loanBuilder);
JsonObject loan = response.getJson();
assertThat("id does not match", loan.getString("id"), is(id.toString()));
assertThat("user id does not match", loan.getString("userId"), is(userId.toString()));
assertThat("item id does not match", loan.getString("itemId"), is(itemId.toString()));
assertThat("loan date does not match", loan.getString("loanDate"), is("2017-02-27T10:23:43.000Z"));
assertThat("status is not open", loan.getJsonObject("status").getString("name"), is("Open"));
assertThat("action is not checkedout", loan.getString("action"), is("checkedout"));
// TODO: Loan Policy should be stored - maybe only works for renewal, possible bug?
// assertThat("last loan policy should be stored",
// loan.getString("loanPolicyId"), is(APITestSuite.canCirculateRollingLoanPolicyId().toString()));
assertThat("title is taken from instance", loan.getJsonObject("item").getString("title"), is("The Long Way to a Small, Angry Planet"));
assertThat("barcode is taken from item", loan.getJsonObject("item").getString("barcode"), is("036000291452"));
assertThat("call number is 123456", loan.getJsonObject("item").getString("callNumber"), is("123456"));
assertThat(loan.getJsonObject("item").encode() + " contains 'materialType'", loan.getJsonObject("item").containsKey("materialType"), is(true));
assertThat("materialType is book", loan.getJsonObject("item").getJsonObject("materialType").getString("name"), is("Book"));
assertThat("item has contributors", loan.getJsonObject("item").containsKey("contributors"), is(true));
JsonArray contributors = loan.getJsonObject("item").getJsonArray("contributors");
assertThat("item has a single contributor", contributors.size(), is(1));
assertThat("Becky Chambers is a contributor", contributors.getJsonObject(0).getString("name"), is("Chambers, Becky"));
assertThat("has item status", loan.getJsonObject("item").containsKey("status"), is(true));
assertThat("status is taken from item", loan.getJsonObject("item").getJsonObject("status").getString("name"), is("Checked out"));
assertThat("has item enumeration", loan.getJsonObject("item").getString("enumeration"), is("v.70:no.1-6"));
assertThat("has item chronology", loan.getJsonObject("item").getString("chronology"), is("1987:Jan.-June"));
assertThat("has item volume", loan.getJsonObject("item").getString("volume"), is("testVolume"));
assertThat("Should not have snapshot of item status, as current status is included", loan.containsKey("itemStatus"), is(false));
assertThat("should have change metadata", loan.containsKey("metadata"), is(true));
JsonObject changeMetadata = loan.getJsonObject("metadata");
assertThat("change metadata should have created date", changeMetadata.containsKey("createdDate"), is(true));
assertThat("change metadata should have updated date", changeMetadata.containsKey("updatedDate"), is(true));
assertThat("due date does not match", loan.getString("dueDate"), isEquivalentTo(dueDate));
JsonObject item = itemsClient.getById(itemId).getJson();
assertThat("item status is not checked out", item.getJsonObject("status").getString("name"), is("Checked out"));
assertThat("item status snapshot in storage is not checked out", loansStorageClient.getById(id).getJson().getString("itemStatus"), is("Checked out"));
assertThat("has item enumeration", item.getString("enumeration"), is("v.70:no.1-6"));
assertThat("has item chronology", item.getString("chronology"), is("1987:Jan.-June"));
assertThat("has item volume", item.getString("volume"), is("testVolume"));
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method canGetLoanWithoutOpenFeesFines.
@Test
void canGetLoanWithoutOpenFeesFines() {
UUID id = UUID.randomUUID();
UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
IndividualResource user = usersFixture.charlotte();
UUID userId = user.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);
IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
accountsClient.create(new AccountBuilder().feeFineStatusOpen().withLoan(response).feeFineStatusClosed().withRemainingFeeFine(150));
JsonObject loan = loansFixture.getLoanById(id).getJson();
assertLoanHasFeeFinesProperties(loan, 0);
}
use of api.support.builders.LoanBuilder in project mod-circulation by folio-org.
the class LoanAPITests method dueDateChangedEventIsPublishedOnCreate.
@Test
void dueDateChangedEventIsPublishedOnCreate() {
UUID id = UUID.randomUUID();
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(item -> item.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
UUID itemId = smallAngryPlanet.getId();
IndividualResource user = usersFixture.charlotte();
UUID userId = user.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);
IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
JsonObject loan = response.getJson();
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
final var event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
assertThat(event, isValidLoanDueDateChangedEvent(loan));
}
Aggregations