Trendyol / stove

Stove: The easiest way of writing e2e/component tests for your JVM back-end API with Kotlin
https://trendyol.github.io/stove/
Apache License 2.0
174 stars 13 forks source link

New feature: Support for WebSocket as protocol #660

Open osoykan opened 2 days ago

osoykan commented 2 days ago

We have http protocol to interact with. But users also in the need of having a WebSocket protocol to test their systems.

http system leverages ktor client to make requests against the Application Under Test (AUT). With a little search I have discovered that WebSocket plugin for Ktor client can be easily installed.

https://ktor.io/docs/server-create-websocket-application.html#add-automated-tests

val client = createClient {
 install(ContentNegotiation) {
    json()
 }

 install(WebSockets) {
    contentConverter = KotlinxWebsocketSerializationConverter(Json)
 }
}

After enabling WebSockets, we can create an API on HttpSystem to interact with AUTs websocket endpoints.

One example could be (on Stove's http dsl)

http {
 webSocket("/chat") { actual -> 
   // we need to think more about the `actual` reference here,
   // what could possibly be the best object to interact and assert with 🤔 
   }
}