Add unit tests #2

Closed
opened 2026-10-10 16:55:12 +02:00 by pepa · 0 comments
Owner

The application currently has no unit tests, and end2end/ is still the untouched Leptos template (it asserts "Welcome to Leptos"), so nothing verifies the app's behaviour.

Goal

Add unit tests for the logic that can be tested without a running server or database, and make them runnable with cargo test --features ssr.

Candidates

Pure logic in src/backend/data.rs:

  • DayHour::try_from / DayHours::try_new — parsing of HH:MM - HH:MM lists, empty input, malformed input
  • DayHours Display — round trip with parsing, including discount
  • WeekHours validation — RE_HOURS regex and validate_hours ("to" before "from")
  • TmCheck::from_str — slot string parsing
  • Reservations::add_slot — merging of adjacent slots per property
  • Page / PagedResponse — limit, offset, is_first, is_last, total_pages (including page_size == 0)
  • validate_closing_time, validate_date
  • validator rules on Company, UserProfile, PwdChange, CrReservation

Other:

  • is_reserved in src/backend/reservation.rs — slot boundaries (start inclusive, end exclusive)
  • MailMessage::replace_body_vars in src/backend/mail.rs — #date# and #summary# placeholders
  • Database::con_string and config parsing in src/config.rs (parse config_sample.toml)
  • AppError conversions and messages in src/error.rs

Out of scope / follow-up

  • Server functions that need PostgreSQL (reservation creation, users, permissions) — these need an integration test setup with a test database.
  • Replacing the template Playwright test in end2end/ with real end-to-end tests.

Done when

  • cargo test --features ssr runs and passes.
  • The test command is documented in README.md and CLAUDE.md.
The application currently has no unit tests, and `end2end/` is still the untouched Leptos template (it asserts "Welcome to Leptos"), so nothing verifies the app's behaviour. ## Goal Add unit tests for the logic that can be tested without a running server or database, and make them runnable with `cargo test --features ssr`. ## Candidates Pure logic in `src/backend/data.rs`: - `DayHour::try_from` / `DayHours::try_new` — parsing of `HH:MM - HH:MM` lists, empty input, malformed input - `DayHours` `Display` — round trip with parsing, including discount - `WeekHours` validation — `RE_HOURS` regex and `validate_hours` ("to" before "from") - `TmCheck::from_str` — slot string parsing - `Reservations::add_slot` — merging of adjacent slots per property - `Page` / `PagedResponse` — `limit`, `offset`, `is_first`, `is_last`, `total_pages` (including `page_size == 0`) - `validate_closing_time`, `validate_date` - `validator` rules on `Company`, `UserProfile`, `PwdChange`, `CrReservation` Other: - `is_reserved` in `src/backend/reservation.rs` — slot boundaries (start inclusive, end exclusive) - `MailMessage::replace_body_vars` in `src/backend/mail.rs` — `#date#` and `#summary#` placeholders - `Database::con_string` and config parsing in `src/config.rs` (parse `config_sample.toml`) - `AppError` conversions and messages in `src/error.rs` ## Out of scope / follow-up - Server functions that need PostgreSQL (reservation creation, users, permissions) — these need an integration test setup with a test database. - Replacing the template Playwright test in `end2end/` with real end-to-end tests. ## Done when - `cargo test --features ssr` runs and passes. - The test command is documented in `README.md` and `CLAUDE.md`.
pepa closed this issue 2026-10-10 17:11:20 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ITsolved/rezervovator#2