use super::*;

#[test]
fn test_get_profile() {
    let chrome = get_profile("chrome").expect("chrome profile should exist");
    assert_eq!(chrome.name, "chrome");
    assert!(chrome.user_agent.contains("Chrome"));

    let unknown = get_profile("unknown");
    assert!(unknown.is_none());
}

#[test]
fn test_rotate() {
    let profile1 = rotate(0);
    let profile2 = rotate(PROFILES.len());
    assert_eq!(profile1, profile2);

    let profile_next = rotate(1);
    assert_ne!(profile1.name, profile_next.name);
}

#[test]
fn test_profiles_not_empty() {
    assert!(
        !PROFILES.is_empty(),
        "TLS profiles list should not be empty"
    );
    assert!(get_profile("firefox").is_some());
    assert!(get_profile("safari").is_some());
    assert!(get_profile("edge").is_some());
}

#[test]
fn profiles_delegate_user_agents_to_shared_stealth_profiles() {
    use guise_profiles::{StealthProfile, profile_facts, profile_user_agent};

    for (name, stealth_profile) in [
        ("chrome", StealthProfile::ChromeWindowsStable),
        ("firefox", StealthProfile::FirefoxLinux),
        ("safari", StealthProfile::SafariMacStable),
        ("edge", StealthProfile::EdgeWindowsStable),
    ] {
        let profile = get_profile(name).expect("profile should exist");
        assert_eq!(
            profile.user_agent,
            profile_user_agent(stealth_profile),
            "{name} User-Agent drifted from stealth-profiles"
        );
        let facts = profile_facts(stealth_profile);
        assert_eq!(profile.accept, facts.accept, "{name} Accept drifted");
        assert_eq!(
            profile.accept_language, facts.accept_language,
            "{name} Accept-Language drifted"
        );
        assert_eq!(
            profile.accept_encoding, facts.accept_encoding,
            "{name} Accept-Encoding drifted"
        );
    }

    let chrome = profile_facts(StealthProfile::ChromeWindowsStable);
    assert_eq!(
        rotate(PROFILES.len()).user_agent,
        profile_user_agent(StealthProfile::ChromeWindowsStable)
    );
    assert_eq!(rotate(PROFILES.len()).accept, chrome.accept);
}
