"""Tests for notification config service."""
import pytest
from app.domains.notifications.service import (
    upsert_notification_config,
    get_notification_configs,
)


@pytest.mark.asyncio
async def test_upsert_creates_config(db, admin_user):
    """Kann Notification-Config anlegen."""
    await upsert_notification_config(db, admin_user.id, "render_complete", "in_app", True)
    configs = await get_notification_configs(db, admin_user.id)
    assert len(configs) >= 1
    render_cfg = next((c for c in configs if c.event_type == "render_complete"), None)
    assert render_cfg is not None


@pytest.mark.asyncio
async def test_upsert_updates_existing(db, admin_user):
    """Update überschreibt bestehende Config."""
    await upsert_notification_config(db, admin_user.id, "order_submitted", "in_app", True)
    await upsert_notification_config(db, admin_user.id, "order_submitted", "in_app", False)
    configs = await get_notification_configs(db, admin_user.id)
    cfg = next((c for c in configs if c.event_type == "order_submitted"), None)
    assert cfg is not None
    assert cfg.enabled is False
