Skip to content

Commit

Permalink
Fix location cloud data source test
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Surzhykov <yuriisurzhykov@gmail.com>
  • Loading branch information
yuriisurzhykov committed May 28, 2024
1 parent 08f2b19 commit 1fd0ef3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.yuriisurzhykov.purs.core.RequestResult
import com.github.yuriisurzhykov.purs.data.cloud.model.LocationCloud
import io.mockk.coEvery
import io.mockk.mockk
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.runTest
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.ResponseBody.Companion.toResponseBody
Expand All @@ -22,8 +22,8 @@ class LocationCloudDataSourceTest {
coEvery { locationService.fetchLocation() } returns Response.success(mockLocationCloud)
val dataSource = LocationCloudDataSource.Base(locationService)

val actual = dataSource.fetchLocation().first()
val expected = RequestResult.Success(mockLocationCloud)
val actual = dataSource.fetchLocation().toList()
val expected = listOf(RequestResult.InProgress(), RequestResult.Success(mockLocationCloud))

assertEquals(expected, actual)
}
Expand All @@ -34,8 +34,8 @@ class LocationCloudDataSourceTest {
coEvery { locationService.fetchLocation() } returns Response.success(null)
val dataSource = LocationCloudDataSource.Base(locationService)

val actual = dataSource.fetchLocation().first()
val expected = RequestResult.Error(null, null)
val actual = dataSource.fetchLocation().toList()
val expected = listOf(RequestResult.InProgress(), RequestResult.Error(null, null))

assertEquals(expected, actual)
}
Expand All @@ -49,8 +49,11 @@ class LocationCloudDataSourceTest {
)
val dataSource = LocationCloudDataSource.Base(locationService)

val actual = dataSource.fetchLocation().first()
val expected = RequestResult.Error(null, ServerError(404, "Page not found"))
val actual = dataSource.fetchLocation().toList()
val expected = listOf(
RequestResult.InProgress(),
RequestResult.Error(null, ServerError(404, "Page not found"))
)

assertEquals(expected, actual)
}
Expand All @@ -62,8 +65,9 @@ class LocationCloudDataSourceTest {
coEvery { locationService.fetchLocation() } throws exceptionToThrow
val dataSource = LocationCloudDataSource.Base(locationService)

val actual = dataSource.fetchLocation().first()
val expected = RequestResult.Error(null, exceptionToThrow)
val actual = dataSource.fetchLocation().toList()
val expected =
listOf(RequestResult.InProgress(), RequestResult.Error(null, exceptionToThrow))

assertEquals(expected, actual)
}
Expand Down

0 comments on commit 1fd0ef3

Please sign in to comment.