Test: Add API tests for GraphQL queries #74
Merged
+326
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #44
What changed
schema.test.ts: tests thesightingsandsightingqueries (search, sorting, pagination, unknown ids). The database is faked, so it runs withnpm run testand in CI without MySQL.schema.db.test.ts: runs the same queries against the real MySQL database. It checks case-insensitive search and that sorting and paging work across the whole result set. It only reads, and skips itself when no database is configured.AGENTS.md: adds the command for the database tests.Why two test files
The faked tests check what the resolvers ask the database for. They cannot show that MySQL gives case-insensitive search or correct sorting across the whole result set, and the project description requires both. The database tests cover that. They stay out of the default
npm run testbecause CI has no database.Testing
npm run lintnpm run test: all backend tests pass; the database suite is skipped without a database.cd backend && npx tsx --env-file=.env --test src/schema.db.test.tsAll 9 pass.
Not covered
CITY_ASCandSHAPE_ASCsorts, the tests check that paging is consistent, not exact alphabetical order. JavaScript and MySQL order text differently, so a JS comparison would give false failures.AI usage
Claude Code wrote the tests. I reviewed them and ran the tests locally, including against the real database.