Create PlayerNotificationListenerTest
This commit is contained in:
@@ -59,10 +59,9 @@ private fun DefaultWebSocketServerSession.runWebSocket(
|
|||||||
}
|
}
|
||||||
|
|
||||||
playerNotificationListener.startListening(
|
playerNotificationListener.startListening(
|
||||||
{ outgoingFrameChannel.trySendBlocking(it) },
|
|
||||||
currentPlayer,
|
currentPlayer,
|
||||||
gameId,
|
gameId,
|
||||||
)
|
) { outgoingFrameChannel.trySendBlocking(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ class PlayerNotificationListener(
|
|||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
fun startListening(
|
fun startListening(
|
||||||
outgoingNotification: (Notification) -> Unit,
|
|
||||||
currentPlayer: Player,
|
currentPlayer: Player,
|
||||||
gameId: GameId,
|
gameId: GameId,
|
||||||
|
outgoingNotification: (Notification) -> Unit,
|
||||||
) {
|
) {
|
||||||
projectionBus.subscribe { currentState ->
|
projectionBus.subscribe { currentState ->
|
||||||
if (currentState !is GameState) return@subscribe
|
if (currentState !is GameState) return@subscribe
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ class GameSimulationTest :
|
|||||||
val eventStore by inject<GameEventStore>()
|
val eventStore by inject<GameEventStore>()
|
||||||
val playerNotificationListener by inject<PlayerNotificationListener>()
|
val playerNotificationListener by inject<PlayerNotificationListener>()
|
||||||
ReactionListener(get(), get()).init()
|
ReactionListener(get(), get()).init()
|
||||||
playerNotificationListener.startListening({ channelNotification1.trySendBlocking(it) }, player1, gameId)
|
playerNotificationListener.startListening(player1, gameId) { channelNotification1.trySendBlocking(it) }
|
||||||
playerNotificationListener.startListening({ channelNotification2.trySendBlocking(it) }, player2, gameId)
|
playerNotificationListener.startListening(player2, gameId) { channelNotification2.trySendBlocking(it) }
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
commandHandler.handle(player1, gameId, channelCommand1, channelNotification1)
|
commandHandler.handle(player1, gameId, channelCommand1, channelNotification1)
|
||||||
|
|||||||
@@ -34,10 +34,9 @@ class GameCommandHandlerTest :
|
|||||||
val channelNotification = Channel<Notification>(Channel.BUFFERED)
|
val channelNotification = Channel<Notification>(Channel.BUFFERED)
|
||||||
ReactionListener(get(), get()).init()
|
ReactionListener(get(), get()).init()
|
||||||
notificationListener.startListening(
|
notificationListener.startListening(
|
||||||
{ channelNotification.trySendBlocking(it) },
|
|
||||||
player,
|
player,
|
||||||
gameId,
|
gameId,
|
||||||
)
|
) { channelNotification.trySendBlocking(it) }
|
||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
commandHandler.handle(
|
commandHandler.handle(
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package eventDemo.business.event.projection.projectionListener
|
||||||
|
|
||||||
|
import eventDemo.adapter.infrastructureLayer.event.projection.GameProjectionBusInMemory
|
||||||
|
import eventDemo.business.entity.GameId
|
||||||
|
import eventDemo.business.entity.Player
|
||||||
|
import eventDemo.business.event.event.NewPlayerEvent
|
||||||
|
import eventDemo.business.event.projection.gameState.GameState
|
||||||
|
import eventDemo.business.notification.WelcomeToTheGameNotification
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import kotlin.test.assertIs
|
||||||
|
|
||||||
|
class PlayerNotificationListenerTest :
|
||||||
|
FunSpec({
|
||||||
|
|
||||||
|
test("startListening should react when a projection is sent to the bus") {
|
||||||
|
val player = Player("Tesla")
|
||||||
|
val gameId = GameId()
|
||||||
|
val bus = GameProjectionBusInMemory()
|
||||||
|
val state =
|
||||||
|
GameState(
|
||||||
|
aggregateId = gameId,
|
||||||
|
lastEvent = NewPlayerEvent(gameId, player, 1),
|
||||||
|
players = setOf(player),
|
||||||
|
)
|
||||||
|
val spyCall: () -> Unit = mockk(relaxed = true)
|
||||||
|
PlayerNotificationListener(bus).startListening(player, gameId) {
|
||||||
|
assertIs<WelcomeToTheGameNotification>(it)
|
||||||
|
spyCall()
|
||||||
|
}
|
||||||
|
bus.publish(state)
|
||||||
|
|
||||||
|
verify(exactly = 1) { spyCall() }
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user