[EPAC-1873]: add integration tests for /api/v1/on-this-day handler#457
Merged
riddim-developer-bot[bot] merged 2 commits intoMay 14, 2026
Conversation
Six integration tests under //go:build integration verify the date-arithmetic SQL in on-this-day/main.go against a real Postgres: - TestOnThisDayHappyPath_ReturnsMatchingSittings - TestOnThisDayLeapYearFeb29 (2024-02-29 valid; 2023-02-29 → HTTP 400) - TestOnThisDayNoMatchingDate_ReturnsEmptyShape - TestOnThisDayLimitBound (limit=1 and limit=999 clamped to maxLimit=20) - TestOnThisDayInvalidDateFormat_Returns400 - TestOnThisDayTimezoneBoundary (DATE column, not TIMESTAMP) Uses the _testdb harness from EPAC-1869. Unit tests unaffected (go test ./... still passes).
When the integration test job runs go test -tags=integration, an earlier test may call HandleRequest and warm the package-level dbConn. The unit test then unsets DATABASE_URL but getDBConn reuses the live connection and returns 200 instead of the expected 500. Fix: close and nil dbConn before unsetting DATABASE_URL, and restore the env var via t.Cleanup so subsequent tests are unaffected.
|
Symphony expected a reviewer-bot review for the current autonomous PR head within the configured SLA window, but none was found.
|
There was a problem hiding this comment.
ReviewAutonomousPR
- Verdict:
approve - Reviewer boundary:
review_only - Acceptance criteria coverage: covered=5, missing=0, unclear=1
Summary
The PR adds the requested integration coverage for /api/v1/on-this-day and keeps the existing unit behavior unchanged; no required correctness defects are present in the changes.
Actionable findings
- nit / follow_up — Timezone boundary test does not enforce a non-UTC runtime context (
backend/on-this-day/main_integration_test.go)- The timezone test validates DATE-only behavior by calling queryOnThisDay directly, but it does not shift process timezone or invoke the handler path while forcing a UTC-offset context. This means subtle request-parsing or request-to-DB timezone regressions tied specifically to handler/runtime timezone handling are not exercised in this test.
- Actionability:
follow_up
Acceptance criteria coverage
- covered — TestOnThisDayHappyPath_ReturnsMatchingSittings seeds 3 speeches on 2010-03-15, 2 on 2015-03-15, extra-date rows, queries 2026-03-15, asserts only March-15 records
- Implemented in
TestOnThisDayHappyPath_ReturnsMatchingSittingswith DB seeding andqueryOnThisDayassertions. - Actionability:
none - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayHappyPath_ReturnsMatchingSittings
- Implemented in
- covered — TestOnThisDayLeapYearFeb29 asserts 2020-02-29 matches 2024-02-29 and documents invalid 2023-02-29 handling
- Test seeds 2020 leap-day rows, verifies 2024 query returns them, and checks 2023-02-29 returns HTTP 400.
- Actionability:
none - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayLeapYearFeb29
- covered — TestOnThisDayNoMatchingDate_ReturnsEmptyShape returns 200 with items:[] and date echo for no matches
- Direct DB query and handler response assertions both verify empty shape and non-nil items array with echoed date.
- Actionability:
none - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayNoMatchingDate_ReturnsEmptyShape
- covered — TestOnThisDayLimitBound validates limit=1 and clamp behavior for limit=999
- Validates direct limit=1 result count and verifies parseLimit(999) equals maxLimit, then queries with maxLimit.
- Actionability:
none - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayLimitBound
- covered — TestOnThisDayInvalidDateFormat_Returns400 checks malformed date format maps to HTTP 400 with error field
- Table-driven cases validate 400 and non-empty
errorfield. - Actionability:
none - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayInvalidDateFormat_Returns400
- Table-driven cases validate 400 and non-empty
- unclear — TestOnThisDayTimezoneBoundary seeds DATE value and verifies query for matching calendar date under shifted timezone context
- Test validates calendar-date behavior but does not explicitly set/process timezone-shifted context or go through handler path for this scenario.
- Actionability:
follow_up - Evidence: backend/on-this-day/main_integration_test.go: TestOnThisDayTimezoneBoundary
- Suggested follow-up: Add timezone-offset context assertion around handler call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The on-this-day handler's date-arithmetic SQL (month/day extraction, leap-year Feb 29, strict
<boundary) is untestable by the existing unit suite — all 6 unit tests use fake row scanners with no real Postgres. Any off-by-one in the SQL ships silently. This PR adds the DB-backed integration test layer to catch those regressions.What changed
backend/on-this-day/main_integration_test.go(280 lines,//go:build integration)speechesrows and callingqueryOnThisDaydirectly (bypassing the package-leveldbConn) orHandleRequestfor HTTP-layer assertions_testdb.Connect(t)and_testdb.SeedSpeechfrom the EPAC-1869 harness; isolation viaDELETE FROM speechesbefore each testTestOnThisDayLeapYearFeb29documents that Go'stime.Parse("2006-01-02", "2023-02-29")returns"day out of range", so the handler returns HTTP 400 for non-leap Feb 29Trade-offs not taken
WithTxfor isolation: UsingBEGIN/ROLLBACKwould hide seeded rows from the handler's own DB connection (which connects separately viaDATABASE_URL). TheDELETE FROM speechesapproach matches the search integration test pattern and keeps both connections seeing the same state.HandleRequestfor all tests: The handler'sgetDBConnuses a package-level*pgx.Conn. CallingqueryOnThisDaydirectly with the test connection avoids polluting or depending on that global and matches the search integration test approach.Test plan
Run the full integration suite locally with Docker (when available):
Expected: all 6 named tests pass. Unit tests unaffected (
go test ./...inbackend/on-this-daypasses withoutDATABASE_URL).Verification evidence
go build ./...frombackend/on-this-day/: PASS (no output)go vet -tags=integration ./...frombackend/on-this-day/: PASS (no output)go test ./...(unit tests, no DB): PASS —ok epac/on-this-day 0.384sservices: postgres:16sidecar inbackend-tests.yml.Resolves EPAC-1873
Reviewer-Boundary: review-only