Image uri test cases

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-07-25 17:54:19 +02:00 committed by Marcel Hibbe
parent d656a93e8a
commit a51e3b98ad
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 23 additions and 5 deletions

View File

@ -58,6 +58,8 @@ class ContactsViewModelTest {
runTest { runTest {
viewModel = ContactsViewModel(FakeRepositoryError()) viewModel = ContactsViewModel(FakeRepositoryError())
assert(viewModel.contactsViewState.value is ContactsUiState.Error) assert(viewModel.contactsViewState.value is ContactsUiState.Error)
val errorState = viewModel.contactsViewState.value as ContactsUiState.Error
assert(errorState.message == "unable to fetch contacts")
} }
@Test @Test
@ -104,5 +106,21 @@ class ContactsViewModelTest {
viewModel = ContactsViewModel(FakeRepositoryError()) viewModel = ContactsViewModel(FakeRepositoryError())
viewModel.createRoom("1", "users", "s@gmail.com", null) viewModel.createRoom("1", "users", "s@gmail.com", null)
assert(viewModel.roomViewState.value is RoomUiState.Error) assert(viewModel.roomViewState.value is RoomUiState.Error)
val errorState = viewModel.roomViewState.value as RoomUiState.Error
assert(errorState.message == "unable to create room")
}
@Test
fun `test image uri`() {
val expectedImageUri = "https://mydomain.com/index.php/avatar/vidya/512"
val imageUri = viewModel.getImageUri("vidya", false)
assert(imageUri == expectedImageUri)
}
@Test
fun `test error image uri`() {
val expectedImageUri = "https://mydoman.com/index.php/avatar/vidya/512"
val imageUri = viewModel.getImageUri("vidya", false)
assert(imageUri != expectedImageUri)
} }
} }

View File

@ -13,7 +13,7 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
class FakeRepositoryError() : ContactsRepository { class FakeRepositoryError() : ContactsRepository {
override suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall { override suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall {
throw Exception("unknown error occurred") throw Exception("unable to fetch contacts")
} }
override suspend fun createRoom( override suspend fun createRoom(
@ -22,10 +22,10 @@ class FakeRepositoryError() : ContactsRepository {
userId: String, userId: String,
conversationName: String? conversationName: String?
): RoomOverall { ): RoomOverall {
throw Exception("unknown error occurred") throw Exception("unable to create room")
} }
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String { override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
throw Exception("unknown error occurred") return "https://mydoman.com/index.php/avatar/$avatarId/512"
} }
} }