fix: fix broken tests
This commit is contained in:
parent
bf63494b93
commit
5730041183
3 changed files with 12 additions and 12 deletions
|
@ -1,6 +1,5 @@
|
|||
package xyz.leomurca.csgomatches.data.remote
|
||||
|
||||
import androidx.compose.foundation.pager.PageSize
|
||||
import kotlinx.serialization.json.Json
|
||||
import xyz.leomurca.csgomatches.data.model.ErrorDto
|
||||
import xyz.leomurca.csgomatches.data.model.MatchDto
|
||||
|
|
|
@ -25,6 +25,7 @@ import xyz.leomurca.csgomatches.data.model.MatchDto
|
|||
import xyz.leomurca.csgomatches.data.model.SerieDto
|
||||
import xyz.leomurca.csgomatches.data.model.TeamDetailsDto
|
||||
import xyz.leomurca.csgomatches.domain.model.Resource
|
||||
import xyz.leomurca.csgomatches.utils.ApiDefaults.ITEMS_PER_PAGE
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
|
@ -55,14 +56,14 @@ class MatchRemoteDataSourceImplTest {
|
|||
runTest {
|
||||
// Arrange
|
||||
val matches = listOf(MATCH_DTO)
|
||||
coEvery { api.upcomingMatches() } returns Response.success(matches)
|
||||
coEvery { api.upcomingMatches(page = 1) } returns Response.success(matches)
|
||||
|
||||
// Act
|
||||
val result = dataSource.upcomingMatches()
|
||||
val result = dataSource.upcomingMatches(page = 1)
|
||||
|
||||
// Assert
|
||||
coVerify(exactly = 1) {
|
||||
api.upcomingMatches("running, not_started", false, "begin_at")
|
||||
api.upcomingMatches("running, not_started", false, "begin_at", ITEMS_PER_PAGE, 1)
|
||||
}
|
||||
assertTrue(result is Resource.Success)
|
||||
assertEquals(matches, (result as Resource.Success).data)
|
||||
|
@ -73,13 +74,13 @@ class MatchRemoteDataSourceImplTest {
|
|||
// Arrange
|
||||
val errorDto = ErrorDto(message = "API failure")
|
||||
|
||||
coEvery { api.upcomingMatches() } returns mockk(relaxed = true) {
|
||||
coEvery { api.upcomingMatches(page = 1) } returns mockk(relaxed = true) {
|
||||
every { isSuccessful } returns false
|
||||
}
|
||||
every { json.decodeFromString<ErrorDto>(any()) } returns errorDto
|
||||
|
||||
// Act
|
||||
val result = dataSource.upcomingMatches()
|
||||
val result = dataSource.upcomingMatches(page = 1)
|
||||
|
||||
// Assert
|
||||
assertTrue(result is Resource.Error)
|
||||
|
@ -90,10 +91,10 @@ class MatchRemoteDataSourceImplTest {
|
|||
@Test
|
||||
fun `upcomingMatches - response is an RuntimeException - returns Resource Error`() = runTest {
|
||||
// Arrange
|
||||
coEvery { api.upcomingMatches() } throws RuntimeException("Network error")
|
||||
coEvery { api.upcomingMatches(page = 1) } throws RuntimeException("Network error")
|
||||
|
||||
// Act
|
||||
val result = dataSource.upcomingMatches()
|
||||
val result = dataSource.upcomingMatches(page = 1)
|
||||
|
||||
// Assert
|
||||
assertTrue(result is Resource.Error)
|
||||
|
|
|
@ -60,10 +60,10 @@ class MatchRepositoryImplTest {
|
|||
serie = SerieDto(1, "Serie 1"),
|
||||
status = "running"
|
||||
)
|
||||
coEvery { remoteDataSource.upcomingMatches() } returns Resource.Success(listOf(dto))
|
||||
coEvery { remoteDataSource.upcomingMatches(page = 1) } returns Resource.Success(listOf(dto))
|
||||
|
||||
// Act
|
||||
val result = repository.upcomingMatches()
|
||||
val result = repository.upcomingMatches(page = 1)
|
||||
|
||||
// Assert
|
||||
assertTrue(result is Resource.Success)
|
||||
|
@ -75,10 +75,10 @@ class MatchRepositoryImplTest {
|
|||
@Test
|
||||
fun `upcomingMatches - Resource Error from data source - returns Error`() = runTest {
|
||||
// Arrange
|
||||
coEvery { remoteDataSource.upcomingMatches() } returns Resource.Error("Network issue")
|
||||
coEvery { remoteDataSource.upcomingMatches(page = 1) } returns Resource.Error("Network issue")
|
||||
|
||||
// Act
|
||||
val result = repository.upcomingMatches()
|
||||
val result = repository.upcomingMatches(page = 1)
|
||||
|
||||
// Assert
|
||||
assertTrue(result is Resource.Error)
|
||||
|
|
Loading…
Add table
Reference in a new issue