Skip to content

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

Open
Ahmedhossamdev wants to merge 3 commits 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 3 commits 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 search and report-problem tests to use a unified test harness with strongly typed response assertions, improving reliability and consistency.
    • Rewrote input/validation, sanitization, boundary, and end-to-end cases for clearer, more focused checks.
    • Renamed a few test cases for clarity.
  • Chores

    • Added a new response model to represent OK responses with empty data.

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: 65256f49-8a74-43c0-a152-af3df4475d41

📥 Commits

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

📒 Files selected for processing (3)
  • internal/restapi/report_problem_with_stop_handler_test.go
  • internal/restapi/report_problem_with_trip_handler_test.go
  • internal/restapi/response_types.go

📝 Walkthrough

Walkthrough

Refactor tests across route-search, stop-search, and report-problem handlers to use a generic callAPIHandler[T] test harness with typed response models; add URL helper functions that inject key=TEST; add an exported EmptyResponse type used by tests for empty-data endpoints.

Changes

Test Harness Refactoring

Layer / File(s) Summary
Route search handler test refactoring
internal/restapi/route_search_handler_test.go
Added maps/net/url imports and routeSearchURL(params url.Values); migrated route-search tests to use callAPIHandler[RoutesResponse] and assert typed RoutesResponse fields (Code, Text, Data.List) including route ShortName/LongName and agencies.
Stop search handler test refactoring
internal/restapi/search_stops_handler_test.go
Added maps import and searchStopsURL(params url.Values); migrated stop-search tests to callAPIHandler[StopsResponse], rewrote API-key, missing-input, end-to-end, no-results, max-count, whitespace/special-char, boundary, and FTS-injection tests; reformatted TestSanitizeFTS5Query cases.
Report-problem handler test refactoring
internal/restapi/report_problem_with_stop_handler_test.go, internal/restapi/report_problem_with_trip_handler_test.go
Rewrote API-key validation, end-to-end, minimal-params (renamed), missing-ID, and sanitization tests to use createTestApi + callAPIHandler (typed responses); replaced manual long-comment generation with strings.Repeat; assertions updated to use HTTP status and typed model fields.
Response type addition
internal/restapi/response_types.go
Added exported EmptyResponse struct for endpoints that return HTTP OK with an empty data body (code, currentTime, text, version).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • OneBusAway/maglev#897: Also refactors internal/restapi tests to use typed response models and updates response-type definitions.
  • OneBusAway/maglev#941: Migrates handler tests to a typed callAPIHandler[T] pattern and adds/updates response types.

Suggested reviewers

  • fletcherw
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'search handlers' but the changeset includes updates to report-problem handlers (4 of 6 files changed). The title is partially accurate but incomplete. Update the title to reflect all handler types updated, e.g., 'refactor(tests): handlers to use new typed response models' or specify both search and report-problem handlers.
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 (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

@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.

@github-actions
Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.0 ms
Error rate 0.00%
Total requests 340
Req/sec 11.1

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

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

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.1 ms
Error rate 0.00%
Total requests 333
Req/sec 10.9

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