from pathlib import Path
import unittest


ROOT = Path(__file__).resolve().parents[1]


class PrivateCandleChartContractTests(unittest.TestCase):
    def test_worker_private_candle_endpoint_accepts_the_interface_chart_contract(self) -> None:
        endpoint = ROOT / "api" / "private" / "get_candles.php"
        self.assertTrue(endpoint.is_file(), "worker candle endpoint is missing")

        source = endpoint.read_text(encoding="utf-8")
        for field in ("test_id", "start", "end", "resolution", "time"):
            self.assertIn(f"$_POST['{field}']", source)
        self.assertIn("new Candle($test_id, $resolution)", source)
        self.assertIn("$candle->getInPeriod", source)
        self.assertIn("echo json_encode($candles)", source)


if __name__ == "__main__":
    unittest.main()
