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