test: add tests for interruptSession in ChatViewModel (#508)
Add unit tests to `ChatViewModelTest.kt` to cover the `interruptSession` method. The tests verify that `interruptSession` correctly sends the `SESSION_INTERRUPT` RPC via the WebSocket client when a session ID is present, and that it safely does nothing when the session ID is missing. This improves test coverage for the chat control logic.
This commit is contained in:
1 file changed
+23
@@ -711,6 +711,29 @@ class ChatViewModelTest {
|
||||
verify { HermesWsClient.send(WsMethods.SESSION_RESUME, mapOf("session_id" to "session-456"), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInterruptSession_withSessionId_sendsRpc() =
|
||||
runTest {
|
||||
val (viewModel, sessionId) = createViewModelWithSession()
|
||||
|
||||
viewModel.interruptSession()
|
||||
advanceUntilIdle()
|
||||
|
||||
verify { HermesWsClient.send(WsMethods.SESSION_INTERRUPT, mapOf("session_id" to sessionId), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInterruptSession_withoutSessionId_doesNotSendRpc() =
|
||||
runTest {
|
||||
val viewModel = createViewModel()
|
||||
advanceUntilIdle()
|
||||
|
||||
viewModel.interruptSession()
|
||||
advanceUntilIdle()
|
||||
|
||||
verify(exactly = 0) { HermesWsClient.send(WsMethods.SESSION_INTERRUPT, any(), any()) }
|
||||
}
|
||||
|
||||
// ── Error handling ───────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user