from django.test import TestCase
from django.urls import reverse


class HealthDashboardTests(TestCase):
    def test_health_page_is_visual_and_public(self):
        response = self.client.get(reverse("health"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Estado do Portal Kreate4Web")
        self.assertContains(response, "Executar testes agora")

    def test_health_json_and_runtime_endpoint(self):
        response = self.client.get(reverse("health") + "?format=json")
        self.assertEqual(response.status_code, 200)
        self.assertIn(response.json()["status"], {"ok", "warning"})
        self.assertGreaterEqual(len(response.json()["checks"]), 8)
        response = self.client.post(reverse("health_run"))
        self.assertEqual(response.status_code, 200)
        self.assertIn("summary", response.json())
