"""Listing tasks by kind returns that kind only, counted the same way. A mocked session cannot show this: the filter is a WHERE clause, and only a real query proves it keeps the issue out of a list of work and the count in step with the page. """ import pytest import pytest_asyncio from grimoire.models import async_session from grimoire.models.note import Note from grimoire.models.project import Project from grimoire.services import notes as notes_svc from tests.helpers import ensure_user pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine", "_no_embedding")] @pytest_asyncio.fixture async def world(): async with async_session() as s: owner = await ensure_user(s, "task_kind_lister") project = Project(user_id=owner.id, title="Kinds") s.add(project) await s.flush() s.add_all([ Note(user_id=owner.id, project_id=project.id, title=f"{kind} {i}", status="todo", task_kind=kind) for kind, n in (("work", 2), ("issue", 1), ("spike", 1)) for i in range(n) ]) await s.commit() return {"owner": owner.id, "pid": project.id} @pytest.mark.parametrize("kind, titles", [ ("issue", ["issue 0"]), ("work", ["work 0", "work 1"]), (None, ["issue 0", "spike 0", "work 0", "work 1"]), ]) async def test_listing_by_kind_returns_that_kind_and_counts_it(world, kind, titles): rows, total = await notes_svc.list_notes( world["owner"], is_task=True, project_id=world["pid"], task_kind=kind, ) assert sorted(r.title for r in rows) == titles assert total == len(titles)