test: add unit tests to MatchMapper.kt
This commit is contained in:
parent
e53d0c0903
commit
7b8c8a5b2e
1 changed files with 131 additions and 0 deletions
|
@ -0,0 +1,131 @@
|
|||
package xyz.leomurca.csgomatches.data.mapper
|
||||
|
||||
import xyz.leomurca.csgomatches.data.model.LeagueDto
|
||||
import xyz.leomurca.csgomatches.data.model.MatchDto
|
||||
import xyz.leomurca.csgomatches.data.model.OpponentDto
|
||||
import xyz.leomurca.csgomatches.data.model.OpponentRecord
|
||||
import xyz.leomurca.csgomatches.data.model.PlayerDto
|
||||
import xyz.leomurca.csgomatches.data.model.SerieDto
|
||||
import xyz.leomurca.csgomatches.data.model.TeamDetailsDto
|
||||
import xyz.leomurca.csgomatches.domain.model.MatchStatus
|
||||
import java.time.ZonedDateTime
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class MatchMapperTest {
|
||||
|
||||
@Test
|
||||
fun `MatchDto - toDomain converts correctly with all fields`() {
|
||||
// Arrange
|
||||
val beginAt = ZonedDateTime.parse("2025-07-19T10:00:00Z")
|
||||
val dto = MatchDto(
|
||||
beginAt = beginAt,
|
||||
opponents = listOf(
|
||||
OpponentDto(
|
||||
type = "Team",
|
||||
opponent = OpponentRecord(id = 1, name = "Team A", imageUrl = "urlA")
|
||||
),
|
||||
OpponentDto(
|
||||
type = "Team",
|
||||
opponent = OpponentRecord(id = 2, name = "Team B", imageUrl = "urlB")
|
||||
)
|
||||
),
|
||||
league = LeagueDto(id = 10, name = "CS League", imageUrl = "leagueUrl"),
|
||||
serie = SerieDto(id = 20, fullName = "Serie X"),
|
||||
status = "running"
|
||||
)
|
||||
|
||||
// Act
|
||||
val domain = dto.toDomain()
|
||||
|
||||
// Assert
|
||||
assertEquals(beginAt, domain.beginAt)
|
||||
assertEquals(2, domain.opponents.size)
|
||||
assertEquals("Team A", domain.opponents[0].name)
|
||||
assertEquals("CS League", domain.league.name)
|
||||
assertEquals("Serie X", domain.serie.name)
|
||||
assertEquals(MatchStatus.LIVE, domain.matchStatus)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MatchDto - toDomain handles nulls gracefully`() {
|
||||
// Arrange
|
||||
val dto = MatchDto(
|
||||
beginAt = null,
|
||||
opponents = listOf(
|
||||
OpponentDto(type = "Team", OpponentRecord(id = 1, name = null, imageUrl = null))
|
||||
),
|
||||
league = LeagueDto(id = 11, name = null, imageUrl = null),
|
||||
serie = SerieDto(id = 22, fullName = null),
|
||||
status = null
|
||||
)
|
||||
|
||||
// Act
|
||||
val domain = dto.toDomain()
|
||||
|
||||
// Assert
|
||||
assertNull(domain.beginAt)
|
||||
assertEquals("", domain.opponents[0].name)
|
||||
assertEquals("", domain.opponents[0].imageUrl)
|
||||
assertEquals("", domain.league.name)
|
||||
assertEquals("", domain.league.imageUrl)
|
||||
assertEquals("", domain.serie.name)
|
||||
assertEquals(MatchStatus.UNKNOWN, domain.matchStatus)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TeamDetailsDto - toDomain maps all players`() {
|
||||
// Arrange
|
||||
val dto = TeamDetailsDto(
|
||||
id = 101,
|
||||
name = "My Team",
|
||||
imageUrl = "team.png",
|
||||
players = listOf(
|
||||
PlayerDto(
|
||||
id = 1,
|
||||
name = "nick",
|
||||
firstName = "John",
|
||||
lastName = "Doe",
|
||||
imageUrl = "img1.png"
|
||||
),
|
||||
PlayerDto(
|
||||
id = 2,
|
||||
name = "nick2",
|
||||
firstName = "Jane",
|
||||
lastName = "Smith",
|
||||
imageUrl = "img2.png"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
// Act
|
||||
val domain = dto.toDomain()
|
||||
|
||||
// Assert
|
||||
assertEquals(101, domain.id)
|
||||
assertEquals("My Team", domain.name)
|
||||
assertEquals(2, domain.players.size)
|
||||
assertEquals("John", domain.players[0].firstName)
|
||||
assertEquals("Smith", domain.players[1].lastName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TeamDetailsDto - toDomain with empty player list`() {
|
||||
// Arrange
|
||||
val dto = TeamDetailsDto(
|
||||
id = 200,
|
||||
name = "No Players",
|
||||
imageUrl = null,
|
||||
players = emptyList()
|
||||
)
|
||||
|
||||
// Act
|
||||
val domain = dto.toDomain()
|
||||
|
||||
// Assert
|
||||
assertEquals(0, domain.players.size)
|
||||
assertEquals("No Players", domain.name)
|
||||
assertEquals(null, domain.imageUrl)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue