diff --git a/src/test/kotlin/BaseIntegrationTest.kt b/src/test/kotlin/BaseIntegrationTest.kt index da696fa9d29b6ff712bd2414c81f7b967bbfb12c..c6eb51fd500a1e4d637189a5cca3c2df2b442b75 100644 --- a/src/test/kotlin/BaseIntegrationTest.kt +++ b/src/test/kotlin/BaseIntegrationTest.kt @@ -7,6 +7,7 @@ abstract class BaseIntegrationTest : KoinTest { environment { config = ApplicationConfig("application-test.yaml") } + startApplication() test() } } \ No newline at end of file diff --git a/src/test/kotlin/player/PlayerIntegrationTest.kt b/src/test/kotlin/player/PlayerIntegrationTest.kt index 4585d90dcd6c21d888d65a63beae19da32e374b0..896b785ee05c099e19d02735a671db5aadd00077 100644 --- a/src/test/kotlin/player/PlayerIntegrationTest.kt +++ b/src/test/kotlin/player/PlayerIntegrationTest.kt @@ -1,8 +1,10 @@ package player import BaseIntegrationTest +import betclic.test.player.Player import betclic.test.player.PlayerRepository import betclic.test.player.dtos.PlayerCreationDTO +import betclic.test.player.dtos.PlayerUpdateDTO import io.ktor.client.request.* import io.ktor.http.* import kotlinx.serialization.encodeToString @@ -13,14 +15,15 @@ import org.koin.test.inject import kotlin.test.assertEquals -private const val PLAYER_NAME = "Clement" +private const val NAME_1 = "Clement" +private const val NAME_2 = "Maxime" class PlayerIntegrationTest : BaseIntegrationTest() { @Test fun `When calling player creation, a player should be saved in DB`() = iTest { val response = client.post("/players") { - val player = PlayerCreationDTO(pseudo = PLAYER_NAME) + val player = PlayerCreationDTO(pseudo = NAME_1) val json = Json.encodeToString(player) header(HttpHeaders.ContentType, ContentType.Application.Json) setBody(json) @@ -28,10 +31,23 @@ class PlayerIntegrationTest : BaseIntegrationTest() { assertEquals(HttpStatusCode.Created, response.status) - val playerRepository: PlayerRepository by inject() - val players = playerRepository.findAll() - assertThat(players).hasSize(1) - assertThat(players.first()).extracting("pseudo", "pointsNumber") - .containsExactly(PLAYER_NAME, 0) + val playerRepository by inject<PlayerRepository>() + val player = playerRepository.findPlayerByPseudo(NAME_1) + assertThat(player).extracting("pseudo", "pointsNumber") + .containsExactly(NAME_1, 0) + } + + @Test + fun `When calling player update, a player should be updated in DB`() = iTest { + val playerRepository by inject<PlayerRepository>() + playerRepository.createNewPlayer(Player(pseudo = NAME_2, pointsNumber = 0)) + val response = client.put("/players") { + header(HttpHeaders.ContentType, ContentType.Application.Json) + setBody(Json.encodeToString(PlayerUpdateDTO(pseudo = NAME_2, pointsNumber = 30))) + } + assertEquals(HttpStatusCode.OK, response.status) + val player = playerRepository.findPlayerByPseudo(NAME_2) + assertThat(player).extracting("pseudo", "pointsNumber") + .containsExactly(NAME_2, 30) } }