Skip to content

refactor: add TripsForLocationResponse type and refactor tests to the new response model#916

Open
Ahmedhossamdev wants to merge 2 commits into
mainfrom
refactor/typed-trips-for-location-tests
Open

refactor: add TripsForLocationResponse type and refactor tests to the new response model#916
Ahmedhossamdev wants to merge 2 commits into
mainfrom
refactor/typed-trips-for-location-tests

Conversation

@Ahmedhossamdev
Copy link
Copy Markdown
Member

@Ahmedhossamdev Ahmedhossamdev commented May 6, 2026

Summary

  • Add TripsForLocationResponse alias and migrate all tests to callAPIHandler[TripsForLocationResponse]
  • Drop map[string]any casts in favor of typed model.Data.List / .References access
  • Combine 3 missing-parameter tests into a single table-driven MissingParameters test
  • Add tripsForLocationURL helper to remove URL-building duplication
  • File shrinks from 441 to 207 lines

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for trips-for-location endpoint, including validation of schedule and status inclusion, cross-reference consistency, and missing parameter handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@Ahmedhossamdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 1 second before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ec5114e-7ed1-486a-ad96-302231e0f27e

📥 Commits

Reviewing files that changed from the base of the PR and between 0b769c3 and d870f3e.

📒 Files selected for processing (2)
  • internal/restapi/response_types.go
  • internal/restapi/trips_for_location_handler_test.go
📝 Walkthrough

Walkthrough

A new response type TripsForLocationResponse is added as a typed alias for ListResponse[models.TripsForLocationListEntry]. The trips-for-location handler tests are refactored with a shared URL builder and expanded with five new test cases covering response structure consistency, schedule and status inclusion, and parameter validation.

Changes

Trips-for-Location Handler Response & Tests

Layer / File(s) Summary
Response Type Definition
internal/restapi/response_types.go
Introduces TripsForLocationResponse as a ListResponse specialization for models.TripsForLocationListEntry.
Test Infrastructure
internal/restapi/trips_for_location_handler_test.go
Adds constants for fixed test location and a helper function buildTripsForLocationURL() to centralize URL construction with optional query parameters.
Test Refactoring
internal/restapi/trips_for_location_handler_test.go
Refactors TestTripsForLocationHandler_DifferentAreas to use the fixed location and new URL builder, removing ad-hoc coordinate variation.
Response Validation Tests
internal/restapi/trips_for_location_handler_test.go
Adds TestTripsForLocationHandler_ReferencesAreConsistent to validate cross-references (stops, routes, agencies) and proper linkage between them.
Optional Field Tests
internal/restapi/trips_for_location_handler_test.go
Adds TestTripsForLocationHandler_ScheduleInclusion and TestTripsForLocationHandler_StatusInclusion to verify schedule and status presence/absence behavior based on query flags.
Parameter Validation Tests
internal/restapi/trips_for_location_handler_test.go
Adds TestTripsForLocationMissingLat, TestTripsForLocationMissingLon, and TestTripsForLocationMissingBothLatAndLon to ensure proper 400 Bad Request responses for missing required parameters.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • OneBusAway/maglev#900: Adds TripsForLocationResponse as a ListResponse alias that directly uses the generic response types introduced in that PR.
  • OneBusAway/maglev#897: Both PRs extend internal/restapi/response_types.go to add typed response models and refactor related handler tests.
  • OneBusAway/maglev#903: Adds similar ListResponse type aliases in internal/restapi/response_types.go with corresponding handler test updates.

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 two main changes: adding the TripsForLocationResponse type and refactoring tests to use the new typed response model.
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/typed-trips-for-location-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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Performance Smoke Test Results

Status: PASSED

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

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

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/restapi/trips_for_location_handler_test.go (1)

137-144: ⚡ Quick win

Tighten includeSchedule=false assertions to catch regressions.

On Line 142, the current branch permits non-nil entry.Schedule as long as StopTimes is empty. That can miss accidental schedule payload leakage when includeSchedule=false. Assert schedule omission directly.

Proposed test assertion adjustment
 			for _, entry := range model.Data.List {
 				if tt.includeSchedule {
 					if assert.NotNil(t, entry.Schedule, "schedule should be present when includeSchedule=true") {
 						assert.NotEmpty(t, entry.Schedule.TimeZone)
 					}
-				} else if entry.Schedule != nil {
-					assert.Empty(t, entry.Schedule.StopTimes, "stopTimes should be empty when includeSchedule=false")
+				} else {
+					assert.Nil(t, entry.Schedule, "schedule should be omitted when includeSchedule=false")
 				}
 			}
🤖 Prompt for 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.

In `@internal/restapi/trips_for_location_handler_test.go` around lines 137 - 144,
When tt.includeSchedule is false we should assert the schedule is omitted, not
merely that StopTimes is empty; update the test loop over model.Data.List so
that in the else branch you assert entry.Schedule is nil (e.g., use assert.Nil
on entry.Schedule) rather than checking entry.Schedule.StopTimes, so any
accidental schedule payload leakage when includeSchedule=false will fail the
test (references: tt.includeSchedule, entry.Schedule, entry.Schedule.StopTimes,
model.Data.List).
🤖 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.

Nitpick comments:
In `@internal/restapi/trips_for_location_handler_test.go`:
- Around line 137-144: When tt.includeSchedule is false we should assert the
schedule is omitted, not merely that StopTimes is empty; update the test loop
over model.Data.List so that in the else branch you assert entry.Schedule is nil
(e.g., use assert.Nil on entry.Schedule) rather than checking
entry.Schedule.StopTimes, so any accidental schedule payload leakage when
includeSchedule=false will fail the test (references: tt.includeSchedule,
entry.Schedule, entry.Schedule.StopTimes, model.Data.List).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 11f4a12a-ce70-4434-8f19-ec197e30acef

📥 Commits

Reviewing files that changed from the base of the PR and between 333ef9e and 0b769c3.

📒 Files selected for processing (2)
  • internal/restapi/response_types.go
  • internal/restapi/trips_for_location_handler_test.go

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.2 ms
Error rate 0.00%
Total requests 325
Req/sec 10.7

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

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

@Ahmedhossamdev Ahmedhossamdev requested a review from fletcherw May 11, 2026 15:29
@Ahmedhossamdev Ahmedhossamdev force-pushed the refactor/typed-trips-for-location-tests branch from 3f57de2 to d870f3e Compare May 13, 2026 17:48
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.2 ms
Error rate 0.00%
Total requests 339
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.

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