import os
import unittest

from core.websocket_client import QingjianAPIClient


class OversizeGuardTest(unittest.TestCase):
    def setUp(self):
        os.environ["MAX_SERVICE_SIZE_LONGEST_METERS"] = "10"
        os.environ["MAX_SERVICE_SIZE_AREA_SQM"] = "20"

    def test_extract_size_pairs(self):
        c = QingjianAPIClient(enable_agent=False)
        pairs = c._extract_size_pairs_m("15*6.4米 高度")
        self.assertTrue(len(pairs) >= 1)
        self.assertEqual(pairs[0], (15.0, 6.4))

    def test_oversize_hits(self):
        c = QingjianAPIClient(enable_agent=False)
        r = c._oversize_reply_if_needed("15*6.4米")
        self.assertIn("做不了", r)

    def test_normal_size_not_hit(self):
        c = QingjianAPIClient(enable_agent=False)
        r = c._oversize_reply_if_needed("2.4*1.2米")
        self.assertEqual(r, "")

    def tearDown(self):
        os.environ.pop("MAX_SERVICE_SIZE_LONGEST_METERS", None)
        os.environ.pop("MAX_SERVICE_SIZE_AREA_SQM", None)


if __name__ == "__main__":
    unittest.main(verbosity=2)
