Skip to content

test: add unit tests, API schema snapshot and CI test pipeline - #246

Open
TwoDCube wants to merge 2 commits into
masterfrom
test/unit-tests
Open

TwoDCube wants to merge 2 commits into
masterfrom
test/unit-tests

Conversation

@TwoDCube

Copy link
Copy Markdown
Member

Step 1 of 3 in adding a test suite (1: unit tests + schema snapshot + CI, 2: MySQL/Redis integration and response snapshot tests, 3: one PR per bug found).

What changes

Library/binary split. src/lib.rs now holds Config, AppState, app() and run(); src/main.rs only reads the environment, connects and serves. Nothing in the library reads env vars or opens connections itself: graphql::build_schema takes the persisted-query cache as an argument instead of connecting to Redis, and AppState::new takes the schema, database and config.

Logic moved out of resolvers, extraction only, no behaviour change:

  • utils/date_range.rs: month_range (archive), calendar_grid_range (events), iso_week_range (canteen)
  • colleagues::compare_names: Hungarian collation, ignoring a Dr. prefix
  • posts::image_urls: turns the images JSON (array or object) into URLs

Tests: 53 unit tests, some with proptest invariants:

  • date ranges: month ends, December → January, ISO week 1 and week 53
  • Date/DateTime scalars and PostCursor encode/decode round-trips
  • connection page info: pins the current hasPreviousPage = "older posts exist" meaning, since website_frontend2 requests these fields
  • Hungarian digraph and long-vowel ordering; image URLs; config defaults and errors

API contract snapshot. insta snapshots schema.sdl() (src/graphql/snapshots/). Adding, renaming or removing a field, or changing its type or nullability, now appears as a diff in the PR.

CI (.github/workflows/ci.yml):

  • runs on pull_request and pushes to master; branch pushes without a PR no longer trigger it
  • replaces the deprecated actions-rs/* actions with dtolnay/rust-toolchain, Swatinem/rust-cache@v2 and actions/checkout@v7
  • tests run with cargo-nextest, plus doctests
  • clippy uses --all-targets, so test code is linted too
  • job names Build/Format/Clippy/Test are unchanged, because branch protection requires them

Docs: docs/testing.md covers how to run the tests, update snapshots and handle known bugs.

Bugs found (ignored tests, fixed in follow-up PRs)

Test Bug
calendar_grid_ends_after_the_sunday_of_the_last_week (+ proptest) events(year, month) stops one day before the end of the calendar grid, so events on the grid's last Sunday are missing. When the next month starts on a Monday it adds a spare 6 days instead.
calendar_grid_does_not_panic_at_the_earliest_representable_month events(year: -262143, month: 1) overflows chrono and panics, returning HTTP 500.
parses_the_format_it_emits The DateTime scalar documents and emits YYYY-MM-DD HH:MM:SS, but its parser only accepts YYYY-MM-DDTHH:MM:SS.

cargo nextest list --run-ignored only lists them.

Verification

  • cargo fmt --check passes; cargo clippy --locked --all-targets -- -D warnings is clean.
  • cargo nextest run --all-targets: 53 passed, 4 skipped (the known bugs). A second run without INSTA_UPDATE passes, so the snapshot is stable.
  • cargo deny check bans licenses sources passes with the new dev-dependencies (insta, proptest). The advisories findings (h2, rustls, proc-macro-error2) already exist on master.

🤖 Generated with Claude Code

Split the crate into a library and a thin binary so the application can be
built from tests, and move date-range, name-ordering and image-URL logic out
of the resolvers into pure functions. Behaviour is unchanged.

- Unit tests, with proptest invariants, for date ranges, the Date and
  DateTime scalars, post cursors, connection page info, Hungarian ordering
  of colleague names, post image URLs and configuration parsing.
- insta snapshot of the GraphQL SDL, so API changes show up in review.
- Bugs found while writing the tests are recorded as
  #[ignore = "bug: ..."] tests and will be fixed in separate PRs.
- CI runs on pull requests, uses maintained actions and cargo-nextest, and
  lints test code. Job names are unchanged for branch protection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@verseghy-prow
verseghy-prow Bot requested a review from smrtrfszm September 14, 2026 17:18
@verseghy-prow

verseghy-prow Bot commented Sep 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: TwoDCube

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@verseghy-prow verseghy-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 14, 2026
With the default fail-fast matrix, a failing advisories check cancelled the
bans/licenses/sources check, so license problems were never reported.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant