|
| 1 | +import json |
| 2 | +from types import SimpleNamespace |
| 3 | +from unittest.mock import AsyncMock |
| 4 | + |
| 5 | +from bisheng.brand.domain.services.brand_service import BRAND_CONFIG_KEY, BrandService |
| 6 | + |
| 7 | + |
| 8 | +def build_service(raw_value: str | None) -> tuple[BrandService, AsyncMock]: |
| 9 | + get_value = AsyncMock(return_value=raw_value) |
| 10 | + repository = SimpleNamespace(get_value=get_value) |
| 11 | + return BrandService(repository=repository), get_value |
| 12 | + |
| 13 | + |
| 14 | +async def test_runtime_config_returns_builtin_brand_when_not_configured() -> None: |
| 15 | + service, get_value = build_service(None) |
| 16 | + |
| 17 | + config = await service.get_runtime_config() |
| 18 | + |
| 19 | + assert config["brandName"] == {"zh": "BISHENG", "en": "BISHENG"} |
| 20 | + assert config["assets"]["favicon"]["url"] == "/assets/bisheng/favicon.ico" |
| 21 | + assert "linsightAgentName" not in config |
| 22 | + get_value.assert_awaited_once_with(BRAND_CONFIG_KEY) |
| 23 | + |
| 24 | + |
| 25 | +async def test_runtime_config_falls_back_to_builtin_brand_for_invalid_saved_config() -> None: |
| 26 | + service, _ = build_service("{invalid json") |
| 27 | + |
| 28 | + config = await service.get_runtime_config() |
| 29 | + |
| 30 | + assert config["brandName"] == {"zh": "BISHENG", "en": "BISHENG"} |
| 31 | + assert config["assets"]["headerLogoLight"]["url"] == "/assets/bisheng/login-logo-small.png" |
| 32 | + |
| 33 | + |
| 34 | +async def test_runtime_config_preserves_saved_brand_and_fills_default_assets() -> None: |
| 35 | + saved_config = json.dumps({"brandName": {"zh": "定制品牌", "en": "Custom Brand"}}) |
| 36 | + service, _ = build_service(saved_config) |
| 37 | + |
| 38 | + config = await service.get_runtime_config() |
| 39 | + |
| 40 | + assert config["brandName"] == {"zh": "定制品牌", "en": "Custom Brand"} |
| 41 | + assert config["assets"]["favicon"]["url"] == "/assets/bisheng/favicon.ico" |
0 commit comments