from pathlib import Path import pytest from app.cli.seed_settings import load_seed from app.services import REQUIRED_SETTINGS def test_production_like_seed_contains_all_mandatory_settings() -> None: path = Path(__file__).resolve().parents[3] / "deployment/app-settings.production-like.yaml" rows = load_seed(path) assert REQUIRED_SETTINGS <= {row["setting_key"] for row in rows} assert all(row["record_status"] == "A" for row in rows) values = {row["setting_key"]: row["setting_value"] for row in rows} assert values["otp.phone.code_length"] == "6" assert values["otp.phone.ttl_seconds"] == "60" assert values["otp.phone.sms_order_timeout_ms"] == "3000" assert values["chat.message.max_length"] == "4000" def test_seed_rejects_invalid_typed_value(tmp_path: Path) -> None: path = tmp_path / "settings.yaml" path.write_text( "schema_version: 1\nsettings:\n" " bad.integer: {type: integer, value: nope, public: false}\n", encoding="utf-8", ) with pytest.raises(ValueError, match="integer value expected"): load_seed(path) @pytest.mark.parametrize( ("key", "value", "message"), [ ("otp.phone.code_length", 3, "between 4 and 10"), ("otp.phone.ttl_seconds", 61, "divisible by 60"), ("otp.phone.sms_order_timeout_ms", 0, "must be positive"), ], ) def test_seed_rejects_invalid_otp_settings( tmp_path: Path, key: str, value: int, message: str ) -> None: path = tmp_path / "settings.yaml" path.write_text( "schema_version: 1\nsettings:\n" f" {key}: {{type: integer, value: {value}, public: false}}\n", encoding="utf-8", ) with pytest.raises(ValueError, match=message): load_seed(path) def test_seed_rejects_public_otp_setting(tmp_path: Path) -> None: path = tmp_path / "settings.yaml" path.write_text( "schema_version: 1\nsettings:\n" " otp.phone.code_length: {type: integer, value: 6, public: true}\n", encoding="utf-8", ) with pytest.raises(ValueError, match="must not be public"): load_seed(path) @pytest.mark.parametrize("value", [0, 10001]) def test_seed_rejects_invalid_chat_message_max_length(tmp_path: Path, value: int) -> None: path = tmp_path / "settings.yaml" path.write_text( "schema_version: 1\nsettings:\n" f" chat.message.max_length: {{type: integer, value: {value}, public: true}}\n", encoding="utf-8", ) with pytest.raises(ValueError, match="value must be between 1 and 10000"): load_seed(path)