- Add support for user-defined custom categories in config.toml - Update Config struct with categories field and default_categories() function - Thread categories through GeminiClient and prompt builder - Update AI prompts to use dynamic categories instead of hardcoded ones - Add comprehensive documentation with examples for different use cases - Update tests to support new categories field - Maintain backward compatibility with default categories - Update version from 1.0.3 to 1.0.4 Closes feature request for custom categories.
94 lines
2.6 KiB
Rust
94 lines
2.6 KiB
Rust
use crate::settings::config::default_categories;
|
|
use crate::settings::*;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
#[test]
|
|
fn test_config_serialization() {
|
|
let config = Config {
|
|
api_key: "test_key_12345".to_string(),
|
|
download_folder: PathBuf::from("/test/path"),
|
|
categories: default_categories(),
|
|
};
|
|
|
|
let toml_str = toml::to_string_pretty(&config).unwrap();
|
|
assert!(toml_str.contains("test_key_12345"));
|
|
|
|
let deserialized: Config = toml::from_str(&toml_str).unwrap();
|
|
assert_eq!(config.api_key, deserialized.api_key);
|
|
assert_eq!(config.download_folder, deserialized.download_folder);
|
|
assert_eq!(config.categories, deserialized.categories);
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_api_key_valid() {
|
|
assert!(Prompter::validate_api_key(
|
|
"AIzaSyB1234567890123456789012345678"
|
|
));
|
|
assert!(Prompter::validate_api_key(
|
|
"AIzaSyB123456789012345678901234567890"
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_api_key_invalid() {
|
|
assert!(!Prompter::validate_api_key(""));
|
|
assert!(!Prompter::validate_api_key("invalid_key"));
|
|
assert!(!Prompter::validate_api_key(
|
|
"BizaSyB1234567890123456789012345678"
|
|
));
|
|
assert!(!Prompter::validate_api_key("short"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_folder_path_valid() {
|
|
let temp_dir = tempfile::tempdir().unwrap();
|
|
assert!(Prompter::validate_folder_path(temp_dir.path()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_folder_path_invalid() {
|
|
assert!(!Prompter::validate_folder_path(Path::new(
|
|
"/nonexistent/path/that/does/not/exist"
|
|
)));
|
|
|
|
let temp_file = tempfile::NamedTempFile::new().unwrap();
|
|
assert!(!Prompter::validate_folder_path(temp_file.path()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_expand_home_with_tilde() {
|
|
if let Some(base_dirs) = directories::BaseDirs::new() {
|
|
let home = base_dirs.home_dir();
|
|
let expanded = Prompter::expand_home("~/test/path");
|
|
assert!(expanded.starts_with(home.to_string_lossy().as_ref()));
|
|
assert!(expanded.contains("test/path"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_expand_home_without_tilde() {
|
|
let expanded = Prompter::expand_home("/absolute/path");
|
|
assert_eq!(expanded, "/absolute/path");
|
|
|
|
let expanded = Prompter::expand_home("relative/path");
|
|
assert_eq!(expanded, "relative/path");
|
|
}
|
|
|
|
#[test]
|
|
fn test_get_default_downloads_folder() {
|
|
let path = Prompter::get_default_downloads_folder();
|
|
assert!(path.ends_with("Downloads"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_config_empty_api_key_error() {
|
|
let config = Config {
|
|
api_key: String::new(),
|
|
download_folder: PathBuf::from("/test/path"),
|
|
categories: default_categories(),
|
|
};
|
|
|
|
assert!(config.api_key.is_empty());
|
|
}
|