simplify tests
This commit is contained in:
@@ -1,14 +1,10 @@
|
|||||||
package eventDemo
|
package eventDemo
|
||||||
|
|
||||||
import eventDemo.app.command.command.GameCommand
|
|
||||||
import eventDemo.app.entity.Card
|
import eventDemo.app.entity.Card
|
||||||
import eventDemo.app.entity.Deck
|
import eventDemo.app.entity.Deck
|
||||||
import io.ktor.websocket.Frame
|
|
||||||
import kotlinx.coroutines.channels.SendChannel
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
|
|
||||||
fun Deck.allCardCount(): Int = stack.size + discard.size + playersHands.values.flatten().size
|
fun Deck.allCardCount(): Int = stack.size + discard.size + playersHands.values.flatten().size
|
||||||
|
|
||||||
fun Deck.allCards(): Set<Card> = stack + discard + playersHands.values.flatten()
|
fun Deck.allCards(): Set<Card> = stack + discard + playersHands.values.flatten()
|
||||||
|
|
||||||
suspend fun SendChannel<Frame>.send(command: GameCommand) = send(Frame.Text(Json.encodeToString(command)))
|
// suspend fun SendChannel<Frame>.send(command: GameCommand) = send(Frame.Text(Json.encodeToString(command)))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import eventDemo.app.notification.PlayerWasReadyNotification
|
|||||||
import eventDemo.app.notification.TheGameWasStartedNotification
|
import eventDemo.app.notification.TheGameWasStartedNotification
|
||||||
import eventDemo.app.notification.WelcomeToTheGameNotification
|
import eventDemo.app.notification.WelcomeToTheGameNotification
|
||||||
import eventDemo.configuration.appKoinModule
|
import eventDemo.configuration.appKoinModule
|
||||||
import eventDemo.send
|
import eventDemo.shared.toFrame
|
||||||
import eventDemo.shared.toNotification
|
import eventDemo.shared.toNotification
|
||||||
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
|
||||||
@@ -43,8 +43,8 @@ class GameStateTest :
|
|||||||
val id = GameId()
|
val id = GameId()
|
||||||
val player1 = Player(name = "Nikola")
|
val player1 = Player(name = "Nikola")
|
||||||
val player2 = Player(name = "Einstein")
|
val player2 = Player(name = "Einstein")
|
||||||
val channelIn1 = Channel<Frame>(Channel.BUFFERED)
|
val channelIn1 = Channel<Frame>()
|
||||||
val channelIn2 = Channel<Frame>(Channel.BUFFERED)
|
val channelIn2 = Channel<Frame>()
|
||||||
val channelOut1 = Channel<Frame>(Channel.BUFFERED)
|
val channelOut1 = Channel<Frame>(Channel.BUFFERED)
|
||||||
val channelOut2 = Channel<Frame>(Channel.BUFFERED)
|
val channelOut2 = Channel<Frame>(Channel.BUFFERED)
|
||||||
|
|
||||||
@@ -63,13 +63,10 @@ class GameStateTest :
|
|||||||
commandHandler.handle(player2, channelIn2, channelOut2)
|
commandHandler.handle(player2, channelIn2, channelOut2)
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
channelIn1.send(IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(id, player1)).toFrame())
|
||||||
channelIn1.send(IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(id, player1)))
|
delay(50)
|
||||||
}
|
channelIn2.send(IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(id, player2)).toFrame())
|
||||||
launch(Dispatchers.IO) {
|
delay(50)
|
||||||
delay(200)
|
|
||||||
channelIn2.send(IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(id, player2)))
|
|
||||||
}
|
|
||||||
channelOut1.receive().toNotification().let {
|
channelOut1.receive().toNotification().let {
|
||||||
assertIs<WelcomeToTheGameNotification>(it).players shouldBeEqual setOf(player1)
|
assertIs<WelcomeToTheGameNotification>(it).players shouldBeEqual setOf(player1)
|
||||||
}
|
}
|
||||||
@@ -81,12 +78,10 @@ class GameStateTest :
|
|||||||
assertIs<PlayerAsJoinTheGameNotification>(it).player shouldBeEqual player2
|
assertIs<PlayerAsJoinTheGameNotification>(it).player shouldBeEqual player2
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
channelIn1.send(IamReadyToPlayCommand(IamReadyToPlayCommand.Payload(id, player1)).toFrame())
|
||||||
channelIn1.send(IamReadyToPlayCommand(IamReadyToPlayCommand.Payload(id, player1)))
|
delay(50)
|
||||||
}
|
channelIn2.send(IamReadyToPlayCommand(IamReadyToPlayCommand.Payload(id, player2)).toFrame())
|
||||||
launch(Dispatchers.IO) {
|
delay(50)
|
||||||
channelIn2.send(IamReadyToPlayCommand(IamReadyToPlayCommand.Payload(id, player2)))
|
|
||||||
}
|
|
||||||
|
|
||||||
channelOut1.receive().toNotification().let {
|
channelOut1.receive().toNotification().let {
|
||||||
assertIs<PlayerWasReadyNotification>(it).player shouldBeEqual player2
|
assertIs<PlayerWasReadyNotification>(it).player shouldBeEqual player2
|
||||||
@@ -104,17 +99,15 @@ class GameStateTest :
|
|||||||
assertIs<TheGameWasStartedNotification>(it).hand shouldHaveSize 7
|
assertIs<TheGameWasStartedNotification>(it).hand shouldHaveSize 7
|
||||||
}
|
}
|
||||||
|
|
||||||
launch {
|
channelIn1.send(IWantToPlayCardCommand(IWantToPlayCardCommand.Payload(id, player1, player1Hand.first())).toFrame())
|
||||||
channelIn1.send(IWantToPlayCardCommand(IWantToPlayCardCommand.Payload(id, player1, player1Hand.first())))
|
delay(50)
|
||||||
}
|
|
||||||
channelOut2.receive().toNotification().let {
|
channelOut2.receive().toNotification().let {
|
||||||
assertIs<PlayerAsPlayACardNotification>(it).player shouldBeEqual player1
|
assertIs<PlayerAsPlayACardNotification>(it).player shouldBeEqual player1
|
||||||
assertIs<PlayerAsPlayACardNotification>(it).card shouldBeEqual player1Hand.first()
|
assertIs<PlayerAsPlayACardNotification>(it).card shouldBeEqual player1Hand.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
launch {
|
channelIn2.send(IWantToPlayCardCommand(IWantToPlayCardCommand.Payload(id, player2, player2Hand.first())).toFrame())
|
||||||
channelIn2.send(IWantToPlayCardCommand(IWantToPlayCardCommand.Payload(id, player2, player2Hand.first())))
|
delay(50)
|
||||||
}
|
|
||||||
channelOut1.receive().toNotification().let {
|
channelOut1.receive().toNotification().let {
|
||||||
assertIs<PlayerAsPlayACardNotification>(it).player shouldBeEqual player2
|
assertIs<PlayerAsPlayACardNotification>(it).player shouldBeEqual player2
|
||||||
assertIs<PlayerAsPlayACardNotification>(it).card shouldBeEqual player2Hand.first()
|
assertIs<PlayerAsPlayACardNotification>(it).card shouldBeEqual player2Hand.first()
|
||||||
|
|||||||
Reference in New Issue
Block a user