"""
Ad Detection Integration Tests — Using Real XML Fixtures
=========================================================
Tests is_ad() against real production XML dumps that actually exist
in the fixtures directory.

Previous tests referenced phantom fixtures (sponsored_reel.xml,
organic_post.xml, peugeot_ad.xml) that were never captured.
These tests use verified, existing fixtures.
"""

import os

from GramAddict.core.utils import is_ad

FIX_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fixtures")


def test_home_feed_with_ad_is_detected():
    """
    Test: home_feed_with_ad.xml contains a real 'Ad' marker on an Instagram
    sponsored post. is_ad() MUST return True.
    """
    xml_path = os.path.join(FIX_DIR, "home_feed_with_ad.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is True, "Failed to detect real Ad in home_feed_with_ad.xml!"


def test_explore_feed_is_not_ad():
    """
    Test: explore_feed_dump.xml is a normal explore grid.
    is_ad() MUST return False — no false positives.
    """
    xml_path = os.path.join(FIX_DIR, "explore_feed_dump.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is False, "False positive! Normal explore feed detected as ad!"


def test_user_profile_is_not_ad():
    """
    Test: user_profile_dump.xml is a profile page.
    is_ad() MUST return False.
    """
    xml_path = os.path.join(FIX_DIR, "user_profile_dump.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is False, "False positive! Profile page detected as ad!"


def test_reels_feed_is_not_ad():
    """
    Test: reels_feed_dump.xml is a normal reels page.
    is_ad() MUST return False.
    """
    xml_path = os.path.join(FIX_DIR, "reels_feed_dump.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is False, "False positive! Reels feed detected as ad!"
