use crates_io_api::SyncClient;
use std::time::Duration;
fn test_client() -> SyncClient {
SyncClient::new("cargo-copter-test/0.1.1 (test suite)", Duration::from_millis(1000))
.expect("Failed to create API client")
}
#[test]
fn test_rgb_reverse_dependencies_with_limit() {
let client = test_client();
let deps = client.crate_reverse_dependencies("rgb").expect("Failed to fetch reverse dependencies");
assert!(!deps.dependencies.is_empty(), "rgb should have reverse dependencies");
assert!(deps.meta.total > 10, "rgb should have >10 reverse deps, got {}", deps.meta.total);
}
#[test]
fn test_rgb_pagination() {
let client = test_client();
let page1 = client.crate_reverse_dependencies("rgb").expect("Failed to fetch reverse dependencies");
assert!(page1.dependencies.len() > 10, "Expected >10 deps, got {}", page1.dependencies.len());
assert!(page1.meta.total > 10, "rgb should have some reverse deps");
}
#[test]
fn test_rgb_contains_known_dependents() {
let client = test_client();
let mut all_deps = Vec::new();
let deps = client.crate_reverse_dependencies("rgb").expect("Failed to fetch dependencies");
all_deps.extend(deps.dependencies.iter().map(|d| d.dependency.crate_id.clone()));
assert!(!all_deps.is_empty(), "Should have found some dependencies");
println!("Found {} dependencies for rgb", all_deps.len());
println!("First few: {:?}", &all_deps[..5.min(all_deps.len())]);
}
#[test]
fn test_rgb_version_resolution() {
let client = test_client();
let rgb_crate = client.get_crate("rgb").expect("Failed to fetch rgb crate info");
assert_eq!(rgb_crate.crate_data.id, "rgb");
assert!(!rgb_crate.versions.is_empty(), "rgb should have versions");
let first_version = &rgb_crate.versions[0];
assert!(!first_version.num.is_empty(), "Version number should not be empty");
let _parsed: semver::Version = first_version.num.parse().expect("Version should be valid semver");
}
#[test]
fn test_limit_parameter_enforced() {
let client = test_client();
let deps = client.crate_reverse_dependencies("rgb").expect("Failed to fetch dependencies");
assert!(deps.dependencies.len() > 10, "Expected some dependencies");
assert!(deps.meta.total > 0, "Should report total count");
assert_eq!(deps.dependencies.len() as u64, deps.meta.total, "Dependencies count should match meta.total");
}
#[test]
fn test_api_endpoint_structure() {
let client = test_client();
let deps = client.crate_reverse_dependencies("rgb").expect("API call should succeed");
assert!(
deps.dependencies.iter().all(|d| !d.dependency.crate_id.is_empty()),
"All dependencies should have non-empty crate_id"
);
assert!(deps.meta.total > 0, "Meta total should be > 0");
}