update ktlint
This commit is contained in:
@@ -22,48 +22,48 @@ import org.koin.java.KoinJavaComponent.getKoin
|
||||
import org.koin.ktor.ext.inject
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class CardTest : FunSpec({
|
||||
test("/game/{id}/card") {
|
||||
testApplication {
|
||||
val client = httpClient()
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
}
|
||||
val id = GameId()
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
client.post("/game/$id/card") {
|
||||
contentType(Json)
|
||||
accept(Json)
|
||||
setBody(card)
|
||||
}.apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
class CardTest :
|
||||
FunSpec({
|
||||
test("/game/{id}/card") {
|
||||
testApplication {
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
}
|
||||
val id = GameId()
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
httpClient()
|
||||
.post("/game/$id/card") {
|
||||
contentType(Json)
|
||||
accept(Json)
|
||||
setBody(card)
|
||||
}.apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
|
||||
val eventStream = getKoin().get<EventStream<GameId>>()
|
||||
assertEquals(PlayCardEvent(id, card), eventStream.read<PlayCardEvent, GameId>(id))
|
||||
val eventStream = getKoin().get<EventStream<GameId>>()
|
||||
assertEquals(PlayCardEvent(id, card), eventStream.read<PlayCardEvent, GameId>(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("/game/{id}/card/last") {
|
||||
testApplication {
|
||||
val client = httpClient()
|
||||
val id = GameId()
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
val eventStream by inject<EventStream<GameId>>()
|
||||
eventStream.publish(
|
||||
PlayCardEvent(GameId(), Card.Simple(2, Card.Color.Yellow)),
|
||||
PlayCardEvent(id, card),
|
||||
)
|
||||
}
|
||||
test("/game/{id}/card/last") {
|
||||
testApplication {
|
||||
val id = GameId()
|
||||
val card: Card = Card.Simple(1, Card.Color.Blue)
|
||||
application {
|
||||
stopKoin()
|
||||
module()
|
||||
val eventStream by inject<EventStream<GameId>>()
|
||||
eventStream.publish(
|
||||
PlayCardEvent(GameId(), Card.Simple(2, Card.Color.Yellow)),
|
||||
PlayCardEvent(id, card),
|
||||
)
|
||||
}
|
||||
|
||||
client.get("/game/$id/card/last").apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
assertEquals(card, this.call.body<Card>())
|
||||
httpClient().get("/game/$id/card/last").apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
assertEquals(card, this.call.body<Card>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -22,47 +22,49 @@ 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())
|
||||
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())
|
||||
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()
|
||||
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)
|
||||
}
|
||||
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>())
|
||||
httpClient().get("/command/next").apply {
|
||||
assertEquals(HttpStatusCode.OK, status, message = bodyAsText())
|
||||
assertEquals(command, this.call.body<Command>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,8 +9,8 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
import java.util.UUID
|
||||
|
||||
fun ApplicationTestBuilder.httpClient(): HttpClient {
|
||||
return createClient {
|
||||
fun ApplicationTestBuilder.httpClient(): HttpClient =
|
||||
createClient {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
Json {
|
||||
@@ -22,4 +22,3 @@ fun ApplicationTestBuilder.httpClient(): HttpClient {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user