Search in sources :

Example 1 with DeclareItemLostRequestBuilder

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

the class DeclareLostAPITests method declaredLostEventIsPublished.

@Test
void declaredLostEventIsPublished() {
    UUID servicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource loanIndividualResource = checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
    final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(loanIndividualResource.getId()).on(getZonedDateTime()).withServicePointId(servicePointId).withNoComment();
    declareLostFixtures.declareItemLost(builder);
    // There should be five events published - "check out", "log event", "declared lost"
    // and one "log record"
    final var publishedEvents = Awaitility.await().atMost(1, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
    final var event = publishedEvents.findFirst(byEventType(EventTypeMatchers.ITEM_DECLARED_LOST));
    final var loan = loanIndividualResource.getJson();
    assertThat(event, isValidItemDeclaredLostEvent(loan));
    verifyNumberOfPublishedEvents(LOAN_CLOSED, 0);
    assertThatPublishedLoanLogRecordEventsAreValid(loansClient.getById(UUID.fromString(loan.getString("id"))).getJson());
}
Also used : FakePubSub(api.support.fakes.FakePubSub) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DeclareItemLostRequestBuilder

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

the class DeclareLostAPITests method shouldNotCreateNoteWhenNotPreviouslyClaimedReturned.

@Test
void shouldNotCreateNoteWhenNotPreviouslyClaimedReturned() {
    String comment = "testing";
    UUID servicePointId = servicePointsFixture.cd1().getId();
    ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
    UUID loanId = checkOutFixture.checkOutByBarcode(item, usersFixture.charlotte()).getId();
    ZonedDateTime dateTime = getZonedDateTime();
    final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(loanId).on(dateTime).withServicePointId(servicePointId).withComment(comment);
    declareLostFixtures.declareItemLost(builder);
    assertEquals(0, notesClient.getAll().size());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with DeclareItemLostRequestBuilder

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

the class DeclareLostAPITests method declareItemLostFailsWhenEventPublishingFailsWithBadRequestError.

@Test
void declareItemLostFailsWhenEventPublishingFailsWithBadRequestError() {
    UUID servicePointId = servicePointsFixture.cd1().getId();
    final IndividualResource checkOut = checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
    final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(checkOut.getId()).on(getZonedDateTime()).withComment("testing").withServicePointId(servicePointId);
    FakePubSub.setFailPublishingWithBadRequestError(true);
    Response response = declareLostFixtures.attemptDeclareItemLost(500, builder);
    assertThat(response.getBody(), containsString("Error during publishing Event Message in PubSub. Status code: 400"));
}
Also used : Response(org.folio.circulation.support.http.client.Response) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DeclareItemLostRequestBuilder

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

the class DeclareLostAPITests method shouldReturn404IfLoanIsNotFound.

@Test
void shouldReturn404IfLoanIsNotFound() {
    UUID servicePointId = servicePointsFixture.cd1().getId();
    final UUID loanId = UUID.randomUUID();
    final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(loanId).withServicePointId(servicePointId).on(getZonedDateTime()).withNoComment();
    Response response = declareLostFixtures.attemptDeclareItemLost(builder);
    assertThat(response.getStatusCode(), is(404));
}
Also used : Response(org.folio.circulation.support.http.client.Response) UUID(java.util.UUID) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DeclareItemLostRequestBuilder

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

the class DeclareLostAPITests method cannotDeclareItemLostWhenNoAutomatedLostItemFeeTypeIsDefined.

@Test
void cannotDeclareItemLostWhenNoAutomatedLostItemFeeTypeIsDefined() {
    UUID servicePointId = servicePointsFixture.cd1().getId();
    feeFineTypeFixture.delete(feeFineTypeFixture.lostItemFee());
    final ItemResource item = itemsFixture.basedUponNod();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(item, usersFixture.charlotte());
    final Response response = declareLostFixtures.attemptDeclareItemLost(new DeclareItemLostRequestBuilder().withServicePointId(servicePointId).forLoanId(loan.getId()));
    assertThat(loansFixture.getLoanById(loan.getId()).getJson(), isOpen());
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Expected automated fee of type Lost item fee"), hasParameter("feeFineType", "Lost item fee"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DeclareItemLostRequestBuilder (api.support.builders.DeclareItemLostRequestBuilder)22 UUID (java.util.UUID)19 Test (org.junit.jupiter.api.Test)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 IndividualResource (api.support.http.IndividualResource)14 ItemResource (api.support.http.ItemResource)11 Response (org.folio.circulation.support.http.client.Response)10 ZonedDateTime (java.time.ZonedDateTime)9 JsonObject (io.vertx.core.json.JsonObject)8 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)8 LostItemFeePolicyBuilder (api.support.builders.LostItemFeePolicyBuilder)3 AgeToLostResult (api.support.fixtures.AgeToLostFixture.AgeToLostResult)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ClaimItemReturnedRequestBuilder (api.support.builders.ClaimItemReturnedRequestBuilder)1 FakePubSub (api.support.fakes.FakePubSub)1 OkapiHeaders (api.support.http.OkapiHeaders)1 UserResource (api.support.http.UserResource)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1