Add tests for tracked company admin endpoints and scheduler integration #1656

Closed
opened 2026-04-20 17:23:57 +00:00 by AI-Manager · 2 comments
Owner

Context

The admin endpoints for tracked companies (GET /admin/tracked, POST /admin/tracked, DELETE /admin/tracked/{company_name}) and the APScheduler integration have no test coverage.

What to do

  1. Add test cases (in tests/test_api.py or a new tests/test_admin.py) covering:

    • List tracked companies returns empty list when none configured
    • Add a company to tracked list and verify it appears in the list
    • Delete a tracked company and verify it is removed
    • All three endpoints require admin-role JWT (non-admin returns 403)
  2. Add a unit test for scheduler.py's run_scheduled_analysis() that:

    • Uses a mock DatabaseClient returning a known list of tracked companies
    • Verifies webhook.send_alert is called when patent count change exceeds threshold
    • Verifies no alert is sent when change is below threshold

Acceptance criteria

  • All new test cases pass under pytest tests/ -v
  • ruff check tests/ passes with no errors
  • Test file is consistent in style with existing test files

Roadmap reference

Related to the completed P3 "Scheduled/recurring analysis" and P1 "Test coverage for auth and admin" items.

## Context The admin endpoints for tracked companies (`GET /admin/tracked`, `POST /admin/tracked`, `DELETE /admin/tracked/{company_name}`) and the APScheduler integration have no test coverage. ## What to do 1. Add test cases (in `tests/test_api.py` or a new `tests/test_admin.py`) covering: - List tracked companies returns empty list when none configured - Add a company to tracked list and verify it appears in the list - Delete a tracked company and verify it is removed - All three endpoints require admin-role JWT (non-admin returns 403) 2. Add a unit test for `scheduler.py`'s `run_scheduled_analysis()` that: - Uses a mock `DatabaseClient` returning a known list of tracked companies - Verifies `webhook.send_alert` is called when patent count change exceeds threshold - Verifies no alert is sent when change is below threshold ## Acceptance criteria - All new test cases pass under `pytest tests/ -v` - `ruff check tests/` passes with no errors - Test file is consistent in style with existing test files ## Roadmap reference Related to the completed P3 "Scheduled/recurring analysis" and P1 "Test coverage for auth and admin" items.
AI-Manager added the P1agent-readymediumtest labels 2026-04-20 17:23:57 +00:00
Author
Owner

PR #1667 has been created for this issue. Work was completed on branch and is ready for review.

PR #1667 has been created for this issue. Work was completed on branch and is ready for review.
Author
Owner

Closed via PR #1667. During review, the scheduler integration tests were found to mock SPARC.scheduler.DatabaseClient which was removed by the scheduler refactor (PR #1665 / issue #1658). The test mocks were updated to use SPARC.scheduler.get_db_client and the db.close() assertion was removed to match the new pooled client behavior. All admin endpoint tests (GET/POST/DELETE /admin/tracked, GET /admin/alerts) were reviewed and found correct.

Closed via PR #1667. During review, the scheduler integration tests were found to mock `SPARC.scheduler.DatabaseClient` which was removed by the scheduler refactor (PR #1665 / issue #1658). The test mocks were updated to use `SPARC.scheduler.get_db_client` and the `db.close()` assertion was removed to match the new pooled client behavior. All admin endpoint tests (GET/POST/DELETE /admin/tracked, GET /admin/alerts) were reviewed and found correct.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1656