"""Tests for notification queue.""" import pytest from typing import Any from immich_watcher_core.notifications.queue import NotificationQueue class InMemoryBackend: """In-memory storage backend for testing.""" def __init__(self, initial_data: dict[str, Any] | None = None): self._data = initial_data async def load(self) -> dict[str, Any] | None: return self._data async def save(self, data: dict[str, Any]) -> None: self._data = data async def remove(self) -> None: self._data = None @pytest.fixture def backend(): return InMemoryBackend() class TestNotificationQueue: @pytest.mark.asyncio async def test_empty_queue(self, backend): queue = NotificationQueue(backend) await queue.async_load() assert not queue.has_pending() assert queue.get_all() == [] @pytest.mark.asyncio async def test_enqueue_and_get(self, backend): queue = NotificationQueue(backend) await queue.async_load() await queue.async_enqueue({"chat_id": "123", "text": "Hello"}) assert queue.has_pending() items = queue.get_all() assert len(items) == 1 assert items[0]["params"]["chat_id"] == "123" @pytest.mark.asyncio async def test_multiple_enqueue(self, backend): queue = NotificationQueue(backend) await queue.async_load() await queue.async_enqueue({"msg": "first"}) await queue.async_enqueue({"msg": "second"}) assert len(queue.get_all()) == 2 @pytest.mark.asyncio async def test_clear(self, backend): queue = NotificationQueue(backend) await queue.async_load() await queue.async_enqueue({"msg": "test"}) await queue.async_clear() assert not queue.has_pending() @pytest.mark.asyncio async def test_remove_indices(self, backend): queue = NotificationQueue(backend) await queue.async_load() await queue.async_enqueue({"msg": "first"}) await queue.async_enqueue({"msg": "second"}) await queue.async_enqueue({"msg": "third"}) # Remove indices in descending order await queue.async_remove_indices([2, 0]) items = queue.get_all() assert len(items) == 1 assert items[0]["params"]["msg"] == "second" @pytest.mark.asyncio async def test_remove_all(self, backend): queue = NotificationQueue(backend) await queue.async_load() await queue.async_enqueue({"msg": "test"}) await queue.async_remove() assert backend._data is None