Skip to content

Commit

Permalink
CIRC-2117 Return empty result when search doesn't find anything (#1485)
Browse files Browse the repository at this point in the history
* CIRC-2117: return empty if no instance found
  • Loading branch information
Maksat-Galymzhan authored Jul 19, 2024
1 parent ea17564 commit 5bd43b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.circulation.infrastructure.storage;

import static org.folio.circulation.support.StringUtil.urlEncode;
import static org.folio.circulation.support.results.Result.emptyAsync;
import static org.folio.circulation.support.results.Result.failed;
import static org.folio.circulation.support.results.ResultBinding.flatMapResult;
import static org.folio.circulation.support.results.ResultBinding.mapResult;
Expand Down Expand Up @@ -62,9 +63,9 @@ private Result<MultipleRecords<SearchInstance>> mapResponseToInstances(Response

private CompletableFuture<Result<SearchInstance>> updateItemDetails(SearchInstance searchInstance) {
log.debug("updateItemDetails:: searchInstance {}", () -> searchInstance);
if (searchInstance == null) {
return CompletableFuture.completedFuture(failed(new BadRequestFailure(
"Search result is empty")));
if (searchInstance == null || searchInstance.getId() == null) {
log.info("updateItemDetails:: searchInstance is empty");
return emptyAsync();
}

Map<String, List<Item>> itemsByTenant = searchInstance.getItems()
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/api/ItemsByInstanceResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static api.support.APITestContext.setTempTenantId;
import static api.support.http.InterfaceUrls.itemsByInstanceUrl;
import static api.support.matchers.JsonObjectMatcher.hasJsonPath;
import static org.folio.HttpStatus.HTTP_OK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasItem;
Expand Down Expand Up @@ -77,6 +78,17 @@ void canGetInstanceById() {
hasJsonPath("tenantId", is(TENANT_ID_UNIVERSITY)))));
}

@Test
void canGetEmptyResult() {
UUID instanceId = UUID.randomUUID();

ResourceClient.forSearchClient().replace(instanceId, new JsonObject());
Response response = get(String.format("query=(id==%s)", instanceId), HTTP_OK.toInt());
JsonObject responseJson = response.getJson();

assertThat(responseJson.isEmpty(), is(true));
}

private Response get(String query, int expectedStatusCode) {
return restAssuredClient.get(itemsByInstanceUrl(query), expectedStatusCode,
"items-by-instance-request");
Expand Down

0 comments on commit 5bd43b6

Please sign in to comment.