Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIRC-2117 Return empty result when search doesn't find anything #1485

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions src/test/java/api/ItemsByInstanceResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

import api.support.APITests;
import api.support.builders.SearchInstanceBuilder;
Expand Down Expand Up @@ -77,6 +78,38 @@ void canGetInstanceById() {
hasJsonPath("tenantId", is(TENANT_ID_UNIVERSITY)))));
}

@Test
void canGetEmptyResult() {
IndividualResource instance = instancesFixture.basedUponDunkirk();
UUID instanceId = instance.getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we inline it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this?
UUID instanceId = instancesFixture.basedUponDunkirk().getId();
Since we do not call instance object, we could do like this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you use this variable only once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thanks!


// create item in tenant "college"
setTempTenantId(TENANT_ID_COLLEGE);
IndividualResource collegeLocation = locationsFixture.mainFloor();
IndividualResource collegeHoldings = holdingsFixture.defaultWithHoldings(instanceId);
IndividualResource collegeItem = itemsFixture.createItemWithHoldingsAndLocation(
collegeHoldings.getId(), collegeLocation.getId());
clearTempTenantId();

// create item in tenant "university"
setTempTenantId(TENANT_ID_UNIVERSITY);
IndividualResource universityLocation = locationsFixture.thirdFloor();
IndividualResource universityHoldings = holdingsFixture.defaultWithHoldings(instanceId);
IndividualResource universityItem = itemsFixture.createItemWithHoldingsAndLocation(
universityHoldings.getId(), universityLocation.getId());
clearTempTenantId();

// make sure neither item exists in current tenant
assertThat(itemsFixture.getById(collegeItem.getId()).getResponse().getStatusCode(), is(404));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertThat(itemsFixture.getById(collegeItem.getId()).getResponse().getStatusCode(), is(404));
assertThat(itemsFixture.getById(collegeItem.getId()).getResponse().getStatusCode(), is(HttpStatus.NOT_FOUND));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assertThat(itemsFixture.getById(universityItem.getId()).getResponse().getStatusCode(), is(404));

ResourceClient.forSearchClient().replace(instanceId, new JsonObject());
OleksandrVidinieiev marked this conversation as resolved.
Show resolved Hide resolved
Response response = get(String.format("query=(id==%s)", instanceId), 200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Response response = get(String.format("query=(id==%s)", instanceId), 200);
Response response = get(String.format("query=(id==%s)", instanceId), HttpStatus.HTTP_OK);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

JsonObject responseJson = response.getJson();

Assertions.assertTrue(responseJson.isEmpty());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using the same import for assertions as seen throughout this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing it, fix it

}

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