integration tests and structured error response helper with request IDs#311
Merged
Conversation
… request IDs - Add creator-feed-newest-sort integration test asserting strict descending registration order, including a guard that fails on reversed ordering - Add creator-detail-cache-headers integration test validating Cache-Control header presence and correctness against documented policy constants - Add creator-feed-cursor-pagination round-trip integration test covering page-one fetch, cursor encode/decode, page-two non-overlap assertions, and tampered-cursor rejection - Add buildErrorResponse helper to api-response.utils that embeds requestId from ALS context when available and omits it when absent; apply to sendError so all error paths carry the request ID for log correlation - Extend api-response.utils.test with buildErrorResponse coverage including ALS context presence, absence, and requestId/log correlation assertions
|
@johnsmccain Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
This PR delivers four scoped improvements to test coverage and error response consistency:
1. Creator List Newest-Registered Sort Test
File:
src/modules/creators/creator-feed-newest-sort.integration.test.tsAdds an integration test for the
sort=createdAt&order=descpath onGET /api/v1/creators. Uses three fixtures with distinctcreatedAttimestamps and asserts:fetchCreatorListreceivessort=createdAtandorder=desccurrent.createdAt > next.createdAtFollows the same fixture factory and
makeReq/makeRes/makeNextconventions used bycreator-feed-default-sort.integration.test.tsandcreator-feed-multi-filter.integration.test.ts.2. Creator Detail Cache Header Integration Test
File:
src/modules/creator/creator-detail-cache-headers.integration.test.tsAdds an integration test validating
Cache-Controlheader behaviour onGET /api/v1/creators/:creatorId/profile. Asserts:CREATOR_PUBLIC_ROUTE_CACHE_CONTROL_HEADER.publicReadpublic, max-age=<N>patternmax-ageis a positive integerThe test is wired directly to the constants in
creator-public-cache.constants.ts, so any drift in the documented policy immediately surfaces as a failure.3. Cursor Pagination Round-Trip Integration Test
File:
src/modules/creators/creator-feed-cursor-pagination.integration.test.tsImplements a happy-path round-trip test using a 6-item fixture set (guaranteeing two full pages at
limit=3):offset=0, limit=3) — asserts 3 items andhasMore=trueencodeCursoroffset=3, limit=3) — asserts correct IDs,hasMore=false, and zero overlap with page onedecodeCursor4. Structured Error Response Helper with Request IDs
Files:
src/utils/api-response.utils.ts,src/utils/test/api-response.utils.test.tsAdds
buildErrorResponse— a reusable helper that constructs the standardApiErrorResponsebody and automatically embeds therequestIdfrom the activeAsyncLocalStoragecontext:requestIdis included when an ALS context with a request ID is activerequestIdis omitted entirely (not set tonull) when no context is presentsendErroris updated to delegate tobuildErrorResponse, so every error path in the API automatically carries the request ID without any call-site changesrequestIdin the response body matches the corresponding server log entry, enabling direct correlationNew tests cover: no-context omission, ALS context inclusion, empty-context omission, details inclusion/omission, and the log-correlation invariant.
Changed Files
src/modules/creators/creator-feed-newest-sort.integration.test.tssrc/modules/creator/creator-detail-cache-headers.integration.test.tssrc/modules/creators/creator-feed-cursor-pagination.integration.test.tssrc/utils/api-response.utils.tsbuildErrorResponse, apply tosendError, import ALSsrc/utils/test/api-response.utils.test.tsbuildErrorResponsetest suite557 insertions, 9 deletions across 5 files.
Testing
pnpm lintpnpm buildpnpm exec prisma generatewhen schema or generated types changedRun new tests in isolation:
Checklist
buildErrorResponseis backward-compatible —sendErrorcall sites are unchangedClose #295
Close #294
Close #293
Close #296