Files

29 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

# Task: Fix test_get_all_alerts
## Goal
Fix the single failing test in `test_alerts.py::TestAlertCRUD::test_get_all_alerts`. The test creates 2 alerts but GET returns `total: 0`.
## Root Cause
The test uses `mock_db.execute_query.side_effect` with SQL string matching. The router's query for alerts uses parameterized queries with dynamic placeholders (`$1`, `$2`, etc.) that don't match the mock's simple string patterns. Specifically, the count query and the data query use different SQL patterns than what the mock expects.
## Requirements
1. Read `test_alerts.py` lines 30-80 to understand the mock side_effect logic
2. Read `routers/alerts.py` lines 30-80 to understand the actual SQL queries being made
3. Fix the mock's `alerts_query_side_effect` function to correctly match all SQL patterns the router uses:
- The COUNT query with `watchlist_id IN (...)` pattern
- The data query with `watchlist_id IN (...)` pattern
- Ensure the mock returns correct data for both queries
4. Ensure the watchlist fixture's `user_id: "test-user-1"` matches the test user's ID
## Acceptance Criteria
- `pytest tests/test_alerts.py::TestAlertCRUD::test_get_all_alerts` passes
- `pytest tests/test_alerts.py` passes all 23 tests (0 failures)
## Files to Modify
- `src/backend/tests/test_alerts.py` — Fix the mock side_effect function
## Constraints
- Do not change the router code
- Do not change the conftest.py fixtures
- Keep the test's existing structure and mock approach