Update unit tests for basic keywords

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-12-24 09:29:28 -03:00
parent 3d0a9a843d
commit 56334dd7b1
8 changed files with 1010 additions and 1195 deletions

View file

@ -1,15 +1,10 @@
use botserver::basic::keywords::agent_reflection::{
extract_insights_from_text, ReflectionConfig, ReflectionResult, ReflectionType,
};
use uuid::Uuid;
#[test]
fn test_reflection_type_from_str() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_reflection_type_from_str() {
assert_eq!( assert_eq!(
ReflectionType::from("conversation_quality"), ReflectionType::from("conversation_quality"),
ReflectionType::ConversationQuality ReflectionType::ConversationQuality
@ -26,22 +21,18 @@
ReflectionType::from("performance"), ReflectionType::from("performance"),
ReflectionType::Performance ReflectionType::Performance
); );
} }
#[test] #[test]
fn test_reflection_config_default() {
fn test_reflection_config_default() {
let config = ReflectionConfig::default(); let config = ReflectionConfig::default();
assert!(!config.enabled); assert!(!config.enabled);
assert_eq!(config.interval, 10); assert_eq!(config.interval, 10);
assert!(!config.auto_apply); assert!(!config.auto_apply);
} }
#[test] #[test]
fn test_reflection_result_new() {
fn test_reflection_result_new() {
let bot_id = Uuid::new_v4(); let bot_id = Uuid::new_v4();
let session_id = Uuid::new_v4(); let session_id = Uuid::new_v4();
let result = ReflectionResult::new(bot_id, session_id, ReflectionType::ConversationQuality); let result = ReflectionResult::new(bot_id, session_id, ReflectionType::ConversationQuality);
@ -50,12 +41,10 @@
assert_eq!(result.session_id, session_id); assert_eq!(result.session_id, session_id);
assert_eq!(result.score, 0.0); assert_eq!(result.score, 0.0);
assert!(result.insights.is_empty()); assert!(result.insights.is_empty());
} }
#[test] #[test]
fn test_reflection_result_from_json() {
fn test_reflection_result_from_json() {
let json_response = r#"{ let json_response = r#"{
"score": 7.5, "score": 7.5,
"key_insights": ["Users prefer concise responses", "Technical questions need more detail"], "key_insights": ["Users prefer concise responses", "Technical questions need more detail"],
@ -75,12 +64,10 @@
assert_eq!(result.insights.len(), 2); assert_eq!(result.insights.len(), 2);
assert_eq!(result.improvements.len(), 2); assert_eq!(result.improvements.len(), 2);
assert_eq!(result.positive_patterns.len(), 2); assert_eq!(result.positive_patterns.len(), 2);
} }
#[test] #[test]
fn test_reflection_result_needs_improvement() {
fn test_reflection_result_needs_improvement() {
let mut result = let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance); ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);
@ -89,12 +76,10 @@
result.score = 8.0; result.score = 8.0;
assert!(!result.needs_improvement(6.0)); assert!(!result.needs_improvement(6.0));
} }
#[test] #[test]
fn test_extract_insights_from_text() {
fn test_extract_insights_from_text() {
let text = "Here are some insights:\n\ let text = "Here are some insights:\n\
1. Users prefer short responses\n\ 1. Users prefer short responses\n\
2. Technical questions need examples\n\ 2. Technical questions need examples\n\
@ -103,21 +88,17 @@
let insights = extract_insights_from_text(text); let insights = extract_insights_from_text(text);
assert!(!insights.is_empty()); assert!(!insights.is_empty());
} }
#[test] #[test]
fn test_reflection_type_prompt_template() {
fn test_reflection_type_prompt_template() {
let template = ReflectionType::ConversationQuality.prompt_template(); let template = ReflectionType::ConversationQuality.prompt_template();
assert!(template.contains("{conversation}")); assert!(template.contains("{conversation}"));
assert!(template.contains("JSON format")); assert!(template.contains("JSON format"));
} }
#[test] #[test]
fn test_reflection_result_summary() {
fn test_reflection_result_summary() {
let mut result = let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance); ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);
result.score = 7.5; result.score = 7.5;
@ -130,4 +111,4 @@
assert!(summary.contains("15")); assert!(summary.contains("15"));
assert!(summary.contains("2")); assert!(summary.contains("2"));
assert!(summary.contains("1")); assert!(summary.contains("1"));
} }

View file

@ -1,53 +1,40 @@
use botserver::basic::keywords::code_sandbox::{
generate_node_lxc_config, generate_python_lxc_config, CodeLanguage, ExecutionResult,
SandboxConfig, SandboxRuntime,
};
#[test]
fn test_sandbox_config_default() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_sandbox_config_default() {
let config = SandboxConfig::default(); let config = SandboxConfig::default();
assert!(config.enabled); assert!(config.enabled);
assert_eq!(config.timeout_seconds, 30); assert_eq!(config.timeout_seconds, 30);
assert_eq!(config.memory_limit_mb, 256); assert_eq!(config.memory_limit_mb, 256);
assert!(!config.network_enabled); assert!(!config.network_enabled);
} }
#[test] #[test]
fn test_execution_result_success() {
fn test_execution_result_success() {
let result = ExecutionResult::success("Hello, World!".to_string(), String::new(), 100); let result = ExecutionResult::success("Hello, World!".to_string(), String::new(), 100);
assert!(result.is_success()); assert!(result.is_success());
assert_eq!(result.output(), "Hello, World!"); assert_eq!(result.output(), "Hello, World!");
} }
#[test] #[test]
fn test_execution_result_error() {
fn test_execution_result_error() {
let result = ExecutionResult::error("Something went wrong"); let result = ExecutionResult::error("Something went wrong");
assert!(!result.is_success()); assert!(!result.is_success());
assert!(result.output().contains("Error")); assert!(result.output().contains("Error"));
} }
#[test] #[test]
fn test_execution_result_timeout() {
fn test_execution_result_timeout() {
let result = ExecutionResult::timeout(); let result = ExecutionResult::timeout();
assert!(!result.is_success()); assert!(!result.is_success());
assert!(result.timed_out); assert!(result.timed_out);
} }
#[test] #[test]
fn test_code_language_from_str() {
fn test_code_language_from_str() {
assert_eq!(CodeLanguage::from("python"), CodeLanguage::Python); assert_eq!(CodeLanguage::from("python"), CodeLanguage::Python);
assert_eq!(CodeLanguage::from("PYTHON"), CodeLanguage::Python); assert_eq!(CodeLanguage::from("PYTHON"), CodeLanguage::Python);
assert_eq!(CodeLanguage::from("py"), CodeLanguage::Python); assert_eq!(CodeLanguage::from("py"), CodeLanguage::Python);
@ -55,30 +42,24 @@
assert_eq!(CodeLanguage::from("js"), CodeLanguage::JavaScript); assert_eq!(CodeLanguage::from("js"), CodeLanguage::JavaScript);
assert_eq!(CodeLanguage::from("node"), CodeLanguage::JavaScript); assert_eq!(CodeLanguage::from("node"), CodeLanguage::JavaScript);
assert_eq!(CodeLanguage::from("bash"), CodeLanguage::Bash); assert_eq!(CodeLanguage::from("bash"), CodeLanguage::Bash);
} }
#[test] #[test]
fn test_code_language_file_extension() {
fn test_code_language_file_extension() {
assert_eq!(CodeLanguage::Python.file_extension(), "py"); assert_eq!(CodeLanguage::Python.file_extension(), "py");
assert_eq!(CodeLanguage::JavaScript.file_extension(), "js"); assert_eq!(CodeLanguage::JavaScript.file_extension(), "js");
assert_eq!(CodeLanguage::Bash.file_extension(), "sh"); assert_eq!(CodeLanguage::Bash.file_extension(), "sh");
} }
#[test] #[test]
fn test_code_language_interpreter() {
fn test_code_language_interpreter() {
assert_eq!(CodeLanguage::Python.interpreter(), "python3"); assert_eq!(CodeLanguage::Python.interpreter(), "python3");
assert_eq!(CodeLanguage::JavaScript.interpreter(), "node"); assert_eq!(CodeLanguage::JavaScript.interpreter(), "node");
assert_eq!(CodeLanguage::Bash.interpreter(), "bash"); assert_eq!(CodeLanguage::Bash.interpreter(), "bash");
} }
#[test] #[test]
fn test_sandbox_runtime_from_str() {
fn test_sandbox_runtime_from_str() {
assert_eq!(SandboxRuntime::from("lxc"), SandboxRuntime::LXC); assert_eq!(SandboxRuntime::from("lxc"), SandboxRuntime::LXC);
assert_eq!(SandboxRuntime::from("docker"), SandboxRuntime::Docker); assert_eq!(SandboxRuntime::from("docker"), SandboxRuntime::Docker);
assert_eq!( assert_eq!(
@ -86,12 +67,10 @@
SandboxRuntime::Firecracker SandboxRuntime::Firecracker
); );
assert_eq!(SandboxRuntime::from("unknown"), SandboxRuntime::Process); assert_eq!(SandboxRuntime::from("unknown"), SandboxRuntime::Process);
} }
#[test] #[test]
fn test_lxc_config_generation() {
fn test_lxc_config_generation() {
let python_config = generate_python_lxc_config(); let python_config = generate_python_lxc_config();
assert!(python_config.contains("gb-sandbox-python")); assert!(python_config.contains("gb-sandbox-python"));
assert!(python_config.contains("memory.max")); assert!(python_config.contains("memory.max"));
@ -99,4 +78,4 @@
let node_config = generate_node_lxc_config(); let node_config = generate_node_lxc_config();
assert!(node_config.contains("gb-sandbox-node")); assert!(node_config.contains("gb-sandbox-node"));
assert!(node_config.contains("/usr/bin/node")); assert!(node_config.contains("/usr/bin/node"));
} }

View file

@ -1,29 +1,22 @@
use botserver::basic::keywords::episodic_memory::{
extract_json, ConversationMessage, Episode, EpisodicMemoryConfig, EpisodicMemoryManager,
ResolutionStatus, Sentiment,
};
use chrono::Utc;
use rhai::Map;
use uuid::Uuid;
#[test]
fn test_default_config() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
#[test]
fn test_default_config() {
let config = EpisodicMemoryConfig::default(); let config = EpisodicMemoryConfig::default();
assert!(config.enabled); assert!(config.enabled);
assert_eq!(config.threshold, 4); assert_eq!(config.threshold, 4);
assert_eq!(config.history, 2); assert_eq!(config.history, 2);
assert_eq!(config.max_episodes, 100); assert_eq!(config.max_episodes, 100);
} }
#[test] #[test]
fn test_should_summarize() {
fn test_should_summarize() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig { let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig {
enabled: true, enabled: true,
threshold: 4, threshold: 4,
@ -35,25 +28,19 @@ use serde_json;
assert!(!manager.should_summarize(2)); assert!(!manager.should_summarize(2));
assert!(manager.should_summarize(4)); assert!(manager.should_summarize(4));
assert!(manager.should_summarize(10)); assert!(manager.should_summarize(10));
} }
#[test]
fn test_extract_json() {
#[test]
fn test_extract_json() {
let response = "Here's the summary:\n```json\n{\"summary\": \"test\"}\n```\n"; let response = "Here's the summary:\n```json\n{\"summary\": \"test\"}\n```\n";
assert!(extract_json(response).is_ok()); assert!(extract_json(response).is_ok());
let response = "The result is {\"summary\": \"test\"}"; let response = "The result is {\"summary\": \"test\"}";
assert!(extract_json(response).is_ok()); assert!(extract_json(response).is_ok());
} }
#[test] #[test]
fn test_generate_summary_prompt() {
fn test_generate_summary_prompt() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default()); let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let messages = vec![ConversationMessage { let messages = vec![ConversationMessage {
id: Uuid::new_v4(), id: Uuid::new_v4(),
@ -65,12 +52,10 @@ use serde_json;
let prompt = manager.generate_summary_prompt(&messages); let prompt = manager.generate_summary_prompt(&messages);
assert!(prompt.contains("CONVERSATION:")); assert!(prompt.contains("CONVERSATION:"));
assert!(prompt.contains("Hello")); assert!(prompt.contains("Hello"));
} }
#[test] #[test]
fn test_parse_summary_response() {
fn test_parse_summary_response() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default()); let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let response = r#"{ let response = r#"{
"summary": "User asked about billing", "summary": "User asked about billing",
@ -101,12 +86,10 @@ use serde_json;
assert_eq!(ep.summary, "User asked about billing"); assert_eq!(ep.summary, "User asked about billing");
assert_eq!(ep.key_topics, vec!["billing", "payment"]); assert_eq!(ep.key_topics, vec!["billing", "payment"]);
assert_eq!(ep.resolution, ResolutionStatus::Resolved); assert_eq!(ep.resolution, ResolutionStatus::Resolved);
} }
#[test] #[test]
fn test_episode_to_dynamic() {
fn test_episode_to_dynamic() {
let episode = Episode { let episode = Episode {
id: Uuid::new_v4(), id: Uuid::new_v4(),
user_id: Uuid::new_v4(), user_id: Uuid::new_v4(),
@ -128,4 +111,4 @@ use serde_json;
let dynamic = episode.to_dynamic(); let dynamic = episode.to_dynamic();
assert!(dynamic.is::<Map>()); assert!(dynamic.is::<Map>());
} }

View file

@ -1,28 +1,20 @@
use botserver::basic::keywords::human_approval::{
ApprovalChannel, ApprovalConfig, ApprovalDecision, ApprovalManager, ApprovalStatus,
};
use chrono::{Duration, Utc};
use rhai::Map;
use uuid::Uuid;
#[test]
fn test_default_config() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
#[test]
fn test_default_config() {
let config = ApprovalConfig::default(); let config = ApprovalConfig::default();
assert!(config.enabled); assert!(config.enabled);
assert_eq!(config.default_timeout, 3600); assert_eq!(config.default_timeout, 3600);
assert_eq!(config.max_reminders, 3); assert_eq!(config.max_reminders, 3);
} }
#[test] #[test]
fn test_create_request() {
fn test_create_request() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request( let request = manager.create_request(
Uuid::new_v4(), Uuid::new_v4(),
@ -40,12 +32,10 @@ use serde_json;
assert_eq!(request.status, ApprovalStatus::Pending); assert_eq!(request.status, ApprovalStatus::Pending);
assert_eq!(request.approval_type, "expense_approval"); assert_eq!(request.approval_type, "expense_approval");
assert!(request.expires_at > Utc::now()); assert!(request.expires_at > Utc::now());
} }
#[test] #[test]
fn test_is_expired() {
fn test_is_expired() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request( let mut request = manager.create_request(
Uuid::new_v4(), Uuid::new_v4(),
@ -62,15 +52,12 @@ use serde_json;
assert!(!manager.is_expired(&request)); assert!(!manager.is_expired(&request));
request.expires_at = Utc::now() - Duration::seconds(10); request.expires_at = Utc::now() - Duration::seconds(10);
assert!(manager.is_expired(&request)); assert!(manager.is_expired(&request));
} }
#[test] #[test]
fn test_process_decision() {
fn test_process_decision() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request( let mut request = manager.create_request(
Uuid::new_v4(), Uuid::new_v4(),
@ -96,12 +83,10 @@ use serde_json;
assert_eq!(request.decision, Some(ApprovalDecision::Approve)); assert_eq!(request.decision, Some(ApprovalDecision::Approve));
assert_eq!(request.decided_by, Some("manager@example.com".to_string())); assert_eq!(request.decided_by, Some("manager@example.com".to_string()));
assert_eq!(request.comments, Some("Looks good!".to_string())); assert_eq!(request.comments, Some("Looks good!".to_string()));
} }
#[test] #[test]
fn test_evaluate_condition() {
fn test_evaluate_condition() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let context = serde_json::json!({ let context = serde_json::json!({
"amount": 15000, "amount": 15000,
@ -117,12 +102,10 @@ use serde_json;
assert!(manager assert!(manager
.evaluate_condition("priority == 2", &context) .evaluate_condition("priority == 2", &context)
.unwrap()); .unwrap());
} }
#[test] #[test]
fn test_handle_timeout_with_default() {
fn test_handle_timeout_with_default() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request( let mut request = manager.create_request(
Uuid::new_v4(), Uuid::new_v4(),
@ -142,12 +125,10 @@ use serde_json;
assert_eq!(request.status, ApprovalStatus::Approved); assert_eq!(request.status, ApprovalStatus::Approved);
assert_eq!(request.decision, Some(ApprovalDecision::Approve)); assert_eq!(request.decision, Some(ApprovalDecision::Approve));
assert_eq!(request.decided_by, Some("system:timeout".to_string())); assert_eq!(request.decided_by, Some("system:timeout".to_string()));
} }
#[test] #[test]
fn test_request_to_dynamic() {
fn test_request_to_dynamic() {
let manager = ApprovalManager::new(ApprovalConfig::default()); let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request( let request = manager.create_request(
Uuid::new_v4(), Uuid::new_v4(),
@ -164,4 +145,4 @@ use serde_json;
let dynamic = request.to_dynamic(); let dynamic = request.to_dynamic();
assert!(dynamic.is::<Map>()); assert!(dynamic.is::<Map>());
} }

View file

@ -1,78 +1,61 @@
use botserver::basic::keywords::on_change::{
detect_provider_from_email, is_cloud_path, parse_folder_path, sanitize_path_for_filename,
ChangeEventType, FolderChangeEvent, FolderMonitor, FolderProvider,
};
use uuid::Uuid;
#[test]
fn test_parse_folder_path_account() {
#![allow(unused_imports)] let (provider, email, path) = parse_folder_path("account://user@gmail.com/Documents/invoices");
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_parse_folder_path_account() {
let (provider, email, path) =
parse_folder_path("account://user@gmail.com/Documents/invoices");
assert_eq!(provider, FolderProvider::GDrive); assert_eq!(provider, FolderProvider::GDrive);
assert_eq!(email, Some("user@gmail.com".to_string())); assert_eq!(email, Some("user@gmail.com".to_string()));
assert_eq!(path, "/Documents/invoices"); assert_eq!(path, "/Documents/invoices");
} }
#[test] #[test]
fn test_parse_folder_path_gdrive() {
fn test_parse_folder_path_gdrive() {
let (provider, email, path) = parse_folder_path("gdrive:///shared/reports"); let (provider, email, path) = parse_folder_path("gdrive:///shared/reports");
assert_eq!(provider, FolderProvider::GDrive); assert_eq!(provider, FolderProvider::GDrive);
assert_eq!(email, None); assert_eq!(email, None);
assert_eq!(path, "/shared/reports"); assert_eq!(path, "/shared/reports");
} }
#[test] #[test]
fn test_parse_folder_path_onedrive() {
fn test_parse_folder_path_onedrive() {
let (provider, email, path) = parse_folder_path("onedrive:///business/docs"); let (provider, email, path) = parse_folder_path("onedrive:///business/docs");
assert_eq!(provider, FolderProvider::OneDrive); assert_eq!(provider, FolderProvider::OneDrive);
assert_eq!(email, None); assert_eq!(email, None);
assert_eq!(path, "/business/docs"); assert_eq!(path, "/business/docs");
} }
#[test] #[test]
fn test_parse_folder_path_dropbox() {
fn test_parse_folder_path_dropbox() {
let (provider, email, path) = parse_folder_path("dropbox:///team/assets"); let (provider, email, path) = parse_folder_path("dropbox:///team/assets");
assert_eq!(provider, FolderProvider::Dropbox); assert_eq!(provider, FolderProvider::Dropbox);
assert_eq!(email, None); assert_eq!(email, None);
assert_eq!(path, "/team/assets"); assert_eq!(path, "/team/assets");
} }
#[test] #[test]
fn test_parse_folder_path_local() {
fn test_parse_folder_path_local() {
let (provider, email, path) = parse_folder_path("/home/user/documents"); let (provider, email, path) = parse_folder_path("/home/user/documents");
assert_eq!(provider, FolderProvider::Local); assert_eq!(provider, FolderProvider::Local);
assert_eq!(email, None); assert_eq!(email, None);
assert_eq!(path, "/home/user/documents"); assert_eq!(path, "/home/user/documents");
} }
#[test] #[test]
fn test_is_cloud_path() {
fn test_is_cloud_path() {
assert!(is_cloud_path("account://user@gmail.com/docs")); assert!(is_cloud_path("account://user@gmail.com/docs"));
assert!(is_cloud_path("gdrive:///shared")); assert!(is_cloud_path("gdrive:///shared"));
assert!(is_cloud_path("onedrive:///files")); assert!(is_cloud_path("onedrive:///files"));
assert!(is_cloud_path("dropbox:///folder")); assert!(is_cloud_path("dropbox:///folder"));
assert!(!is_cloud_path("/local/path")); assert!(!is_cloud_path("/local/path"));
assert!(!is_cloud_path("./relative/path")); assert!(!is_cloud_path("./relative/path"));
} }
#[test] #[test]
fn test_folder_provider_from_str() {
fn test_folder_provider_from_str() {
assert_eq!( assert_eq!(
FolderProvider::from_str("gdrive"), FolderProvider::from_str("gdrive"),
Some(FolderProvider::GDrive) Some(FolderProvider::GDrive)
@ -110,12 +93,10 @@
Some(FolderProvider::Local) Some(FolderProvider::Local)
); );
assert_eq!(FolderProvider::from_str("unknown"), None); assert_eq!(FolderProvider::from_str("unknown"), None);
} }
#[test] #[test]
fn test_change_event_type_from_str() {
fn test_change_event_type_from_str() {
assert_eq!( assert_eq!(
ChangeEventType::from_str("create"), ChangeEventType::from_str("create"),
Some(ChangeEventType::Create) Some(ChangeEventType::Create)
@ -149,12 +130,10 @@
Some(ChangeEventType::Move) Some(ChangeEventType::Move)
); );
assert_eq!(ChangeEventType::from_str("invalid"), None); assert_eq!(ChangeEventType::from_str("invalid"), None);
} }
#[test] #[test]
fn test_sanitize_path() {
fn test_sanitize_path() {
assert_eq!( assert_eq!(
sanitize_path_for_filename("/home/user/docs"), sanitize_path_for_filename("/home/user/docs"),
"_home_user_docs" "_home_user_docs"
@ -167,12 +146,10 @@
sanitize_path_for_filename("path with spaces"), sanitize_path_for_filename("path with spaces"),
"path_with_spaces" "path_with_spaces"
); );
} }
#[test] #[test]
fn test_folder_monitor_struct() {
fn test_folder_monitor_struct() {
let monitor = FolderMonitor { let monitor = FolderMonitor {
id: Uuid::new_v4(), id: Uuid::new_v4(),
bot_id: Uuid::new_v4(), bot_id: Uuid::new_v4(),
@ -190,12 +167,10 @@
assert!(monitor.is_active); assert!(monitor.is_active);
assert!(monitor.watch_subfolders); assert!(monitor.watch_subfolders);
assert_eq!(monitor.account_email, Some("user@gmail.com".to_string())); assert_eq!(monitor.account_email, Some("user@gmail.com".to_string()));
} }
#[test] #[test]
fn test_folder_change_event_struct() {
fn test_folder_change_event_struct() {
let event = FolderChangeEvent { let event = FolderChangeEvent {
id: Uuid::new_v4(), id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(), monitor_id: Uuid::new_v4(),
@ -210,12 +185,10 @@
assert_eq!(event.event_type, "create"); assert_eq!(event.event_type, "create");
assert_eq!(event.file_size, Some(1024)); assert_eq!(event.file_size, Some(1024));
} }
#[test] #[test]
fn test_detect_provider_from_email() {
fn test_detect_provider_from_email() {
assert_eq!( assert_eq!(
detect_provider_from_email("user@gmail.com"), detect_provider_from_email("user@gmail.com"),
FolderProvider::GDrive FolderProvider::GDrive
@ -232,4 +205,4 @@
detect_provider_from_email("user@company.com"), detect_provider_from_email("user@company.com"),
FolderProvider::GDrive FolderProvider::GDrive
); );
} }

View file

@ -1,15 +1,11 @@
use botserver::basic::keywords::on_email::{
is_email_path, parse_email_path, sanitize_email_for_filename, EmailAttachment, EmailMonitor,
EmailReceivedEvent,
};
use uuid::Uuid;
#[test]
fn test_email_monitor_struct() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_email_monitor_struct() {
let monitor = EmailMonitor { let monitor = EmailMonitor {
id: Uuid::new_v4(), id: Uuid::new_v4(),
bot_id: Uuid::new_v4(), bot_id: Uuid::new_v4(),
@ -24,12 +20,10 @@
assert!(monitor.is_active); assert!(monitor.is_active);
assert!(monitor.filter_from.is_none()); assert!(monitor.filter_from.is_none());
assert!(monitor.filter_subject.is_none()); assert!(monitor.filter_subject.is_none());
} }
#[test] #[test]
fn test_email_monitor_with_filters() {
fn test_email_monitor_with_filters() {
let monitor = EmailMonitor { let monitor = EmailMonitor {
id: Uuid::new_v4(), id: Uuid::new_v4(),
bot_id: Uuid::new_v4(), bot_id: Uuid::new_v4(),
@ -43,12 +37,10 @@
assert_eq!(monitor.email_address, "orders@company.com"); assert_eq!(monitor.email_address, "orders@company.com");
assert_eq!(monitor.filter_from, Some("supplier@vendor.com".to_string())); assert_eq!(monitor.filter_from, Some("supplier@vendor.com".to_string()));
assert_eq!(monitor.filter_subject, Some("Invoice".to_string())); assert_eq!(monitor.filter_subject, Some("Invoice".to_string()));
} }
#[test] #[test]
fn test_email_attachment_struct() {
fn test_email_attachment_struct() {
let attachment = EmailAttachment { let attachment = EmailAttachment {
filename: "document.pdf".to_string(), filename: "document.pdf".to_string(),
mime_type: "application/pdf".to_string(), mime_type: "application/pdf".to_string(),
@ -58,12 +50,10 @@
assert_eq!(attachment.filename, "document.pdf"); assert_eq!(attachment.filename, "document.pdf");
assert_eq!(attachment.mime_type, "application/pdf"); assert_eq!(attachment.mime_type, "application/pdf");
assert_eq!(attachment.size, 1024); assert_eq!(attachment.size, 1024);
} }
#[test] #[test]
fn test_email_received_event_struct() {
fn test_email_received_event_struct() {
let event = EmailReceivedEvent { let event = EmailReceivedEvent {
id: Uuid::new_v4(), id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(), monitor_id: Uuid::new_v4(),
@ -85,54 +75,44 @@
assert!(event.has_attachments); assert!(event.has_attachments);
assert_eq!(event.attachments.len(), 1); assert_eq!(event.attachments.len(), 1);
assert_eq!(event.attachments[0].filename, "file.pdf"); assert_eq!(event.attachments[0].filename, "file.pdf");
} }
#[test] #[test]
fn test_parse_email_path_basic() {
fn test_parse_email_path_basic() {
let result = parse_email_path("email://user@gmail.com"); let result = parse_email_path("email://user@gmail.com");
assert!(result.is_some()); assert!(result.is_some());
let (email, folder) = result.unwrap(); let (email, folder) = result.unwrap();
assert_eq!(email, "user@gmail.com"); assert_eq!(email, "user@gmail.com");
assert!(folder.is_none()); assert!(folder.is_none());
} }
#[test] #[test]
fn test_parse_email_path_with_folder() {
fn test_parse_email_path_with_folder() {
let result = parse_email_path("email://user@gmail.com/INBOX"); let result = parse_email_path("email://user@gmail.com/INBOX");
assert!(result.is_some()); assert!(result.is_some());
let (email, folder) = result.unwrap(); let (email, folder) = result.unwrap();
assert_eq!(email, "user@gmail.com"); assert_eq!(email, "user@gmail.com");
assert_eq!(folder, Some("INBOX".to_string())); assert_eq!(folder, Some("INBOX".to_string()));
} }
#[test] #[test]
fn test_parse_email_path_invalid() {
fn test_parse_email_path_invalid() {
assert!(parse_email_path("user@gmail.com").is_none()); assert!(parse_email_path("user@gmail.com").is_none());
assert!(parse_email_path("mailto:user@gmail.com").is_none()); assert!(parse_email_path("mailto:user@gmail.com").is_none());
assert!(parse_email_path("/local/path").is_none()); assert!(parse_email_path("/local/path").is_none());
} }
#[test] #[test]
fn test_is_email_path() {
fn test_is_email_path() {
assert!(is_email_path("email://user@gmail.com")); assert!(is_email_path("email://user@gmail.com"));
assert!(is_email_path("email://user@company.com/INBOX")); assert!(is_email_path("email://user@company.com/INBOX"));
assert!(!is_email_path("user@gmail.com")); assert!(!is_email_path("user@gmail.com"));
assert!(!is_email_path("mailto:user@gmail.com")); assert!(!is_email_path("mailto:user@gmail.com"));
assert!(!is_email_path("account://user@gmail.com")); assert!(!is_email_path("account://user@gmail.com"));
} }
#[test] #[test]
fn test_sanitize_email_for_filename() {
fn test_sanitize_email_for_filename() {
assert_eq!( assert_eq!(
sanitize_email_for_filename("user@gmail.com"), sanitize_email_for_filename("user@gmail.com"),
"user_at_gmail_com" "user_at_gmail_com"
@ -145,12 +125,10 @@
sanitize_email_for_filename("USER@EXAMPLE.COM"), sanitize_email_for_filename("USER@EXAMPLE.COM"),
"user_at_example_com" "user_at_example_com"
); );
} }
#[test] #[test]
fn test_email_event_without_attachments() {
fn test_email_event_without_attachments() {
let event = EmailReceivedEvent { let event = EmailReceivedEvent {
id: Uuid::new_v4(), id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(), monitor_id: Uuid::new_v4(),
@ -166,12 +144,10 @@
assert!(!event.has_attachments); assert!(!event.has_attachments);
assert!(event.attachments.is_empty()); assert!(event.attachments.is_empty());
assert!(event.subject.is_none()); assert!(event.subject.is_none());
} }
#[test] #[test]
fn test_multiple_to_addresses() {
fn test_multiple_to_addresses() {
let event = EmailReceivedEvent { let event = EmailReceivedEvent {
id: Uuid::new_v4(), id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(), monitor_id: Uuid::new_v4(),
@ -192,12 +168,10 @@
assert!(event assert!(event
.to_addresses .to_addresses
.contains(&"user2@example.com".to_string())); .contains(&"user2@example.com".to_string()));
} }
#[test] #[test]
fn test_multiple_attachments() {
fn test_multiple_attachments() {
let attachments = vec![ let attachments = vec![
EmailAttachment { EmailAttachment {
filename: "doc1.pdf".to_string(), filename: "doc1.pdf".to_string(),
@ -221,4 +195,4 @@
assert_eq!(attachments[0].filename, "doc1.pdf"); assert_eq!(attachments[0].filename, "doc1.pdf");
assert_eq!(attachments[1].mime_type, "image/png"); assert_eq!(attachments[1].mime_type, "image/png");
assert_eq!(attachments[2].size, 4096); assert_eq!(attachments[2].size, 4096);
} }

View file

@ -1,15 +1,9 @@
use botserver::basic::keywords::play::{
detect_content_type, extract_title_from_source, ContentType, PlayOptions,
};
#[test]
fn test_content_type_from_extension() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_content_type_from_extension() {
assert_eq!(ContentType::from_extension("mp4"), ContentType::Video); assert_eq!(ContentType::from_extension("mp4"), ContentType::Video);
assert_eq!(ContentType::from_extension("MP3"), ContentType::Audio); assert_eq!(ContentType::from_extension("MP3"), ContentType::Audio);
assert_eq!(ContentType::from_extension("png"), ContentType::Image); assert_eq!(ContentType::from_extension("png"), ContentType::Image);
@ -24,22 +18,18 @@
ContentType::Spreadsheet ContentType::Spreadsheet
); );
assert_eq!(ContentType::from_extension("md"), ContentType::Markdown); assert_eq!(ContentType::from_extension("md"), ContentType::Markdown);
} }
#[test] #[test]
fn test_content_type_from_mime() {
fn test_content_type_from_mime() {
assert_eq!(ContentType::from_mime("video/mp4"), ContentType::Video); assert_eq!(ContentType::from_mime("video/mp4"), ContentType::Video);
assert_eq!(ContentType::from_mime("audio/mpeg"), ContentType::Audio); assert_eq!(ContentType::from_mime("audio/mpeg"), ContentType::Audio);
assert_eq!(ContentType::from_mime("image/png"), ContentType::Image); assert_eq!(ContentType::from_mime("image/png"), ContentType::Image);
assert_eq!(ContentType::from_mime("application/pdf"), ContentType::Pdf); assert_eq!(ContentType::from_mime("application/pdf"), ContentType::Pdf);
} }
#[test] #[test]
fn test_play_options_from_string() {
fn test_play_options_from_string() {
let opts = PlayOptions::from_string("autoplay,loop,muted"); let opts = PlayOptions::from_string("autoplay,loop,muted");
assert!(opts.autoplay); assert!(opts.autoplay);
assert!(opts.loop_content); assert!(opts.loop_content);
@ -57,12 +47,10 @@
assert_eq!(opts.theme, Some("dark".to_string())); assert_eq!(opts.theme, Some("dark".to_string()));
assert_eq!(opts.zoom, Some(1.5)); assert_eq!(opts.zoom, Some(1.5));
assert_eq!(opts.page, Some(3)); assert_eq!(opts.page, Some(3));
} }
#[test] #[test]
fn test_detect_content_type() {
fn test_detect_content_type() {
assert_eq!( assert_eq!(
detect_content_type("https://youtube.com/watch?v=123"), detect_content_type("https://youtube.com/watch?v=123"),
ContentType::Video ContentType::Video
@ -81,12 +69,10 @@
); );
assert_eq!(detect_content_type("report.pdf"), ContentType::Pdf); assert_eq!(detect_content_type("report.pdf"), ContentType::Pdf);
assert_eq!(detect_content_type("main.rs"), ContentType::Code); assert_eq!(detect_content_type("main.rs"), ContentType::Code);
} }
#[test] #[test]
fn test_extract_title_from_source() {
fn test_extract_title_from_source() {
assert_eq!(extract_title_from_source("documents/report.pdf"), "report"); assert_eq!(extract_title_from_source("documents/report.pdf"), "report");
assert_eq!( assert_eq!(
extract_title_from_source("https://example.com/video.mp4?token=abc"), extract_title_from_source("https://example.com/video.mp4?token=abc"),
@ -96,15 +82,13 @@
extract_title_from_source("presentation.pptx"), extract_title_from_source("presentation.pptx"),
"presentation" "presentation"
); );
} }
#[test] #[test]
fn test_player_component() {
fn test_player_component() {
assert_eq!(ContentType::Video.player_component(), "video-player"); assert_eq!(ContentType::Video.player_component(), "video-player");
assert_eq!(ContentType::Audio.player_component(), "audio-player"); assert_eq!(ContentType::Audio.player_component(), "audio-player");
assert_eq!(ContentType::Image.player_component(), "image-viewer"); assert_eq!(ContentType::Image.player_component(), "image-viewer");
assert_eq!(ContentType::Pdf.player_component(), "pdf-viewer"); assert_eq!(ContentType::Pdf.player_component(), "pdf-viewer");
assert_eq!(ContentType::Code.player_component(), "code-viewer"); assert_eq!(ContentType::Code.player_component(), "code-viewer");
} }

View file

@ -1,22 +1,12 @@
use botserver::basic::keywords::set_schedule::parse_natural_schedule;
#[test]
fn test_every_minute() {
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_every_minute() {
assert_eq!(parse_natural_schedule("every minute").unwrap(), "* * * * *"); assert_eq!(parse_natural_schedule("every minute").unwrap(), "* * * * *");
} }
#[test] #[test]
fn test_every_n_minutes() {
fn test_every_n_minutes() {
assert_eq!( assert_eq!(
parse_natural_schedule("every 5 minutes").unwrap(), parse_natural_schedule("every 5 minutes").unwrap(),
"*/5 * * * *" "*/5 * * * *"
@ -29,20 +19,16 @@
parse_natural_schedule("every 30 minutes").unwrap(), parse_natural_schedule("every 30 minutes").unwrap(),
"*/30 * * * *" "*/30 * * * *"
); );
} }
#[test] #[test]
fn test_every_hour() {
fn test_every_hour() {
assert_eq!(parse_natural_schedule("every hour").unwrap(), "0 * * * *"); assert_eq!(parse_natural_schedule("every hour").unwrap(), "0 * * * *");
assert_eq!(parse_natural_schedule("hourly").unwrap(), "0 * * * *"); assert_eq!(parse_natural_schedule("hourly").unwrap(), "0 * * * *");
} }
#[test] #[test]
fn test_every_n_hours() {
fn test_every_n_hours() {
assert_eq!( assert_eq!(
parse_natural_schedule("every 2 hours").unwrap(), parse_natural_schedule("every 2 hours").unwrap(),
"0 */2 * * *" "0 */2 * * *"
@ -51,57 +37,45 @@
parse_natural_schedule("every 6 hours").unwrap(), parse_natural_schedule("every 6 hours").unwrap(),
"0 */6 * * *" "0 */6 * * *"
); );
} }
#[test] #[test]
fn test_every_day() {
fn test_every_day() {
assert_eq!(parse_natural_schedule("every day").unwrap(), "0 0 * * *"); assert_eq!(parse_natural_schedule("every day").unwrap(), "0 0 * * *");
assert_eq!(parse_natural_schedule("daily").unwrap(), "0 0 * * *"); assert_eq!(parse_natural_schedule("daily").unwrap(), "0 0 * * *");
} }
#[test] #[test]
fn test_every_week() {
fn test_every_week() {
assert_eq!(parse_natural_schedule("every week").unwrap(), "0 0 * * 0"); assert_eq!(parse_natural_schedule("every week").unwrap(), "0 0 * * 0");
assert_eq!(parse_natural_schedule("weekly").unwrap(), "0 0 * * 0"); assert_eq!(parse_natural_schedule("weekly").unwrap(), "0 0 * * 0");
} }
#[test] #[test]
fn test_every_month() {
fn test_every_month() {
assert_eq!(parse_natural_schedule("every month").unwrap(), "0 0 1 * *"); assert_eq!(parse_natural_schedule("every month").unwrap(), "0 0 1 * *");
assert_eq!(parse_natural_schedule("monthly").unwrap(), "0 0 1 * *"); assert_eq!(parse_natural_schedule("monthly").unwrap(), "0 0 1 * *");
} }
#[test] #[test]
fn test_at_time() {
fn test_at_time() {
assert_eq!(parse_natural_schedule("at 9am").unwrap(), "0 9 * * *"); assert_eq!(parse_natural_schedule("at 9am").unwrap(), "0 9 * * *");
assert_eq!(parse_natural_schedule("at 9:30am").unwrap(), "30 9 * * *"); assert_eq!(parse_natural_schedule("at 9:30am").unwrap(), "30 9 * * *");
assert_eq!(parse_natural_schedule("at 2pm").unwrap(), "0 14 * * *"); assert_eq!(parse_natural_schedule("at 2pm").unwrap(), "0 14 * * *");
assert_eq!(parse_natural_schedule("at 14:00").unwrap(), "0 14 * * *"); assert_eq!(parse_natural_schedule("at 14:00").unwrap(), "0 14 * * *");
assert_eq!(parse_natural_schedule("at midnight").unwrap(), "0 0 * * *"); assert_eq!(parse_natural_schedule("at midnight").unwrap(), "0 0 * * *");
assert_eq!(parse_natural_schedule("at noon").unwrap(), "0 12 * * *"); assert_eq!(parse_natural_schedule("at noon").unwrap(), "0 12 * * *");
} }
#[test] #[test]
fn test_day_of_week() {
fn test_day_of_week() {
assert_eq!(parse_natural_schedule("every monday").unwrap(), "0 0 * * 1"); assert_eq!(parse_natural_schedule("every monday").unwrap(), "0 0 * * 1");
assert_eq!(parse_natural_schedule("every friday").unwrap(), "0 0 * * 5"); assert_eq!(parse_natural_schedule("every friday").unwrap(), "0 0 * * 5");
assert_eq!(parse_natural_schedule("every sunday").unwrap(), "0 0 * * 0"); assert_eq!(parse_natural_schedule("every sunday").unwrap(), "0 0 * * 0");
} }
#[test] #[test]
fn test_day_with_time() {
fn test_day_with_time() {
assert_eq!( assert_eq!(
parse_natural_schedule("every monday at 9am").unwrap(), parse_natural_schedule("every monday at 9am").unwrap(),
"0 9 * * 1" "0 9 * * 1"
@ -110,12 +84,10 @@
parse_natural_schedule("every friday at 5pm").unwrap(), parse_natural_schedule("every friday at 5pm").unwrap(),
"0 17 * * 5" "0 17 * * 5"
); );
} }
#[test] #[test]
fn test_weekdays() {
fn test_weekdays() {
assert_eq!(parse_natural_schedule("weekdays").unwrap(), "0 0 * * 1-5"); assert_eq!(parse_natural_schedule("weekdays").unwrap(), "0 0 * * 1-5");
assert_eq!( assert_eq!(
parse_natural_schedule("every weekday").unwrap(), parse_natural_schedule("every weekday").unwrap(),
@ -125,23 +97,19 @@
parse_natural_schedule("weekdays at 8am").unwrap(), parse_natural_schedule("weekdays at 8am").unwrap(),
"0 8 * * 1-5" "0 8 * * 1-5"
); );
} }
#[test] #[test]
fn test_weekends() {
fn test_weekends() {
assert_eq!(parse_natural_schedule("weekends").unwrap(), "0 0 * * 0,6"); assert_eq!(parse_natural_schedule("weekends").unwrap(), "0 0 * * 0,6");
assert_eq!( assert_eq!(
parse_natural_schedule("every weekend").unwrap(), parse_natural_schedule("every weekend").unwrap(),
"0 0 * * 0,6" "0 0 * * 0,6"
); );
} }
#[test] #[test]
fn test_combined() {
fn test_combined() {
assert_eq!( assert_eq!(
parse_natural_schedule("every day at 9am").unwrap(), parse_natural_schedule("every day at 9am").unwrap(),
"0 9 * * *" "0 9 * * *"
@ -150,22 +118,18 @@
parse_natural_schedule("every day at 6:30pm").unwrap(), parse_natural_schedule("every day at 6:30pm").unwrap(),
"30 18 * * *" "30 18 * * *"
); );
} }
#[test] #[test]
fn test_hour_range() {
fn test_hour_range() {
assert_eq!( assert_eq!(
parse_natural_schedule("every hour from 9 to 17").unwrap(), parse_natural_schedule("every hour from 9 to 17").unwrap(),
"0 9-17 * * *" "0 9-17 * * *"
); );
} }
#[test] #[test]
fn test_business_hours() {
fn test_business_hours() {
assert_eq!( assert_eq!(
parse_natural_schedule("business hours").unwrap(), parse_natural_schedule("business hours").unwrap(),
"0 9-17 * * 1-5" "0 9-17 * * 1-5"
@ -178,12 +142,10 @@
parse_natural_schedule("every hour during business hours").unwrap(), parse_natural_schedule("every hour during business hours").unwrap(),
"0 9-17 * * 1-5" "0 9-17 * * 1-5"
); );
} }
#[test] #[test]
fn test_raw_cron_passthrough() {
fn test_raw_cron_passthrough() {
assert_eq!(parse_natural_schedule("0 * * * *").unwrap(), "0 * * * *"); assert_eq!(parse_natural_schedule("0 * * * *").unwrap(), "0 * * * *");
assert_eq!( assert_eq!(
parse_natural_schedule("*/5 * * * *").unwrap(), parse_natural_schedule("*/5 * * * *").unwrap(),
@ -193,12 +155,10 @@
parse_natural_schedule("0 9-17 * * 1-5").unwrap(), parse_natural_schedule("0 9-17 * * 1-5").unwrap(),
"0 9-17 * * 1-5" "0 9-17 * * 1-5"
); );
} }
#[test] #[test]
fn test_invalid_input() {
fn test_invalid_input() {
assert!(parse_natural_schedule("potato salad").is_err()); assert!(parse_natural_schedule("potato salad").is_err());
assert!(parse_natural_schedule("every 100 minutes").is_err()); assert!(parse_natural_schedule("every 100 minutes").is_err());
} }