use std::fs;
use tempfile::TempDir;
#[test]
fn test_config_parser_loads_valid_config() {
use actr_config::ConfigParser;
let temp_dir = TempDir::new().unwrap();
let actr_toml = r#"edition = 1
exports = []
[package]
name = "test-service"
description = "A test service"
[package.actr_type]
manufacturer = "test-company"
name = "test-service"
[dependencies]
[system.signaling]
url = "ws://localhost:8080/"
[system.deployment]
realm_id = 1001
[system.discovery]
visible = true
[scripts]
dev = "cargo run"
test = "cargo test"
"#;
let config_path = temp_dir.path().join("Actr.toml");
fs::write(&config_path, actr_toml).unwrap();
let config = ConfigParser::from_file(&config_path).expect("Failed to parse config");
assert_eq!(config.package.name, "test-service");
assert_eq!(config.package.actr_type.manufacturer, "test-company");
assert_eq!(config.package.actr_type.name, "test-service");
assert_eq!(config.realm.realm_id, 1001);
assert!(config.visible_in_discovery);
assert_eq!(config.scripts.get("dev"), Some(&"cargo run".to_string()));
assert_eq!(config.scripts.get("test"), Some(&"cargo test".to_string()));
}
#[test]
fn test_template_case_conversion() {
use actr_cli::templates::TemplateContext;
let ctx = TemplateContext::new("MyProject", "ws://localhost:8080", "echo-service");
assert_eq!(ctx.project_name_snake, "my_project");
assert_eq!(ctx.project_name_pascal, "MyProject");
let ctx = TemplateContext::new("my-project", "ws://localhost:8080", "echo-service");
assert_eq!(ctx.project_name_snake, "my_project");
assert_eq!(ctx.project_name_pascal, "MyProject");
let ctx = TemplateContext::new("my_project", "ws://localhost:8080", "echo-service");
assert_eq!(ctx.project_name_snake, "my_project");
assert_eq!(ctx.project_name_pascal, "MyProject");
}
#[test]
fn test_project_template_basic_generation() {
use actr_cli::templates::{
ProjectTemplate, ProjectTemplateName, SupportedLanguage, TemplateContext,
};
let temp_dir = TempDir::new().unwrap();
let template = ProjectTemplate::new(ProjectTemplateName::Echo, SupportedLanguage::Rust);
let context = TemplateContext::new("test-service", "ws://localhost:8080", "echo-service");
template
.generate(temp_dir.path(), &context)
.expect("Failed to generate template");
assert!(temp_dir.path().join("Cargo.toml").exists());
assert!(temp_dir.path().join("src/lib.rs").exists());
assert!(temp_dir.path().join("build.rs").exists());
assert!(temp_dir.path().join("README.md").exists());
let cargo_toml = fs::read_to_string(temp_dir.path().join("Cargo.toml")).unwrap();
assert!(cargo_toml.contains("name = \"test-service\""));
}