import pytest
from app.services.legendary_scanner import (
    _has_placeholder, _niche_keyword_hits, _word_count,
    _extract_niche_keywords, _rate
)


class TestHelpers:
    def test_has_placeholder_true(self):
        assert _has_placeholder("This is [your brand] placeholder")
        assert _has_placeholder("Lorem ipsum dolor sit amet")

    def test_has_placeholder_false(self):
        assert not _has_placeholder("Genuine brand copy about solar panels")

    def test_niche_keyword_hits(self):
        text = "Solar panels are great for solar energy and solar power"
        assert _niche_keyword_hits(text, ["solar", "energy"]) >= 2

    def test_niche_keyword_hits_empty(self):
        assert _niche_keyword_hits("nothing relevant", ["blockchain"]) == 0

    def test_word_count(self):
        assert _word_count("one two three") == 3
        assert _word_count("") == 0

    def test_extract_niche_keywords(self):
        kws = _extract_niche_keywords("solarpanels.com", "Solar Energy", ["renewable"])
        assert "solar" in kws
        assert len(kws) > 0

    def test_rate_function(self):
        assert _rate(0.95) == "legendary"
        assert _rate(0.9) == "legendary"
        assert _rate(0.6) == "good"
        assert _rate(0.3) == "default"
