//! Tests for validation module

use crate::dev::validation::validate_node_names;

#[test]
fn test_validate_node_names_valid() {
    let available = vec!["speaker".to_string(), "listener".to_string(), "motor".to_string()];

    let result = validate_node_names(&["speaker".to_string(), "motor".to_string()], &available);
    assert!(result.is_ok());
    assert_eq!(result.unwrap(), vec!["speaker".to_string(), "motor".to_string()]);
}

#[test]
fn test_validate_node_names_all_available() {
    let available = vec!["speaker".to_string(), "listener".to_string()];
    let result = validate_node_names(&available, &available);
    assert!(result.is_ok());
}

#[test]
fn test_validate_node_names_invalid() {
    let available = vec!["speaker".to_string(), "listener".to_string()];
    let result = validate_node_names(&["invalid".to_string()], &available);
    assert!(result.is_err());

    let err_msg = result.unwrap_err().to_string();
    assert!(err_msg.contains("Unknown nodes"));
    assert!(err_msg.contains("invalid"));
}

#[test]
fn test_validate_node_names_multiple_invalid() {
    let available = vec!["speaker".to_string()];
    let result = validate_node_names(&["invalid1".to_string(), "invalid2".to_string()], &available);
    assert!(result.is_err());

    let err_msg = result.unwrap_err().to_string();
    assert!(err_msg.contains("invalid1"));
    assert!(err_msg.contains("invalid2"));
}

#[test]
fn test_validate_node_names_empty() {
    let available = vec!["speaker".to_string()];
    let result = validate_node_names(&[], &available);
    assert!(result.is_ok());
    assert_eq!(result.unwrap(), Vec::<String>::new());
}

#[test]
fn test_validate_node_names_partial_match() {
    let available = vec!["speaker".to_string(), "listener".to_string(), "motor".to_string()];
    let requested = vec!["speaker".to_string(), "invalid".to_string()];
    let result = validate_node_names(&requested, &available);
    assert!(result.is_err());
}
