Fix a bug where no tags would return an empty tag while searching
This commit is contained in:
parent
381d935875
commit
2c967ebd8c
@ -22,5 +22,5 @@ internal object UuidFieldConverter : FieldConverter<UUID> {
|
||||
|
||||
internal object TagsFieldConverter : FieldConverter<List<String>> {
|
||||
override fun toDoc(value: List<String>): String = value.joinToString(" ")
|
||||
override fun fromDoc(value: String): List<String> = value.split(" ")
|
||||
override fun fromDoc(value: String): List<String> = value.split(" ").filter(String::isNotEmpty)
|
||||
}
|
||||
|
||||
26
search/src/test/kotlin/TagsFieldConverterTest.kt
Normal file
26
search/src/test/kotlin/TagsFieldConverterTest.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package be.simplenotes.search
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
import java.util.stream.Stream
|
||||
|
||||
internal class TagsFieldConverterTest {
|
||||
|
||||
@Suppress("unused")
|
||||
fun tags(): Stream<List<String>> = Stream.of(
|
||||
listOf("example"),
|
||||
listOf("example", "second"),
|
||||
listOf(),
|
||||
)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("tags")
|
||||
fun `tags should stay the same`(input: List<String>) {
|
||||
val doc = TagsFieldConverter.toDoc(input)
|
||||
val out = TagsFieldConverter.fromDoc(doc)
|
||||
assertThat(out)
|
||||
.hasSameSizeAs(input)
|
||||
.containsExactlyInAnyOrderElementsOf(input)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user