Skip to content

Conversation

asgeija
Copy link
Member

@asgeija asgeija commented Oct 15, 2026

Closes #44

What changed

  • schema.test.ts: tests the sightings and sighting queries (search, sorting, pagination, unknown ids). The database is faked, so it runs with npm run test and 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 test because CI has no database.

Testing

  • npm run lint
  • npm run test: all backend tests pass; the database suite is skipped without a database.
  • Database tests, run against the VM's database:
    cd backend && npx tsx --env-file=.env --test src/schema.db.test.ts
    All 9 pass.

Not covered

  • The database tests are not part of CI. Running them there would need a MySQL database in the workflow. That is a tooling change, so it would be a separate issue.
  • For the CITY_ASC and SHAPE_ASC sorts, 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.

Cover search, sorting, pagination and the single sighting query by
running them through the real schema and resolvers with a faked
database, so no MySQL is needed locally or in CI.

Refs #44
Run the queries against a real MySQL database to check what the faked tests cannot: case-insensitive search and sorting and paging across the whole result set. The tests only read, and skip themselves when no database is configured.

Closes #44
@asgeija asgeija added the test label Oct 15, 2026
@asgeija asgeija added this to the Partial submission 2 milestone Oct 15, 2026
@asgeija asgeija requested a review from a team as a code owner October 15, 2026 09:12
@asgeija asgeija linked an issue Oct 15, 2026 that may be closed by this pull request
3 tasks
Copy link
Member

@jonatsm jonatsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@asgeija asgeija merged commit 823f29c into main Oct 15, 2026
2 checks passed
@asgeija asgeija deleted the 44-add-api-tests-for-the-graphql-querie branch October 15, 2026 09:18
Sign in to join this conversation on GitHub.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API tests for the GraphQL queries
2 participants