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

Log exhausted search query #98

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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,12 +1,16 @@
package com.gchristov.thecodinglove.searchdata.domain

sealed class SearchError(override val message: String? = null) : Throwable(message) {
abstract val additionalInfo: String?
data class Empty(
val additionalInfo: String? = null
override val additionalInfo: String? = null
) : SearchError("No results found${additionalInfo?.let { ": $it" } ?: ""}")

object Exhausted : SearchError("Results exhausted")
data class Exhausted(
override val additionalInfo: String? = null
) : SearchError("Results exhausted${additionalInfo?.let { ": $it" } ?: ""}")

data class SessionNotFound(
val additionalInfo: String? = null
override val additionalInfo: String? = null
) : SearchError("Session not found${additionalInfo?.let { ": $it" } ?: ""}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RealSearchWithHistoryUseCase(
resultsPerPage = searchConfig.postsPerPage,
exclusions = searchHistory.getExcludedPages()
)
.mapLeft { it.toSearchError() }
.mapLeft { it.toSearchError(query) }
.flatMap { postPage ->
// Get all posts on the random page
searchRepository.search(
Expand All @@ -67,7 +67,7 @@ class RealSearchWithHistoryUseCase(
posts = searchResults,
exclusions = searchHistory.getExcludedPostIndexes(postPage)
)
.mapLeft { it.toSearchError() }
.mapLeft { it.toSearchError(query) }
.map { postIndexOnPage ->
SearchWithHistoryUseCase.Result(
query = query,
Expand All @@ -84,7 +84,7 @@ class RealSearchWithHistoryUseCase(
}
}

private fun RangeError.toSearchError() = when (this) {
private fun RangeError.toSearchError(query: String) = when (this) {
is RangeError.Empty -> SearchError.Empty(additionalInfo = "could not randomize")
is RangeError.Exhausted -> SearchError.Exhausted
is RangeError.Exhausted -> SearchError.Exhausted(additionalInfo = "query=$query")
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RealPreloadSearchResultUseCaseTest {
)

return runBlockingTest(
singleSearchWithHistoryInvocationResult = Either.Left(SearchError.Exhausted),
singleSearchWithHistoryInvocationResult = Either.Left(SearchError.Exhausted(additionalInfo = "test")),
searchSession = searchSession,
) { useCase, searchRepository, searchWithHistoryUseCase ->
val actualResult = useCase.invoke(searchSessionId = TestSearchSessionId)
Expand All @@ -93,7 +93,7 @@ class RealPreloadSearchResultUseCaseTest {
)
)
assertEquals(
expected = Either.Left(SearchError.Exhausted),
expected = Either.Left(SearchError.Exhausted(additionalInfo = "test")),
actual = actualResult,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class RealSearchUseCaseTest {
fun searchWithExhaustedResultClearsSearchSessionHistoryAndRetries(): TestResult {
val searchType = SearchUseCase.Type.WithSessionId(TestSearchSessionId)
val searchWithHistoryResults = listOf(
Either.Left(SearchError.Exhausted),
Either.Left(SearchError.Exhausted(additionalInfo = "test")),
Either.Left(SearchError.Empty(additionalInfo = "test"))
)
val searchSession = SearchSessionCreator.searchSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class RealSearchWithHistoryUseCaseTest {
query = TestSearchQuery,
searchHistory = searchHistory,
)
assertTrue { actualResult == Either.Left(SearchError.Exhausted) }
assertTrue { actualResult == Either.Left(SearchError.Exhausted(additionalInfo = "query=$TestSearchQuery")) }
}
}

Expand Down