Skip to content

Commit

Permalink
CIRC-2148: fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kapil-epam committed Sep 19, 2024
1 parent 06a6a98 commit f60e5af
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/test/java/api/requests/RequestsAPICreationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ void canCreateARequest() {
.withHoldShelfExpiration(LocalDate.of(2017, 8, 31))
.withPickupServicePointId(pickupServicePointId)
.withTags(new RequestBuilder.Tags(asList("new", "important")))
.withPatronComments("I need this book"));
.withPatronComments("I need this book")
.withPrintDetails(new RequestBuilder.PrintDetails(49,
requester.getId().toString(), true, "2024-09-16T11:58:22" +
".295+00:00")));

JsonObject representation = request.getJson();

Expand Down
63 changes: 39 additions & 24 deletions src/test/java/api/requests/RequestsAPIRetrievalTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package api.requests;

import api.support.APITests;
import api.support.MultipleJsonRecords;
import api.support.builders.Address;
import api.support.builders.ItemBuilder;
import api.support.builders.RequestBuilder;
import api.support.http.IndividualResource;
import api.support.http.ItemResource;
import api.support.http.UserResource;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.folio.circulation.support.http.client.Response;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;

import java.net.HttpURLConnection;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.UUID;

import static api.support.builders.ItemBuilder.CHECKED_OUT;
import static api.support.fixtures.ConfigurationExample.newYorkTimezoneConfiguration;
import static api.support.http.CqlQuery.noQuery;
Expand All @@ -26,26 +45,6 @@
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.net.HttpURLConnection;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.UUID;

import org.folio.circulation.support.http.client.Response;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;

import api.support.APITests;
import api.support.MultipleJsonRecords;
import api.support.TlrFeatureStatus;
import api.support.builders.Address;
import api.support.builders.ItemBuilder;
import api.support.builders.RequestBuilder;
import api.support.http.IndividualResource;
import api.support.http.ItemResource;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

class RequestsAPIRetrievalTests extends APITests {
private static final String NEW_TAG = "new";
private static final String IMPORTANT_TAG = "important";
Expand Down Expand Up @@ -873,7 +872,8 @@ private void assertThatRequestsHavePatronComments(MultipleJsonRecords requests)

@Test
void printDetailsTest() {
UUID printDetailsRequester = usersFixture.charlotte().getId();
UserResource printDetailsRequester = usersFixture.charlotte();
UUID printDetailsRequesterId = printDetailsRequester.getId();
final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();

final IndividualResource workAddressType = addressTypesFixture.work();
Expand All @@ -894,16 +894,31 @@ void printDetailsTest() {
.forItem(smallAngryPlanet)
.deliverToAddress(workAddressType.getId())
.by(charlotte)
.withPrintDetails(new RequestBuilder.PrintDetails(49, printDetailsRequester.toString(), true, "2024-09-16T11:58:22" +
.withPrintDetails(new RequestBuilder.PrintDetails(49, printDetailsRequesterId.toString(), true, "2024-09-16T11:58:22" +
".295+00:00")));


final MultipleJsonRecords requests = requestsFixture.getRequests(
queryFromTemplate("requestType==%s", "Page"),
queryFromTemplate("printDetails.isPrinted==%s", "true"),
noLimit(), noOffset());

assertThat(requests.size(), is(1));
assertThat(requests.totalRecords(), is(1));

requests.forEach(this::requestHasExpectedProperties);
JsonObject printDetails = requests.getFirst().getJsonObject("printDetails");
assertThat(printDetails.getInteger("printCount"), is(49));
assertThat(printDetails.getString("requesterId"),
is(printDetailsRequesterId.toString()));
assertTrue(printDetails.getBoolean("isPrinted"));

JsonObject lastPrintRequester = printDetails.getJsonObject(
"lastPrintRequester");
JsonObject expectedLastPrintRequester = printDetailsRequester.getJson()
.getJsonObject("personal");

assertThat(lastPrintRequester.getString("firstName"),
is(expectedLastPrintRequester.getString("firstName")));
assertThat(lastPrintRequester.getString("lastName"),
is(expectedLastPrintRequester.getString("lastName")));
}
}
5 changes: 2 additions & 3 deletions src/test/java/api/support/builders/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class RequestBuilder extends JsonBuilder implements Builder {

public RequestBuilder() {
this(UUID.randomUUID(),
"Holdkapil",
"Hold",
"Item",
ZonedDateTime.of(2017, 7, 15, 9, 35, 27, 0, UTC),
UUID.randomUUID(),
Expand All @@ -91,8 +91,7 @@ public RequestBuilder() {
null,
null,
null,
new PrintDetails(49, UUID.randomUUID().toString(), true, "2024-09-16T11:58:22" +
".295+00:00"));
null);
}

public static RequestBuilder from(IndividualResource response) {
Expand Down

0 comments on commit f60e5af

Please sign in to comment.