create CommandStream and first Command
This commit is contained in:
@@ -4,6 +4,7 @@ import eventDemo.app.Card
|
||||
import eventDemo.app.EventStream
|
||||
import eventDemo.app.GameId
|
||||
import eventDemo.app.PlayCardEvent
|
||||
import eventDemo.app.read
|
||||
import eventDemo.module
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.ktor.client.call.body
|
||||
@@ -11,11 +12,13 @@ import io.ktor.client.request.accept
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.ContentType.Application.Json
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.server.testing.testApplication
|
||||
import org.koin.core.context.stopKoin
|
||||
import org.koin.java.KoinJavaComponent.getKoin
|
||||
import org.koin.ktor.ext.inject
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -27,13 +30,17 @@ class CardTest : FunSpec({
|
||||
stopKoin()
|
||||
module()
|
||||
}
|
||||
val id = GameId().toString()
|
||||
val id = GameId()
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
client.post("/game/$id/card") {
|
||||
contentType(Json)
|
||||
accept(Json)
|
||||
setBody(Card.Simple(1, Card.Color.Blue))
|
||||
setBody(card)
|
||||
}.apply {
|
||||
assertEquals(status, HttpStatusCode.OK)
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
|
||||
val eventStream = getKoin().get<EventStream<GameId>>()
|
||||
assertEquals(PlayCardEvent(id, card), eventStream.read<PlayCardEvent, GameId>(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +49,7 @@ class CardTest : FunSpec({
|
||||
testApplication {
|
||||
val client = httpClient()
|
||||
val id = GameId()
|
||||
val card = Card.Simple(1, Card.Color.Blue)
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
@@ -54,7 +61,7 @@ class CardTest : FunSpec({
|
||||
}
|
||||
|
||||
client.get("/game/$id/card/last").apply {
|
||||
assertEquals(HttpStatusCode.OK, status)
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
assertEquals(card, this.call.body<Card>())
|
||||
}
|
||||
}
|
||||
|
||||
68
src/test/kotlin/eventDemo/app/actions/CommandTest.kt
Normal file
68
src/test/kotlin/eventDemo/app/actions/CommandTest.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package eventDemo.app.actions
|
||||
|
||||
import eventDemo.app.Card
|
||||
import eventDemo.app.Command
|
||||
import eventDemo.app.CommandStream
|
||||
import eventDemo.app.Game
|
||||
import eventDemo.app.PlayCardCommand
|
||||
import eventDemo.module
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.accept
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.ContentType.Application.Json
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.server.testing.testApplication
|
||||
import org.koin.core.context.stopKoin
|
||||
import org.koin.java.KoinJavaComponent.getKoin
|
||||
import org.koin.ktor.ext.inject
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class CommandTest : FunSpec({
|
||||
test("/command/send") {
|
||||
testApplication {
|
||||
val client = httpClient()
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
}
|
||||
val command = PlayCardCommand(Game.new(), Card.Simple(1, Card.Color.Blue))
|
||||
client.post("/command/send") {
|
||||
contentType(Json)
|
||||
accept(Json)
|
||||
setBody(command)
|
||||
}.apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
|
||||
val commandStream = getKoin().get<CommandStream>()
|
||||
assertEquals(command, commandStream.readNext())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("/command/next") {
|
||||
testApplication {
|
||||
val command =
|
||||
PlayCardCommand(
|
||||
Game.new(),
|
||||
Card.Simple(1, Card.Color.Blue),
|
||||
)
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
|
||||
val commandStream by inject<CommandStream>()
|
||||
commandStream.sendRequest(command)
|
||||
}
|
||||
|
||||
httpClient().get("/command/next").apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
assertEquals(command, this.call.body<Command>())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user