Skip to content

Commit

Permalink
fix(entity): calculate the count of entities when offset is out of ra…
Browse files Browse the repository at this point in the history
…nge (#851)
  • Loading branch information
bobeal authored Feb 8, 2023
1 parent a0a31cd commit b802a5c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ class QueryService(
queryParams,
accessRightFilter
)
if (entitiesIds.isEmpty())
return@either Pair<List<JsonLdEntity>, 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<List<JsonLdEntity>, Int>(emptyList(), count)

val entitiesPayloads =
entityPayloadService.retrieve(entitiesIds)
.map { toJsonLdEntity(it, listOf(queryParams.context)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b802a5c

Please sign in to comment.