From 2f5a841a03a7f6473fd04b84e6b282c7e1258db4 Mon Sep 17 00:00:00 2001 From: M57 <41645758+Hy4ri@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:19:01 +0300 Subject: [PATCH] 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. --- .../ui/chat/ChatViewModelTest.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt b/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt index 52578442..200e9fa6 100644 --- a/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt +++ b/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt @@ -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