Updated on 2026-08-14
This commit is contained in:
parent
03c5bdd053
commit
d2d15bdbb9
4 changed files with 46 additions and 6 deletions
|
|
@ -30,7 +30,7 @@ class GetContactsUseCase(
|
|||
private fun Contact.matches(query: String): Boolean {
|
||||
val isNameContaining = name.value.contains(other = query, ignoreCase = true)
|
||||
val isAddressContaining = addresses.any { addressEntry ->
|
||||
addressEntry.address.contains(other = query, ignoreCase = true)
|
||||
addressEntry.address.contains(other = query, ignoreCase = false)
|
||||
}
|
||||
return isNameContaining || isAddressContaining
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,41 @@ class GetContactsUseCaseTest {
|
|||
assertThat(result).containsExactly(bob)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN address query matching case WHEN invoke THEN returns matching contact`() = runTest {
|
||||
// Arrange
|
||||
val carol = contact(name = "Carol", address = "0xAbCdEf")
|
||||
every { repository.getAllContacts() } returns flowOf(listOf(alice, carol))
|
||||
|
||||
// Act
|
||||
val result = useCase(query = "0xAbCdEf").first()
|
||||
|
||||
// Assert
|
||||
assertThat(result).containsExactly(carol)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN address query with different case WHEN invoke THEN returns empty`() = runTest {
|
||||
// Arrange
|
||||
val carol = contact(name = "Carol", address = "0xAbCdEf")
|
||||
every { repository.getAllContacts() } returns flowOf(listOf(alice, carol))
|
||||
|
||||
// Act
|
||||
val result = useCase(query = "0xabcdef").first()
|
||||
|
||||
// Assert
|
||||
assertThat(result).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN name query with different case WHEN invoke THEN returns matching contact`() = runTest {
|
||||
// Act
|
||||
val result = useCase(query = "ALICE").first()
|
||||
|
||||
// Assert
|
||||
assertThat(result).containsExactly(alice)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN blank query WHEN invoke THEN returns all contacts unfiltered`() = runTest {
|
||||
// Act
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue