"""Tests for the demo module."""

from yaml_doctor.demo import DEMOS
from yaml_doctor.scanner import scan_content


class TestDemoData:
    def test_all_demos_defined(self):
        expected = {"kubernetes", "compose", "github-actions", "gitlab-ci", "yaml"}
        assert set(DEMOS.keys()) == expected

    def test_all_demos_valid_yaml(self):
        for name, (filename, content) in DEMOS.items():
            result = scan_content(content, filename)
            # All demos should parse (valid YAML)
            assert result.valid_yaml is True, f"Demo '{name}' failed to parse"

    def test_all_demos_have_findings(self):
        for name, (filename, content) in DEMOS.items():
            result = scan_content(content, filename)
            assert len(result.findings) > 0, f"Demo '{name}' should have findings"

    def test_kubernetes_demo_detects_issues(self):
        _, content = DEMOS["kubernetes"]
        result = scan_content(content, "deployment.yaml")
        rule_ids = {f.rule.rule_id for f in result.findings}
        # Should detect at least: privileged, :latest tag
        assert "K8S004" in rule_ids or "K8S005" in rule_ids

    def test_compose_demo_detects_issues(self):
        _, content = DEMOS["compose"]
        result = scan_content(content, "docker-compose.yml")
        rule_ids = {f.rule.rule_id for f in result.findings}
        assert "DC001" in rule_ids or "DC002" in rule_ids

    def test_github_actions_demo_detects_issues(self):
        filename, content = DEMOS["github-actions"]
        result = scan_content(content, filename)
        rule_ids = {f.rule.rule_id for f in result.findings}
        assert "GHA001" in rule_ids or "GHA009" in rule_ids

    def test_gitlab_ci_demo_detects_issues(self):
        filename, content = DEMOS["gitlab-ci"]
        result = scan_content(content, filename)
        rule_ids = {f.rule.rule_id for f in result.findings}
        assert len(rule_ids) > 0

    def test_demo_filenames(self):
        assert DEMOS["kubernetes"][0] == "deployment.yaml"
        assert DEMOS["compose"][0] == "docker-compose.yml"
        assert DEMOS["github-actions"][0] == ".github/workflows/ci.yml"
        assert DEMOS["gitlab-ci"][0] == ".gitlab-ci.yml"
        assert DEMOS["yaml"][0] == "config.yaml"
