#[cfg(test)]
mod tests {
use crate::audit::audit_file;
use crate::rank::DbStore;
use crate::serp::get_autocomplete;
#[test]
fn test_audit_markdown() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("post.md");
std::fs::write(
&path,
"---\ntitle: High Performance Rust Web Frameworks\ndescription: A comprehensive comparison of Actix, Axum, and Warp for building production services.\n---\n# High Performance Rust Web Frameworks\n\n## Introduction\nRust is blazing fast.\n\n\n"
).unwrap();
let report = audit_file(path.to_str().unwrap()).unwrap();
assert_eq!(report.h1_count, 1);
assert_eq!(report.h2_count, 1);
assert_eq!(report.title.as_deref(), Some("High Performance Rust Web Frameworks"));
assert!(report.checks.iter().any(|c| c.name == "H1 Uniqueness" && c.passed));
}
#[test]
fn test_audit_html() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("page.html");
std::fs::write(
&path,
"<!DOCTYPE html><html><head><title>My SEO Title</title><meta name=\"description\" content=\"A valid test description between eighty and one hundred sixty characters long for SEO testing.\"></head><body><h1>Main Heading</h1><img src=\"foo.jpg\" alt=\"Foo\"><a href=\"/local\">Local</a><a href=\"https://google.com\">Ext</a></body></html>"
).unwrap();
let report = audit_file(path.to_str().unwrap()).unwrap();
assert_eq!(report.h1_count, 1);
assert_eq!(report.title.as_deref(), Some("My SEO Title"));
assert_eq!(report.internal_links, 1);
assert_eq!(report.external_links, 1);
assert_eq!(report.images_missing_alt, 0);
}
#[test]
fn test_sqlite_rank_drift() {
let mut db = DbStore::open().unwrap();
let delta1 = db.track_keyword("example.com", "best rust framework", Some(5), Some("https://example.com/rust")).unwrap();
assert_eq!(delta1.curr_rank, Some(5));
let delta2 = db.track_keyword("example.com", "best rust framework", Some(3), Some("https://example.com/rust")).unwrap();
assert_eq!(delta2.prev_rank, Some(5));
assert_eq!(delta2.curr_rank, Some(3));
}
#[test]
fn test_ddg_autocomplete_live() {
let res = get_autocomplete("rust programming");
assert!(res.is_ok());
let list = res.unwrap();
assert!(!list.is_empty(), "Autocomplete should return suggestions");
}
}