diff --git a/server/src/http/chat.rs b/server/src/http/chat.rs index de3ff1e..137d589 100644 --- a/server/src/http/chat.rs +++ b/server/src/http/chat.rs @@ -23,3 +23,36 @@ impl ChatApi { Ok(Json(true)) } } + +#[cfg(test)] +mod tests { + use super::*; + use tempfile::TempDir; + + fn test_api(dir: &TempDir) -> ChatApi { + ChatApi { + ctx: Arc::new(AppContext::new_test(dir.path().to_path_buf())), + } + } + + #[tokio::test] + async fn cancel_chat_returns_true() { + let dir = TempDir::new().unwrap(); + let api = test_api(&dir); + let result = api.cancel_chat().await; + assert!(result.is_ok()); + assert!(result.unwrap().0); + } + + #[tokio::test] + async fn cancel_chat_sends_cancel_signal() { + let dir = TempDir::new().unwrap(); + let api = test_api(&dir); + let mut cancel_rx = api.ctx.state.cancel_rx.clone(); + cancel_rx.borrow_and_update(); + + api.cancel_chat().await.unwrap(); + + assert!(*cancel_rx.borrow()); + } +}