✨ Sync chat from SN
This commit is contained in:
37
src/test/kotlin/dev/solsynth/snConnect/WebSocketTest.kt
Normal file
37
src/test/kotlin/dev/solsynth/snConnect/WebSocketTest.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package dev.solsynth.snConnect
|
||||
|
||||
import dev.solsynth.snConnect.services.SnService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.logging.Logger
|
||||
|
||||
class WebSocketTest {
|
||||
private val logger = Logger.getLogger(WebSocketTest::class.java.name)
|
||||
|
||||
@Test
|
||||
fun testWebSocketConnection() = runBlocking {
|
||||
val service = SnService(
|
||||
baseUrl = "http://localhost:8080", // Replace with actual test server URL
|
||||
clientId = "testClientId",
|
||||
clientSecret = "testClientSecret",
|
||||
botApiKey = "testBotApiKey"
|
||||
)
|
||||
|
||||
// Collect from the flow for a limited time to avoid hanging on failure
|
||||
val packets = withTimeoutOrNull(10000L) { // 10 seconds timeout
|
||||
val collectedPackets = mutableListOf<String>()
|
||||
service.connectWebSocketAsFlow().collect { packet ->
|
||||
collectedPackets.add("Received packet: type=${packet.type}, endpoint=${packet.endpoint}")
|
||||
logger.info(collectedPackets.last())
|
||||
// In a real test, you might check packet contents or behavior
|
||||
}
|
||||
collectedPackets
|
||||
}
|
||||
|
||||
// For this test, we're mainly checking that the flow can be created and the setup doesn't crash
|
||||
// In real scenarios, you'd need a WebSocket server running at the specified URL
|
||||
logger.info("WebSocket test finished. Packets received: ${packets?.size ?: 0}")
|
||||
assert(packets != null) // Flow started without immediate error
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user