test: fix test for redis

This commit is contained in:
2025-04-12 23:23:23 +02:00
parent d394fca3f9
commit 4086a21dcb
3 changed files with 61 additions and 50 deletions

View File

@@ -8,6 +8,7 @@ import eventDemo.business.event.event.NewPlayerEvent
import eventDemo.business.event.event.PlayerReadyEvent import eventDemo.business.event.event.PlayerReadyEvent
import eventDemo.business.event.projection.gameList.GameList import eventDemo.business.event.projection.gameList.GameList
import eventDemo.testApplicationWithConfig import eventDemo.testApplicationWithConfig
import io.kotest.assertions.nondeterministic.continually
import io.kotest.assertions.nondeterministic.eventually import io.kotest.assertions.nondeterministic.eventually
import io.kotest.assertions.nondeterministic.eventuallyConfig import io.kotest.assertions.nondeterministic.eventuallyConfig
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
@@ -65,19 +66,21 @@ class GameListRouteTest :
interval = 300.milliseconds interval = 300.milliseconds
}, },
) { ) {
httpClient() continually(1.seconds) {
.get("/games") { httpClient()
withAuth(player1) .get("/games") {
accept(ContentType.Application.Json) withAuth(player1)
}.apply { accept(ContentType.Application.Json)
assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) }.apply {
call.body<List<GameList>>().first().let { assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
it.status shouldBeEqual GameList.Status.OPENING call.body<List<GameList>>().first().let {
it.players shouldHaveSize 1 it.status shouldBeEqual GameList.Status.OPENING
it.players shouldContain player1 it.players shouldHaveSize 1
it.winners shouldHaveSize 0 it.players shouldContain player1
it.winners shouldHaveSize 0
}
} }
} }
} }
} }
} }
@@ -103,20 +106,22 @@ class GameListRouteTest :
} }
} }
}) { }) {
httpClient() eventually(1.seconds) {
.get("/games") { httpClient()
withAuth(player1) .get("/games") {
accept(ContentType.Application.Json) withAuth(player1)
}.apply { accept(ContentType.Application.Json)
assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) }.apply {
call.body<List<GameList>>().first().let { assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
it.status shouldBeEqual GameList.Status.IS_STARTED call.body<List<GameList>>().first().let {
it.players shouldHaveSize 2 it.status shouldBeEqual GameList.Status.IS_STARTED
it.players shouldContain player1 it.players shouldHaveSize 2
it.players shouldContain player2 it.players shouldContain player1
it.winners shouldHaveSize 0 it.players shouldContain player2
it.winners shouldHaveSize 0
}
} }
} }
} }
} }
}) })

View File

@@ -12,6 +12,7 @@ import eventDemo.business.event.event.disableShuffleDeck
import eventDemo.business.event.projection.gameState.GameState import eventDemo.business.event.projection.gameState.GameState
import eventDemo.business.event.projection.gameState.GameStateRepository import eventDemo.business.event.projection.gameState.GameStateRepository
import eventDemo.testApplicationWithConfig import eventDemo.testApplicationWithConfig
import io.kotest.assertions.nondeterministic.eventually
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.equals.shouldBeEqual import io.kotest.matchers.equals.shouldBeEqual
@@ -26,6 +27,7 @@ import kotlinx.coroutines.runBlocking
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertIs import kotlin.test.assertIs
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
import kotlin.time.Duration.Companion.seconds
class GameStateRouteTest : class GameStateRouteTest :
FunSpec({ FunSpec({
@@ -92,23 +94,25 @@ class GameStateRouteTest :
delay(100) delay(100)
} }
}) { }) {
httpClient() eventually(1.seconds) {
.get("/games/$gameId/state") { httpClient()
withAuth(player1) .get("/games/$gameId/state") {
accept(ContentType.Application.Json) withAuth(player1)
}.apply { accept(ContentType.Application.Json)
assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) }.apply {
call.body<GameState>().apply { assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
aggregateId shouldBeEqual gameId call.body<GameState>().apply {
players shouldHaveSize 2 aggregateId shouldBeEqual gameId
isStarted shouldBeEqual true players shouldHaveSize 2
assertIs<CardIsPlayedEvent>(lastEvent) isStarted shouldBeEqual true
readyPlayers shouldBeEqual setOf(player1, player2) assertIs<CardIsPlayedEvent>(lastEvent)
direction shouldBeEqual GameState.Direction.CLOCKWISE readyPlayers shouldBeEqual setOf(player1, player2)
assertNotNull(lastCardPlayer) shouldBeEqual player1 direction shouldBeEqual GameState.Direction.CLOCKWISE
assertNotNull(colorOnCurrentStack) shouldBeEqual Card.Color.Red assertNotNull(lastCardPlayer) shouldBeEqual player1
assertNotNull(colorOnCurrentStack) shouldBeEqual Card.Color.Red
}
} }
} }
} }
} }
@@ -155,14 +159,16 @@ class GameStateRouteTest :
delay(100) delay(100)
} }
}) { }) {
httpClient() eventually(1.seconds) {
.get("/games/$gameId/card/last") { httpClient()
withAuth(player1) .get("/games/$gameId/card/last") {
accept(ContentType.Application.Json) withAuth(player1)
}.apply { accept(ContentType.Application.Json)
assertEquals(HttpStatusCode.OK, status, message = bodyAsText()) }.apply {
assertEquals(assertNotNull(lastPlayedCard), call.body<Card>()) assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
} assertEquals(assertNotNull(lastPlayedCard), call.body<Card>())
}
}
} }
} }
}) })

View File

@@ -173,7 +173,7 @@ class GameStateRepositoryTest :
lastEventVersion shouldBeEqual 200 lastEventVersion shouldBeEqual 200
players shouldHaveSize 200 players shouldHaveSize 200
} }
repo.count(aggregateId) shouldBe 39 repo.count(aggregateId) shouldBe 21
} }
} }
} }