Skip to content

refactor(mocks): type handler responses against API types#322

Merged
Amund211 merged 1 commit into
mainfrom
type-mock-handler-responses
Jul 11, 2026
Merged

refactor(mocks): type handler responses against API types#322
Amund211 merged 1 commit into
mainfrom
type-mock-handler-responses

Conversation

@Amund211

Copy link
Copy Markdown
Owner

Summary

Every JSON-returning MSW handler now assigns its payload to a typed const response: API... = ... before HttpResponse.json(response), so the mocks fail to compile if they drift from the expected flashlight API response shapes.

  • account endpoints — added exported APIUsernameResponse (/v1/account/uuid/:uuid) and APIUUIDResponse (/v1/account/username/:username) discriminated unions covering both the success and 404 payloads.
  • wrapped endpoint — exported the existing APIWrappedData interface and used it to type makeWrappedResponse(...)'s output.
  • history / sessions endpoints — already typed their arrays (APIPlayerDataPIT[] / APISession[]); renamed the locals to response for a uniform pattern.
  • The mineatar handler returns an arrayBuffer, 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

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>
Copilot AI review requested due to automatic review settings July 11, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 returning HttpResponse.json(response).
  • Standardized local variable naming in handlers (e.g., history/sessionsresponse) 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.

@Amund211
Amund211 merged commit 07b63ea into main Jul 11, 2026
9 checks passed
@Amund211
Amund211 deleted the type-mock-handler-responses branch July 11, 2026 15:22
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