"""Smoke tests for the health + GDPR endpoints.

Run with:
    ./odoo-bin -c odoo.conf --test-tags encoach_api --stop-after-init
"""

import json

from odoo.tests import HttpCase, tagged


@tagged("post_install", "-at_install", "encoach_api")
class TestHealthEndpoints(HttpCase):
    def test_health_live_returns_200(self):
        """``GET /api/health`` must always return 200 once Odoo has booted."""
        response = self.url_open("/api/health", timeout=10)
        self.assertEqual(response.status_code, 200)
        body = response.json() if hasattr(response, "json") else json.loads(response.text)
        self.assertTrue(body.get("ok") is True or body.get("status") in {"ok", "live"})

    def test_health_ready_returns_2xx(self):
        """``GET /api/health/ready`` is allowed to flap, but must not 5xx."""
        response = self.url_open("/api/health/ready", timeout=10)
        self.assertIn(
            response.status_code, (200, 503),
            f"unexpected status {response.status_code}: {response.text[:200]}",
        )
