import os from pathlib import Path import pytest from journal_bot.config import Config def test_config_loads_from_env(monkeypatch, tmp_path): monkeypatch.setenv("TELEGRAM_TOKEN", "abc") monkeypatch.setenv("ALLOWED_USER_ID", "42") monkeypatch.setenv("VAULT_PATH", str(tmp_path)) monkeypatch.setenv("JOURNAL_BOT_HOME", str(tmp_path / "runtime")) cfg = Config() assert cfg.telegram_token == "abc" assert cfg.allowed_user_id == 42 assert cfg.vault_path == tmp_path assert cfg.queue_dir == tmp_path / "runtime" / "queue" assert cfg.state_dir == tmp_path / "runtime" / "state" assert cfg.logs_dir == tmp_path / "runtime" / "logs" def test_config_missing_required_fails(monkeypatch): for var in ["TELEGRAM_TOKEN", "ALLOWED_USER_ID", "VAULT_PATH"]: monkeypatch.delenv(var, raising=False) with pytest.raises(Exception): Config()