Skip to content

test (route): add table-driven tests for route IDs with multiple underscores#1039

Merged
burma-shave merged 2 commits into
OneBusAway:mainfrom
3rabiii:fix-route_issue_4
Jun 18, 2026
Merged

test (route): add table-driven tests for route IDs with multiple underscores#1039
burma-shave merged 2 commits into
OneBusAway:mainfrom
3rabiii:fix-route_issue_4

Conversation

@3rabiii

@3rabiii 3rabiii commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Description

The current GET /api/where/route/{id} implementation uses strings.SplitN(id, "_", 2) to parse the agency and entity IDs. While this correctly handles entity IDs containing underscores, there was no test coverage explicitly validating this edge case, leaving it vulnerable to future regressions.

Changes Made:

  • Added TestRouteHandler_EntityIDWithUnderscores to route_handler_test.go.
  • Utilized table-driven tests to verify multiple underscore scenarios (e.g., KCM_40_100479, AGENCY_part1_part2_part3).
  • Verified that the underlying utility accurately extracts the agency/entity.
  • Verified that the HTTP handler successfully parses these IDs and gracefully returns a 404 Not Found (since the dummy routes do not exist in the test DB) rather than a 400 Bad Request.

Fixes: #1010

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of route identifiers that include underscores in the entity portion: requests are no longer rejected as invalid and instead return 404 Not Found when the route doesn’t exist.
  • Tests

    • Added coverage for route ID inputs with underscores to ensure the API returns 404 (not 400 validation errors) for these cases.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81bbf50f-d130-401c-b265-9c54d5b083e1

📥 Commits

Reviewing files that changed from the base of the PR and between a71a26d and 0c789e2.

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

📝 Walkthrough

Walkthrough

This PR adds a new test function TestRouteHandler_EntityIDWithUnderscores to verify that route IDs containing underscores in the entity portion are correctly handled by the route handler. The test validates behavior across multiple test cases, each asserting a 404 Not Found response instead of a 400 validation error.

Changes

Route ID Underscore Parsing Test

Layer / File(s) Summary
Test for entity IDs with underscores
internal/restapi/route_handler_test.go
New test TestRouteHandler_EntityIDWithUnderscores validates that route IDs with underscores in the entity component are accepted by the handler, returning 404 instead of 400 validation error for edge cases like KCM_40_100479.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • aaronbrethorst
  • burma-shave
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding table-driven tests for route IDs with underscores, which matches the implementation of TestRouteHandler_EntityIDWithUnderscores.
Linked Issues check ✅ Passed The PR fulfills issue #1010 by adding TestRouteHandler_EntityIDWithUnderscores that verifies route ID parsing with multiple underscores, testing cases like KCM_40_100479.
Out of Scope Changes check ✅ Passed All changes are in-scope, limited to adding the test function TestRouteHandler_EntityIDWithUnderscores in route_handler_test.go as specified in issue #1010.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

ID parsing is already covered by TestExtractAgencyIDAndCodeID in
utils/api_test.go. Keep only the handler-level assertions.
@sonarqubecloud

Copy link
Copy Markdown

@burma-shave burma-shave merged commit 5c311d9 into OneBusAway:main Jun 18, 2026
9 checks passed
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.

test: add missing edge-case coverage for route ID parsing

2 participants