From b802a5c2468e2709d864d42d6db8283a85baae54 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Wed, 8 Feb 2023 17:28:12 +0100 Subject: [PATCH] fix(entity): calculate the count of entities when offset is out of range (#851) --- .../kotlin/com/egm/stellio/search/service/QueryService.kt | 7 ++++--- .../com/egm/stellio/search/service/QueryServiceTests.kt | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt index e0f883edc..ecb99fe5b 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt @@ -38,14 +38,15 @@ class QueryService( queryParams, accessRightFilter ) - if (entitiesIds.isEmpty()) - return@either Pair, Int>(emptyList(), 0) - val count = temporalEntityAttributeService.getCountForEntities( queryParams, accessRightFilter ).bind() + // we can have an empty list of entities with a non-zero count (e.g., offset too high) + if (entitiesIds.isEmpty()) + return@either Pair, Int>(emptyList(), count) + val entitiesPayloads = entityPayloadService.retrieve(entitiesIds) .map { toJsonLdEntity(it, listOf(queryParams.context)) } diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt index 9050349af..b352cccda 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt @@ -97,14 +97,13 @@ class QueryServiceTests { @Test fun `it should return an empty list if no entity matched the query`() = runTest { coEvery { temporalEntityAttributeService.getForEntities(any(), any()) } returns emptyList() + coEvery { temporalEntityAttributeService.getCountForEntities(any(), any()) } returns 0.right() queryService.queryEntities(buildDefaultQueryParams()) { null } .shouldSucceedWith { assertEquals(0, it.second) assertTrue(it.first.isEmpty()) } - - coVerify { temporalEntityAttributeService.getCountForEntities(any(), any()) wasNot Called } } @Test