# app/modules/dev_tools/tests/unit/test_domain_health_service.py
"""Unit tests for domain_health_service."""

import pytest

from app.modules.dev_tools.services.domain_health_service import _entry


@pytest.mark.unit
@pytest.mark.dev
class TestEntry:
    """Tests for the _entry helper function."""

    def test_entry_pass(self):
        """Passing entry has status 'pass'."""

        class FakeStore:
            store_code = "ACME"
            subdomain = "acme"

        result = _entry(
            domain="acme.rewardflow.lu",
            entry_type="custom subdomain",
            platform_code="RF",
            expected_store=FakeStore(),
            resolved_store=FakeStore(),
            passed=True,
            note="",
        )
        assert result["status"] == "pass"
        assert result["domain"] == "acme.rewardflow.lu"
        assert result["type"] == "custom subdomain"
        assert result["platform_code"] == "RF"
        assert result["expected_store"] == "ACME"
        assert result["resolved_store"] == "ACME"

    def test_entry_fail(self):
        """Failing entry has status 'fail' and includes note."""

        class FakeStore:
            store_code = "ACME"
            subdomain = "acme"

        result = _entry(
            domain="acme.rewardflow.lu",
            entry_type="custom subdomain",
            platform_code="RF",
            expected_store=FakeStore(),
            resolved_store=None,
            passed=False,
            note="custom_subdomain lookup failed",
        )
        assert result["status"] == "fail"
        assert result["resolved_store"] is None
        assert result["note"] == "custom_subdomain lookup failed"

    def test_entry_none_stores(self):
        """Entry handles None expected/resolved stores."""
        result = _entry(
            domain="test.example.com",
            entry_type="custom domain",
            platform_code=None,
            expected_store=None,
            resolved_store=None,
            passed=False,
            note="not found",
        )
        assert result["expected_store"] is None
        assert result["resolved_store"] is None
        assert result["platform_code"] is None
