Add integration tests for Games & Routes API

25 tests covering game CRUD (create/list/get/update/delete), slug
uniqueness enforcement, by-region grouping, and route operations
(create/update/delete/reorder). Verifies that list_game_routes
excludes routes with no Pokemon encounters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 12:51:37 +01:00
parent 4aae12cd72
commit 79eabf4f9f
2 changed files with 340 additions and 15 deletions

View File

@@ -1,26 +1,31 @@
---
# nuzlocke-tracker-ch77
title: Integration tests for Games & Routes API
status: draft
status: completed
type: task
priority: normal
created_at: 2026-02-10T09:33:13Z
updated_at: 2026-02-10T09:33:13Z
updated_at: 2026-02-21T11:48:10Z
parent: nuzlocke-tracker-yzpb
---
Write integration tests for the games and routes API endpoints in `backend/src/app/api/games.py`.
Write integration tests for the games and routes API endpoints in backend/src/app/api/games.py.
## Key behaviors to test
- Game CRUD: create (201), list, get with routes, update, delete (204)
- Slug uniqueness enforced at create and update (409)
- 404 for missing games
- 422 for invalid request bodies
- Route operations require version_group_id on the game (need VersionGroup fixture via db_session)
- list_game_routes only returns routes with encounters (or parents of routes with encounters)
- Game detail (GET /{id}) returns all routes regardless
- Route create, update, delete, reorder
## Checklist
- [ ] Test CRUD operations for games (create, list, get, update, delete)
- [ ] Test route management within a game (create, list, reorder, update, delete)
- [ ] Test route encounter management (add/remove Pokemon to routes)
- [ ] Test bulk import functionality
- [ ] Test region grouping/filtering
- [ ] Test error cases (404 for missing games, validation errors, duplicate handling)
## Notes
- Use the httpx AsyncClient fixture from the test infrastructure task
- Each test should be independent — use fixtures to set up required data
- Test both success and error response codes and bodies
- [x] Test CRUD operations for games (create, list, get, update, delete)
- [x] Test route management within a game (create, list, update, delete, reorder)
- [x] Test error cases (404, 409 duplicate slug, 422 validation)
- [x] Test list_game_routes filtering behavior (empty routes excluded)
- [x] Test by-region endpoint structure