Skip to content

test: add coverage for omitted and invalid time parameters - #1296

Open
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap12
Open

test: add coverage for omitted and invalid time parameters#1296
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap12

Conversation

@3rabiii

@3rabiii 3rabiii commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR addresses the missing test coverage for edge cases regarding the time query parameter in the trips-for-route handler.

Changes Made

  • Added TestTripsForRouteHandler_TimeOmitted: Verifies that when the time parameter is not provided, the handler correctly defaults to the current clock time and returns a 200 OK response.
  • Added TestTripsForRouteHandler_InvalidTimeParameter: Asserts that passing malformed time values (e.g., garbage strings, overflowing epochs, or invalid calendar dates) correctly triggers a validation error, returning a 400 Bad Request.

Closes: #1295

Summary by CodeRabbit

  • Tests
    • Added coverage for omitted time parameters, confirming requests use the API’s default clock and return successfully.
    • Added validation coverage for malformed, overflowing, and invalid-date time values, confirming they return clear HTTP 400 errors.

- Add TestTripsForRouteHandler_TimeOmitted to verify 200 OK fallback behavior.
- Add TestTripsForRouteHandler_InvalidTimeParameter to assert 400 Bad Request on malformed inputs.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@3rabiii, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 50066945-1f12-4f69-a0bd-eb8d1cf0b91a

📥 Commits

Reviewing files that changed from the base of the PR and between e6e63ee and a6b1349.

📒 Files selected for processing (7)
  • internal/restapi/stops_for_route_handler.go
  • internal/restapi/trips_for_location_handler.go
  • internal/restapi/trips_for_route_handler.go
  • internal/restapi/trips_for_route_handler_test.go
  • internal/restapi/vehicles_for_agency_handler.go
  • internal/utils/api.go
  • internal/utils/api_test.go
📝 Walkthrough

Walkthrough

The change adds trips-for-route handler tests for omitted and invalid time query parameters. The tests verify API-clock defaulting, successful responses, and HTTP 400 validation payloads.

Changes

Trips-for-route time parameter coverage

Layer / File(s) Summary
Time parameter default and validation tests
internal/restapi/trips_for_route_handler_test.go
Tests verify omitted time uses the mocked API clock and returns HTTP 200. Table-driven cases verify malformed, overflowing, and invalid-date values return HTTP 400 with the expected field error payload.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: LGTM

Suggested reviewers: ahmedhossamdev

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added tests for omitted and invalid time parameters.
Linked Issues check ✅ Passed The tests cover omitted time fallback behavior and malformed time validation required by issue #1295.
Out of Scope Changes check ✅ Passed The changes are limited to tests for the time parameter behavior described in issue #1295.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/restapi/trips_for_route_handler_test.go`:
- Around line 219-230: Update the omitted-time parsing path in the
trips-for-route handler to use api.Clock instead of time.Now(), while preserving
explicit time-parameter behavior. Extend the test around
createTestApiWithTripsForRouteFixture and the omitted-time request to assert the
clock-dependent active fixture trip, and add coverage for each new
clock-selection branch or condition.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3d76fc8c-acb1-4db3-a31c-6c0954fdcc2b

📥 Commits

Reviewing files that changed from the base of the PR and between 3b73fd9 and e6e63ee.

📒 Files selected for processing (1)
  • internal/restapi/trips_for_route_handler_test.go

Comment thread internal/restapi/trips_for_route_handler_test.go
- Update utils.ParseTimeParameter and its callers to use the provided api.Clock instead of the system time.Now().
- Update TestTripsForRouteHandler_TimeOmitted with a strict assertion to guarantee the active fixture trip is deterministically returned.
@sonarqubecloud

sonarqubecloud Bot commented Aug 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing test coverage for omitted and invalid time parameter in trips-for-route handler

1 participant