fix tauri test

This commit is contained in:
Dinh Long Nguyen 2025-09-30 22:43:14 +07:00
parent d50226b4dd
commit 9a72a2d5d5
3 changed files with 13 additions and 2 deletions

View File

@ -38,6 +38,7 @@ async fn test_run_mcp_commands() {
std::fs::remove_file(&config_path).expect("Failed to remove config file");
}
#[test]
fn test_add_server_config_new_file() {
let app = mock_app();
let app_path = get_jan_data_folder_path(app.handle().clone());
@ -151,7 +152,14 @@ fn test_add_server_config_existing_servers() {
fn test_add_server_config_missing_config_file() {
let app = mock_app();
let app_path = get_jan_data_folder_path(app.handle().clone());
let config_path = app_path.join("nonexistent_config.json");
// Ensure the directory exists
if let Some(parent) = app_path.parent() {
std::fs::create_dir_all(parent).ok();
}
std::fs::create_dir_all(&app_path).ok();
let config_path = app_path.join("mcp_config.json");
// Ensure the file doesn't exist
if config_path.exists() {

View File

@ -148,6 +148,9 @@ pub async fn create_message<R: Runtime>(
let data = serde_json::to_string(&message).map_err(|e| e.to_string())?;
writeln!(file, "{}", data).map_err(|e| e.to_string())?;
// Explicitly flush to ensure data is written before returning
file.flush().map_err(|e| e.to_string())?;
}
Ok(message)

View File

@ -82,7 +82,7 @@ async fn test_create_and_list_messages() {
let messages = list_messages(app.handle().clone(), thread_id.clone())
.await
.unwrap();
assert!(messages.len() > 0);
assert!(messages.len() > 0, "Expected at least one message, but got none. Thread ID: {}", thread_id);
assert_eq!(messages[0]["role"], "user");
// Clean up