from pathlib import Path from linkki_poster.cli import apply_language_order, load_config, load_config_strict from linkki_poster.models import Language, LanguageAssets def test_load_config_strict_reads_required_fields(tmp_path: Path) -> None: config_path = tmp_path / "telegram_config.json" config_path.write_text('{"bot_token":"token","chat_id":"-100123"}', encoding="utf-8") config = load_config_strict(tmp_path) assert config.bot_token == "token" assert config.chat_id == "-100123" assert config.channel_username == "" def test_load_config_strict_fails_when_missing(tmp_path: Path) -> None: try: load_config_strict(tmp_path) except FileNotFoundError: return raise AssertionError("Expected FileNotFoundError") def test_load_config_strict_fails_when_required_field_missing(tmp_path: Path) -> None: config_path = tmp_path / "telegram_config.json" config_path.write_text('{"bot_token":"token"}', encoding="utf-8") try: load_config_strict(tmp_path) except ValueError: return raise AssertionError("Expected ValueError") def test_apply_language_order_uses_requested_prefix_and_keeps_rest(tmp_path: Path) -> None: fi = LanguageAssets(Language.FI, tmp_path / "fi.md", "fi", []) sv = LanguageAssets(Language.SV, tmp_path / "sv.md", "sv", []) en = LanguageAssets(Language.EN, tmp_path / "en.md", "en", []) ordered = apply_language_order([fi, sv, en], "en,fi") assert [item.language for item in ordered] == [Language.EN, Language.FI, Language.SV] def test_load_config_interactive_prompts_missing_values(tmp_path: Path) -> None: answers = iter(["token_from_prompt", "-100123", "publicname"]) config = load_config(tmp_path, non_interactive=False, input_fn=lambda _: next(answers)) assert config.bot_token == "token_from_prompt" assert config.chat_id == "-100123" assert config.channel_username == "publicname"