diff --git a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameListRouteTest.kt b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameListRouteTest.kt index f1c50f2..f3322c2 100644 --- a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameListRouteTest.kt +++ b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameListRouteTest.kt @@ -8,6 +8,7 @@ import eventDemo.business.event.event.NewPlayerEvent import eventDemo.business.event.event.PlayerReadyEvent import eventDemo.business.event.projection.gameList.GameList import eventDemo.testApplicationWithConfig +import io.kotest.assertions.nondeterministic.continually import io.kotest.assertions.nondeterministic.eventually import io.kotest.assertions.nondeterministic.eventuallyConfig import io.kotest.core.spec.style.FunSpec @@ -65,19 +66,21 @@ class GameListRouteTest : interval = 300.milliseconds }, ) { - httpClient() - .get("/games") { - withAuth(player1) - accept(ContentType.Application.Json) - }.apply { - assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) - call.body>().first().let { - it.status shouldBeEqual GameList.Status.OPENING - it.players shouldHaveSize 1 - it.players shouldContain player1 - it.winners shouldHaveSize 0 + continually(1.seconds) { + httpClient() + .get("/games") { + withAuth(player1) + accept(ContentType.Application.Json) + }.apply { + assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) + call.body>().first().let { + it.status shouldBeEqual GameList.Status.OPENING + it.players shouldHaveSize 1 + it.players shouldContain player1 + it.winners shouldHaveSize 0 + } } - } + } } } } @@ -103,20 +106,22 @@ class GameListRouteTest : } } }) { - httpClient() - .get("/games") { - withAuth(player1) - accept(ContentType.Application.Json) - }.apply { - assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) - call.body>().first().let { - it.status shouldBeEqual GameList.Status.IS_STARTED - it.players shouldHaveSize 2 - it.players shouldContain player1 - it.players shouldContain player2 - it.winners shouldHaveSize 0 + eventually(1.seconds) { + httpClient() + .get("/games") { + withAuth(player1) + accept(ContentType.Application.Json) + }.apply { + assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) + call.body>().first().let { + it.status shouldBeEqual GameList.Status.IS_STARTED + it.players shouldHaveSize 2 + it.players shouldContain player1 + it.players shouldContain player2 + it.winners shouldHaveSize 0 + } } - } + } } } }) diff --git a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameStateRouteTest.kt b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameStateRouteTest.kt index 4f76d0b..811a335 100644 --- a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameStateRouteTest.kt +++ b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameStateRouteTest.kt @@ -12,6 +12,7 @@ import eventDemo.business.event.event.disableShuffleDeck import eventDemo.business.event.projection.gameState.GameState import eventDemo.business.event.projection.gameState.GameStateRepository import eventDemo.testApplicationWithConfig +import io.kotest.assertions.nondeterministic.eventually import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.equals.shouldBeEqual @@ -26,6 +27,7 @@ import kotlinx.coroutines.runBlocking import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull +import kotlin.time.Duration.Companion.seconds class GameStateRouteTest : FunSpec({ @@ -92,23 +94,25 @@ class GameStateRouteTest : delay(100) } }) { - httpClient() - .get("/games/$gameId/state") { - withAuth(player1) - accept(ContentType.Application.Json) - }.apply { - assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) - call.body().apply { - aggregateId shouldBeEqual gameId - players shouldHaveSize 2 - isStarted shouldBeEqual true - assertIs(lastEvent) - readyPlayers shouldBeEqual setOf(player1, player2) - direction shouldBeEqual GameState.Direction.CLOCKWISE - assertNotNull(lastCardPlayer) shouldBeEqual player1 - assertNotNull(colorOnCurrentStack) shouldBeEqual Card.Color.Red + eventually(1.seconds) { + httpClient() + .get("/games/$gameId/state") { + withAuth(player1) + accept(ContentType.Application.Json) + }.apply { + assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) + call.body().apply { + aggregateId shouldBeEqual gameId + players shouldHaveSize 2 + isStarted shouldBeEqual true + assertIs(lastEvent) + readyPlayers shouldBeEqual setOf(player1, player2) + direction shouldBeEqual GameState.Direction.CLOCKWISE + assertNotNull(lastCardPlayer) shouldBeEqual player1 + assertNotNull(colorOnCurrentStack) shouldBeEqual Card.Color.Red + } } - } + } } } @@ -155,14 +159,16 @@ class GameStateRouteTest : delay(100) } }) { - httpClient() - .get("/games/$gameId/card/last") { - withAuth(player1) - accept(ContentType.Application.Json) - }.apply { - assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) - assertEquals(assertNotNull(lastPlayedCard), call.body()) - } + eventually(1.seconds) { + httpClient() + .get("/games/$gameId/card/last") { + withAuth(player1) + accept(ContentType.Application.Json) + }.apply { + assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) + assertEquals(assertNotNull(lastPlayedCard), call.body()) + } + } } } }) diff --git a/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt b/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt index 1877f0b..77b3e47 100644 --- a/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt +++ b/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt @@ -173,7 +173,7 @@ class GameStateRepositoryTest : lastEventVersion shouldBeEqual 200 players shouldHaveSize 200 } - repo.count(aggregateId) shouldBe 39 + repo.count(aggregateId) shouldBe 21 } } }