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;
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_reflection_type_from_str() {
#[test]
fn test_reflection_type_from_str() {
assert_eq!(
ReflectionType::from("conversation_quality"),
ReflectionType::ConversationQuality
@ -26,22 +21,18 @@
ReflectionType::from("performance"),
ReflectionType::Performance
);
}
}
#[test]
fn test_reflection_config_default() {
#[test]
fn test_reflection_config_default() {
let config = ReflectionConfig::default();
assert!(!config.enabled);
assert_eq!(config.interval, 10);
assert!(!config.auto_apply);
}
}
#[test]
fn test_reflection_result_new() {
#[test]
fn test_reflection_result_new() {
let bot_id = Uuid::new_v4();
let session_id = Uuid::new_v4();
let result = ReflectionResult::new(bot_id, session_id, ReflectionType::ConversationQuality);
@ -50,12 +41,10 @@
assert_eq!(result.session_id, session_id);
assert_eq!(result.score, 0.0);
assert!(result.insights.is_empty());
}
}
#[test]
fn test_reflection_result_from_json() {
#[test]
fn test_reflection_result_from_json() {
let json_response = r#"{
"score": 7.5,
"key_insights": ["Users prefer concise responses", "Technical questions need more detail"],
@ -75,12 +64,10 @@
assert_eq!(result.insights.len(), 2);
assert_eq!(result.improvements.len(), 2);
assert_eq!(result.positive_patterns.len(), 2);
}
}
#[test]
fn test_reflection_result_needs_improvement() {
#[test]
fn test_reflection_result_needs_improvement() {
let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);
@ -89,12 +76,10 @@
result.score = 8.0;
assert!(!result.needs_improvement(6.0));
}
}
#[test]
fn test_extract_insights_from_text() {
#[test]
fn test_extract_insights_from_text() {
let text = "Here are some insights:\n\
1. Users prefer short responses\n\
2. Technical questions need examples\n\
@ -103,21 +88,17 @@
let insights = extract_insights_from_text(text);
assert!(!insights.is_empty());
}
}
#[test]
fn test_reflection_type_prompt_template() {
#[test]
fn test_reflection_type_prompt_template() {
let template = ReflectionType::ConversationQuality.prompt_template();
assert!(template.contains("{conversation}"));
assert!(template.contains("JSON format"));
}
}
#[test]
fn test_reflection_result_summary() {
#[test]
fn test_reflection_result_summary() {
let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);
result.score = 7.5;
@ -130,4 +111,4 @@
assert!(summary.contains("15"));
assert!(summary.contains("2"));
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,
};
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_sandbox_config_default() {
#[test]
fn test_sandbox_config_default() {
let config = SandboxConfig::default();
assert!(config.enabled);
assert_eq!(config.timeout_seconds, 30);
assert_eq!(config.memory_limit_mb, 256);
assert!(!config.network_enabled);
}
}
#[test]
fn test_execution_result_success() {
#[test]
fn test_execution_result_success() {
let result = ExecutionResult::success("Hello, World!".to_string(), String::new(), 100);
assert!(result.is_success());
assert_eq!(result.output(), "Hello, World!");
}
}
#[test]
fn test_execution_result_error() {
#[test]
fn test_execution_result_error() {
let result = ExecutionResult::error("Something went wrong");
assert!(!result.is_success());
assert!(result.output().contains("Error"));
}
}
#[test]
fn test_execution_result_timeout() {
#[test]
fn test_execution_result_timeout() {
let result = ExecutionResult::timeout();
assert!(!result.is_success());
assert!(result.timed_out);
}
}
#[test]
fn test_code_language_from_str() {
#[test]
fn test_code_language_from_str() {
assert_eq!(CodeLanguage::from("python"), CodeLanguage::Python);
assert_eq!(CodeLanguage::from("PYTHON"), CodeLanguage::Python);
assert_eq!(CodeLanguage::from("py"), CodeLanguage::Python);
@ -55,30 +42,24 @@
assert_eq!(CodeLanguage::from("js"), CodeLanguage::JavaScript);
assert_eq!(CodeLanguage::from("node"), CodeLanguage::JavaScript);
assert_eq!(CodeLanguage::from("bash"), CodeLanguage::Bash);
}
}
#[test]
fn test_code_language_file_extension() {
#[test]
fn test_code_language_file_extension() {
assert_eq!(CodeLanguage::Python.file_extension(), "py");
assert_eq!(CodeLanguage::JavaScript.file_extension(), "js");
assert_eq!(CodeLanguage::Bash.file_extension(), "sh");
}
}
#[test]
fn test_code_language_interpreter() {
#[test]
fn test_code_language_interpreter() {
assert_eq!(CodeLanguage::Python.interpreter(), "python3");
assert_eq!(CodeLanguage::JavaScript.interpreter(), "node");
assert_eq!(CodeLanguage::Bash.interpreter(), "bash");
}
}
#[test]
fn test_sandbox_runtime_from_str() {
#[test]
fn test_sandbox_runtime_from_str() {
assert_eq!(SandboxRuntime::from("lxc"), SandboxRuntime::LXC);
assert_eq!(SandboxRuntime::from("docker"), SandboxRuntime::Docker);
assert_eq!(
@ -86,12 +67,10 @@
SandboxRuntime::Firecracker
);
assert_eq!(SandboxRuntime::from("unknown"), SandboxRuntime::Process);
}
}
#[test]
fn test_lxc_config_generation() {
#[test]
fn test_lxc_config_generation() {
let python_config = generate_python_lxc_config();
assert!(python_config.contains("gb-sandbox-python"));
assert!(python_config.contains("memory.max"));
@ -99,4 +78,4 @@
let node_config = generate_node_lxc_config();
assert!(node_config.contains("gb-sandbox-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;
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
#[test]
fn test_default_config() {
#[test]
fn test_default_config() {
let config = EpisodicMemoryConfig::default();
assert!(config.enabled);
assert_eq!(config.threshold, 4);
assert_eq!(config.history, 2);
assert_eq!(config.max_episodes, 100);
}
}
#[test]
fn test_should_summarize() {
#[test]
fn test_should_summarize() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig {
enabled: true,
threshold: 4,
@ -35,25 +28,19 @@ use serde_json;
assert!(!manager.should_summarize(2));
assert!(manager.should_summarize(4));
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";
assert!(extract_json(response).is_ok());
let response = "The result is {\"summary\": \"test\"}";
assert!(extract_json(response).is_ok());
}
}
#[test]
fn test_generate_summary_prompt() {
#[test]
fn test_generate_summary_prompt() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let messages = vec![ConversationMessage {
id: Uuid::new_v4(),
@ -65,12 +52,10 @@ use serde_json;
let prompt = manager.generate_summary_prompt(&messages);
assert!(prompt.contains("CONVERSATION:"));
assert!(prompt.contains("Hello"));
}
}
#[test]
fn test_parse_summary_response() {
#[test]
fn test_parse_summary_response() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let response = r#"{
"summary": "User asked about billing",
@ -101,12 +86,10 @@ use serde_json;
assert_eq!(ep.summary, "User asked about billing");
assert_eq!(ep.key_topics, vec!["billing", "payment"]);
assert_eq!(ep.resolution, ResolutionStatus::Resolved);
}
}
#[test]
fn test_episode_to_dynamic() {
#[test]
fn test_episode_to_dynamic() {
let episode = Episode {
id: Uuid::new_v4(),
user_id: Uuid::new_v4(),
@ -128,4 +111,4 @@ use serde_json;
let dynamic = episode.to_dynamic();
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;
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
#[test]
fn test_default_config() {
#[test]
fn test_default_config() {
let config = ApprovalConfig::default();
assert!(config.enabled);
assert_eq!(config.default_timeout, 3600);
assert_eq!(config.max_reminders, 3);
}
}
#[test]
fn test_create_request() {
#[test]
fn test_create_request() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request(
Uuid::new_v4(),
@ -40,12 +32,10 @@ use serde_json;
assert_eq!(request.status, ApprovalStatus::Pending);
assert_eq!(request.approval_type, "expense_approval");
assert!(request.expires_at > Utc::now());
}
}
#[test]
fn test_is_expired() {
#[test]
fn test_is_expired() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
Uuid::new_v4(),
@ -62,15 +52,12 @@ use serde_json;
assert!(!manager.is_expired(&request));
request.expires_at = Utc::now() - Duration::seconds(10);
assert!(manager.is_expired(&request));
}
}
#[test]
fn test_process_decision() {
#[test]
fn test_process_decision() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
Uuid::new_v4(),
@ -96,12 +83,10 @@ use serde_json;
assert_eq!(request.decision, Some(ApprovalDecision::Approve));
assert_eq!(request.decided_by, Some("manager@example.com".to_string()));
assert_eq!(request.comments, Some("Looks good!".to_string()));
}
}
#[test]
fn test_evaluate_condition() {
#[test]
fn test_evaluate_condition() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let context = serde_json::json!({
"amount": 15000,
@ -117,12 +102,10 @@ use serde_json;
assert!(manager
.evaluate_condition("priority == 2", &context)
.unwrap());
}
}
#[test]
fn test_handle_timeout_with_default() {
#[test]
fn test_handle_timeout_with_default() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
Uuid::new_v4(),
@ -142,12 +125,10 @@ use serde_json;
assert_eq!(request.status, ApprovalStatus::Approved);
assert_eq!(request.decision, Some(ApprovalDecision::Approve));
assert_eq!(request.decided_by, Some("system:timeout".to_string()));
}
}
#[test]
fn test_request_to_dynamic() {
#[test]
fn test_request_to_dynamic() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request(
Uuid::new_v4(),
@ -164,4 +145,4 @@ use serde_json;
let dynamic = request.to_dynamic();
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;
#![allow(unused_imports)]
#![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");
#[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!(email, Some("user@gmail.com".to_string()));
assert_eq!(path, "/Documents/invoices");
}
}
#[test]
fn test_parse_folder_path_gdrive() {
#[test]
fn test_parse_folder_path_gdrive() {
let (provider, email, path) = parse_folder_path("gdrive:///shared/reports");
assert_eq!(provider, FolderProvider::GDrive);
assert_eq!(email, None);
assert_eq!(path, "/shared/reports");
}
}
#[test]
fn test_parse_folder_path_onedrive() {
#[test]
fn test_parse_folder_path_onedrive() {
let (provider, email, path) = parse_folder_path("onedrive:///business/docs");
assert_eq!(provider, FolderProvider::OneDrive);
assert_eq!(email, None);
assert_eq!(path, "/business/docs");
}
}
#[test]
fn test_parse_folder_path_dropbox() {
#[test]
fn test_parse_folder_path_dropbox() {
let (provider, email, path) = parse_folder_path("dropbox:///team/assets");
assert_eq!(provider, FolderProvider::Dropbox);
assert_eq!(email, None);
assert_eq!(path, "/team/assets");
}
}
#[test]
fn test_parse_folder_path_local() {
#[test]
fn test_parse_folder_path_local() {
let (provider, email, path) = parse_folder_path("/home/user/documents");
assert_eq!(provider, FolderProvider::Local);
assert_eq!(email, None);
assert_eq!(path, "/home/user/documents");
}
}
#[test]
fn test_is_cloud_path() {
#[test]
fn test_is_cloud_path() {
assert!(is_cloud_path("account://user@gmail.com/docs"));
assert!(is_cloud_path("gdrive:///shared"));
assert!(is_cloud_path("onedrive:///files"));
assert!(is_cloud_path("dropbox:///folder"));
assert!(!is_cloud_path("/local/path"));
assert!(!is_cloud_path("./relative/path"));
}
}
#[test]
fn test_folder_provider_from_str() {
#[test]
fn test_folder_provider_from_str() {
assert_eq!(
FolderProvider::from_str("gdrive"),
Some(FolderProvider::GDrive)
@ -110,12 +93,10 @@
Some(FolderProvider::Local)
);
assert_eq!(FolderProvider::from_str("unknown"), None);
}
}
#[test]
fn test_change_event_type_from_str() {
#[test]
fn test_change_event_type_from_str() {
assert_eq!(
ChangeEventType::from_str("create"),
Some(ChangeEventType::Create)
@ -149,12 +130,10 @@
Some(ChangeEventType::Move)
);
assert_eq!(ChangeEventType::from_str("invalid"), None);
}
}
#[test]
fn test_sanitize_path() {
#[test]
fn test_sanitize_path() {
assert_eq!(
sanitize_path_for_filename("/home/user/docs"),
"_home_user_docs"
@ -167,12 +146,10 @@
sanitize_path_for_filename("path with spaces"),
"path_with_spaces"
);
}
}
#[test]
fn test_folder_monitor_struct() {
#[test]
fn test_folder_monitor_struct() {
let monitor = FolderMonitor {
id: Uuid::new_v4(),
bot_id: Uuid::new_v4(),
@ -190,12 +167,10 @@
assert!(monitor.is_active);
assert!(monitor.watch_subfolders);
assert_eq!(monitor.account_email, Some("user@gmail.com".to_string()));
}
}
#[test]
fn test_folder_change_event_struct() {
#[test]
fn test_folder_change_event_struct() {
let event = FolderChangeEvent {
id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(),
@ -210,12 +185,10 @@
assert_eq!(event.event_type, "create");
assert_eq!(event.file_size, Some(1024));
}
}
#[test]
fn test_detect_provider_from_email() {
#[test]
fn test_detect_provider_from_email() {
assert_eq!(
detect_provider_from_email("user@gmail.com"),
FolderProvider::GDrive
@ -232,4 +205,4 @@
detect_provider_from_email("user@company.com"),
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;
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_email_monitor_struct() {
#[test]
fn test_email_monitor_struct() {
let monitor = EmailMonitor {
id: Uuid::new_v4(),
bot_id: Uuid::new_v4(),
@ -24,12 +20,10 @@
assert!(monitor.is_active);
assert!(monitor.filter_from.is_none());
assert!(monitor.filter_subject.is_none());
}
}
#[test]
fn test_email_monitor_with_filters() {
#[test]
fn test_email_monitor_with_filters() {
let monitor = EmailMonitor {
id: Uuid::new_v4(),
bot_id: Uuid::new_v4(),
@ -43,12 +37,10 @@
assert_eq!(monitor.email_address, "orders@company.com");
assert_eq!(monitor.filter_from, Some("supplier@vendor.com".to_string()));
assert_eq!(monitor.filter_subject, Some("Invoice".to_string()));
}
}
#[test]
fn test_email_attachment_struct() {
#[test]
fn test_email_attachment_struct() {
let attachment = EmailAttachment {
filename: "document.pdf".to_string(),
mime_type: "application/pdf".to_string(),
@ -58,12 +50,10 @@
assert_eq!(attachment.filename, "document.pdf");
assert_eq!(attachment.mime_type, "application/pdf");
assert_eq!(attachment.size, 1024);
}
}
#[test]
fn test_email_received_event_struct() {
#[test]
fn test_email_received_event_struct() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(),
@ -85,54 +75,44 @@
assert!(event.has_attachments);
assert_eq!(event.attachments.len(), 1);
assert_eq!(event.attachments[0].filename, "file.pdf");
}
}
#[test]
fn test_parse_email_path_basic() {
#[test]
fn test_parse_email_path_basic() {
let result = parse_email_path("email://user@gmail.com");
assert!(result.is_some());
let (email, folder) = result.unwrap();
assert_eq!(email, "user@gmail.com");
assert!(folder.is_none());
}
}
#[test]
fn test_parse_email_path_with_folder() {
#[test]
fn test_parse_email_path_with_folder() {
let result = parse_email_path("email://user@gmail.com/INBOX");
assert!(result.is_some());
let (email, folder) = result.unwrap();
assert_eq!(email, "user@gmail.com");
assert_eq!(folder, Some("INBOX".to_string()));
}
}
#[test]
fn test_parse_email_path_invalid() {
#[test]
fn test_parse_email_path_invalid() {
assert!(parse_email_path("user@gmail.com").is_none());
assert!(parse_email_path("mailto:user@gmail.com").is_none());
assert!(parse_email_path("/local/path").is_none());
}
}
#[test]
fn test_is_email_path() {
#[test]
fn test_is_email_path() {
assert!(is_email_path("email://user@gmail.com"));
assert!(is_email_path("email://user@company.com/INBOX"));
assert!(!is_email_path("user@gmail.com"));
assert!(!is_email_path("mailto:user@gmail.com"));
assert!(!is_email_path("account://user@gmail.com"));
}
}
#[test]
fn test_sanitize_email_for_filename() {
#[test]
fn test_sanitize_email_for_filename() {
assert_eq!(
sanitize_email_for_filename("user@gmail.com"),
"user_at_gmail_com"
@ -145,12 +125,10 @@
sanitize_email_for_filename("USER@EXAMPLE.COM"),
"user_at_example_com"
);
}
}
#[test]
fn test_email_event_without_attachments() {
#[test]
fn test_email_event_without_attachments() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(),
@ -166,12 +144,10 @@
assert!(!event.has_attachments);
assert!(event.attachments.is_empty());
assert!(event.subject.is_none());
}
}
#[test]
fn test_multiple_to_addresses() {
#[test]
fn test_multiple_to_addresses() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
monitor_id: Uuid::new_v4(),
@ -192,12 +168,10 @@
assert!(event
.to_addresses
.contains(&"user2@example.com".to_string()));
}
}
#[test]
fn test_multiple_attachments() {
#[test]
fn test_multiple_attachments() {
let attachments = vec![
EmailAttachment {
filename: "doc1.pdf".to_string(),
@ -221,4 +195,4 @@
assert_eq!(attachments[0].filename, "doc1.pdf");
assert_eq!(attachments[1].mime_type, "image/png");
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,
};
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
fn test_content_type_from_extension() {
#[test]
fn test_content_type_from_extension() {
assert_eq!(ContentType::from_extension("mp4"), ContentType::Video);
assert_eq!(ContentType::from_extension("MP3"), ContentType::Audio);
assert_eq!(ContentType::from_extension("png"), ContentType::Image);
@ -24,22 +18,18 @@
ContentType::Spreadsheet
);
assert_eq!(ContentType::from_extension("md"), ContentType::Markdown);
}
}
#[test]
fn test_content_type_from_mime() {
#[test]
fn test_content_type_from_mime() {
assert_eq!(ContentType::from_mime("video/mp4"), ContentType::Video);
assert_eq!(ContentType::from_mime("audio/mpeg"), ContentType::Audio);
assert_eq!(ContentType::from_mime("image/png"), ContentType::Image);
assert_eq!(ContentType::from_mime("application/pdf"), ContentType::Pdf);
}
}
#[test]
fn test_play_options_from_string() {
#[test]
fn test_play_options_from_string() {
let opts = PlayOptions::from_string("autoplay,loop,muted");
assert!(opts.autoplay);
assert!(opts.loop_content);
@ -57,12 +47,10 @@
assert_eq!(opts.theme, Some("dark".to_string()));
assert_eq!(opts.zoom, Some(1.5));
assert_eq!(opts.page, Some(3));
}
}
#[test]
fn test_detect_content_type() {
#[test]
fn test_detect_content_type() {
assert_eq!(
detect_content_type("https://youtube.com/watch?v=123"),
ContentType::Video
@ -81,12 +69,10 @@
);
assert_eq!(detect_content_type("report.pdf"), ContentType::Pdf);
assert_eq!(detect_content_type("main.rs"), ContentType::Code);
}
}
#[test]
fn test_extract_title_from_source() {
#[test]
fn test_extract_title_from_source() {
assert_eq!(extract_title_from_source("documents/report.pdf"), "report");
assert_eq!(
extract_title_from_source("https://example.com/video.mp4?token=abc"),
@ -96,15 +82,13 @@
extract_title_from_source("presentation.pptx"),
"presentation"
);
}
}
#[test]
fn test_player_component() {
#[test]
fn test_player_component() {
assert_eq!(ContentType::Video.player_component(), "video-player");
assert_eq!(ContentType::Audio.player_component(), "audio-player");
assert_eq!(ContentType::Image.player_component(), "image-viewer");
assert_eq!(ContentType::Pdf.player_component(), "pdf-viewer");
assert_eq!(ContentType::Code.player_component(), "code-viewer");
}
}

View file

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