refactor(mocks): type handler responses against API types#322
Merged
Conversation
Annotate every JSON response in the MSW handlers with the API type it represents (const response: API... = ...; return HttpResponse.json(response)). This makes the mocks fail to compile if they drift from the expected flashlight API response shapes. Adds exported response types for the account endpoints (APIUsernameResponse, APIUUIDResponse) and exports the existing APIWrappedData so the mocks can reference it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors MSW mock handlers to type-check their JSON payloads against the corresponding Flashlight API response types, ensuring mocks fail compilation if they drift from the expected API shapes.
Changes:
- Exported and introduced API response types (
APIUsernameResponse,APIUUIDResponse,APIWrappedData) for use by mocks. - Updated MSW handlers to assign typed
const response = ...values before returningHttpResponse.json(response). - Standardized local variable naming in handlers (e.g.,
history/sessions→response) for consistency.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/queries/wrapped.ts | Exports APIWrappedData so MSW mocks can type-check wrapped endpoint responses. |
| src/queries/uuid.ts | Adds exported APIUUIDResponse union type for /v1/account/username/:username responses. |
| src/queries/username.ts | Adds exported APIUsernameResponse union type for /v1/account/uuid/:uuid responses. |
| src/mocks/handlers.ts | Types JSON payloads returned by MSW handlers against the exported API response types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Every JSON-returning MSW handler now assigns its payload to a typed
const response: API... = ...beforeHttpResponse.json(response), so the mocks fail to compile if they drift from the expected flashlight API response shapes.APIUsernameResponse(/v1/account/uuid/:uuid) andAPIUUIDResponse(/v1/account/username/:username) discriminated unions covering both the success and 404 payloads.APIWrappedDatainterface and used it to typemakeWrappedResponse(...)'s output.APIPlayerDataPIT[]/APISession[]); renamed the locals toresponsefor a uniform pattern.mineatarhandler returns anarrayBuffer, not JSON, so it is unchanged.This is behavior-preserving: the returned objects are identical, only the type annotations are new.
Testing
pnpm tsc✅pnpm lint:check(oxlint + oxfmt) ✅pnpm test:unit— 797 passed ✅pnpm test:ui— 201 passed ✅ (browser tests exercise these MSW handlers)🤖 Generated with Claude Code