story-kit: merge 101_story_test_coverage_http_chat_rs_to_80
This commit is contained in:
@@ -23,3 +23,36 @@ impl ChatApi {
|
|||||||
Ok(Json(true))
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user