#![allow(deprecated)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
#[test]
fn test_templates_list_command() {
let mut cmd = Command::cargo_bin("vika-cli").unwrap();
cmd.args(["templates", "list"]);
cmd.assert()
.success()
.stdout(predicate::str::contains("Built-in templates"))
.stdout(predicate::str::contains("type-interface"))
.stdout(predicate::str::contains("zod-schema"))
.stdout(predicate::str::contains("api-client-fetch"));
}
#[test]
fn test_custom_template_override() {
let temp_dir = TempDir::new().unwrap();
let original_dir = std::env::current_dir().unwrap();
std::env::set_current_dir(temp_dir.path()).unwrap();
let templates_dir = temp_dir.path().join(".vika").join("templates");
fs::create_dir_all(&templates_dir).unwrap();
let mut cmd = Command::cargo_bin("vika-cli").unwrap();
cmd.args(["templates", "init"]);
let result = cmd.output();
if result.is_err() {
let builtin_content = r#"export interface {{ type_name }} {
{% for field in fields %}
{{ field.name }}{% if field.optional %}?{% endif %}: {{ field.type_name }};
{% endfor %}
}
"#;
fs::write(templates_dir.join("type-interface.tera"), builtin_content).unwrap();
}
let custom_content = r#"export interface {{ type_name }} {
// Custom template override
customField: string;
}
"#;
fs::write(templates_dir.join("type-interface.tera"), custom_content).unwrap();
assert!(templates_dir.join("type-interface.tera").exists());
let content = fs::read_to_string(templates_dir.join("type-interface.tera")).unwrap();
assert!(content.contains("Custom template override"));
std::env::set_current_dir(original_dir).unwrap();
}