diff --git a/tests/test_integration_task_kind_list.py b/tests/test_integration_task_kind_list.py new file mode 100644 index 00000000..362dc906 --- /dev/null +++ b/tests/test_integration_task_kind_list.py @@ -0,0 +1,45 @@ +"""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) diff --git a/tests/test_routes_planning.py b/tests/test_routes_planning.py index 7f731f85..0524ff6b 100644 --- a/tests/test_routes_planning.py +++ b/tests/test_routes_planning.py @@ -1,12 +1,11 @@ -import inspect +"""The planning door of the tasks API is routed: POST /api/tasks/planning +reaches a handler on the running app. What the handler does is the planning +service's to prove (tests/test_mcp_tool_create_records.py drives it).""" -def test_planning_handler_callable(): - from grimoire.routes import tasks as tasks_routes - assert callable(tasks_routes.start_planning_route) - - -def test_planning_service_signature(): - from grimoire.services.planning import start_planning - params = inspect.signature(start_planning).parameters - assert "user_id" in params and "project_id" in params and "title" in params +def test_starting_a_plan_is_routed_on_the_app(): + from grimoire.app import create_app + rules = { + (str(r.rule), m) for r in create_app().url_map.iter_rules() for m in r.methods + } + assert ("/api/tasks/planning", "POST") in rules diff --git a/tests/test_routes_tasks_kind.py b/tests/test_routes_tasks_kind.py deleted file mode 100644 index 2a8ce1dd..00000000 --- a/tests/test_routes_tasks_kind.py +++ /dev/null @@ -1,17 +0,0 @@ -import inspect - - -def test_create_note_accepts_task_kind(): - from grimoire.services.notes import create_note - assert "task_kind" in inspect.signature(create_note).parameters - - -def test_list_notes_accepts_task_kind(): - from grimoire.services.notes import list_notes - assert "task_kind" in inspect.signature(list_notes).parameters - - -def test_tasks_blueprint_registered_in_app(): - from grimoire.app import create_app - app = create_app() - assert "tasks" in app.blueprints diff --git a/tests/test_services_notes_task_kind.py b/tests/test_services_notes_task_kind.py index d85fd70b..4c9de31a 100644 --- a/tests/test_services_notes_task_kind.py +++ b/tests/test_services_notes_task_kind.py @@ -1,4 +1,5 @@ -"""task_kind create + list-filter behavior in services/notes.py.""" +"""create_note carries the task_kind it is given onto the row. The list +filter is proven against real Postgres in test_integration_task_kind_list.""" from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -20,19 +21,3 @@ async def test_create_note_passes_task_kind_to_model(): from grimoire.services.notes import create_note await create_note(user_id=1, title="P", status="todo", task_kind="plan") assert captured["task_kind"] == "plan" - - -@pytest.mark.asyncio -async def test_list_notes_filters_by_task_kind(): - mock_session = make_mock_session() - mock_session.scalar = AsyncMock(return_value=0) - exec_result = MagicMock() - exec_result.scalars.return_value.all.return_value = [] - mock_session.execute = AsyncMock(return_value=exec_result) - with patch("grimoire.services.notes.async_session") as mock_cls: - mock_cls.return_value = mock_session - from grimoire.services.notes import list_notes - # Should not raise; task_kind is a recognized kwarg. - rows, total = await list_notes(user_id=1, is_task=True, task_kind="plan") - assert rows == [] - assert total == 0