Skip to content

refactor(tests): search handlers to use the new typed response model#960

Open
Ahmedhossamdev wants to merge 1 commit into
mainfrom
refactor/test-typed-responses-search-endpoints
Open

refactor(tests): search handlers to use the new typed response model#960
Ahmedhossamdev wants to merge 1 commit into
mainfrom
refactor/test-typed-responses-search-endpoints

Conversation

@Ahmedhossamdev
Copy link
Copy Markdown
Member

@Ahmedhossamdev Ahmedhossamdev commented May 16, 2026

Update the search handlers to use new response type models for parsing the JSON responses.

Summary by CodeRabbit

  • Tests
    • Refactored route and stop search handler tests with unified test harnesses and strongly typed response validation, improving test reliability and code organization across the search test suite.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

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: 261c748f-4f90-4cb6-be48-ee692bb76b31

📥 Commits

Reviewing files that changed from the base of the PR and between 2f29632 and e64e3e4.

📒 Files selected for processing (2)
  • internal/restapi/route_search_handler_test.go
  • internal/restapi/search_stops_handler_test.go

📝 Walkthrough

Walkthrough

Refactored route-search and stop-search handler tests to use a shared callAPIHandler[T] test harness with strongly typed response models (RoutesResponse, StopsResponse) instead of manual server setup and generic JSON decoding. Each handler test file now includes a URL helper that injects the API key and returns fully encoded query URLs.

Changes

Test Harness Refactoring

Layer / File(s) Summary
Route search handler test refactoring
internal/restapi/route_search_handler_test.go
Added imports (maps, net/url) and routeSearchURL helper that builds /api/where/search/route.json URLs with injected API key. Refactored all seven test cases (RequiresValidApiKey, EndToEnd, RequiresInput, ValidatesMaxCount, NoResults, WhitespaceInput, MaxCountBoundaries) to use callAPIHandler[RoutesResponse] and assert directly against typed RoutesResponse fields (Code, Text, Data.List) with route ShortName/LongName and agency references.
Stop search handler test refactoring
internal/restapi/search_stops_handler_test.go
Added imports (maps) and searchStopsURL helper that builds /api/where/search/stop.json URLs with injected API key. Refactored API-key validation, missing-input, end-to-end success, no-results, max-count, whitespace/special-character input, max-count boundary, and FTS injection tests to use callAPIHandler[StopsResponse] with typed StopsResponse assertions. Reformatted TestSanitizeFTS5Query test cases table into compact struct literals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • OneBusAway/maglev#912: Both PRs refactor handler tests in internal/restapi to standardize on the shared callAPIHandler[T] generic test harness with strongly typed response models.

Suggested reviewers

  • fletcherw
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title accurately describes the main change: refactoring test files for search handlers to use typed response models instead of generic JSON parsing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/test-typed-responses-search-endpoints

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.

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 1.8 ms
Error rate 0.00%
Total requests 330
Req/sec 10.8

Smoke test config: 5 VUs x 30s. Thresholds: p(95) < 300ms, error rate < 1%.

Full results uploaded as workflow artifact: k6-smoke-summary.

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.

1 participant