Skip to content

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

Merged
burma-shave merged 4 commits into
mainfrom
refactor/test-typed-responses-search-endpoints
Jun 3, 2026
Merged

refactor(tests): search handlers to use the new typed response model#960
burma-shave merged 4 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

Warning

Review limit reached

@Ahmedhossamdev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 30 minutes and 24 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0d273577-d046-481a-a43b-7f799bad20d1

📥 Commits

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

📒 Files selected for processing (2)
  • internal/restapi/route_search_handler_test.go
  • internal/restapi/search_stops_handler_test.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 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.

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

Comment thread internal/restapi/route_search_handler_test.go
Comment thread internal/restapi/search_stops_handler_test.go
var model models.ResponseModel
err = json.Unmarshal(bodyBytes, &model)
require.NoError(t, err)
resp, model := callAPIHandler[StopsResponse](t, api, searchStopsURL(url.Values{"input": {"Buenaventura"}}))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is more of a preference, but when we have symbols that are narrowly scoped like this, we may as well give longer, more descriptive names e.g. stopsResponse and stopsModel.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree. I’ll change it.
Thanks for the review, I appreciate it @burma-shave

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Performance Smoke Test Results

Status: PASSED

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

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

sonarqubecloud Bot commented Jun 3, 2026

@burma-shave burma-shave merged commit 8344f95 into main Jun 3, 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.

2 participants